Files
scrypted/plugins/zwave/src/CommandClasses/FloodSensorToWaterAlarm.ts
Koushik Dutta a46b2811ed initial commit
2021-08-24 21:22:41 -07:00

23 lines
946 B
TypeScript

import { FloodSensor } from "@scrypted/sdk";
import { ValueID } from "@zwave-js/core";
import { ZWaveNode, ZWaveNodeValueUpdatedArgs } from "zwave-js";
import { Notification } from "./Notification";
import { ZwaveDeviceBase } from "./ZwaveDeviceBase";
export class FloodSensorToWaterAlarm extends Notification implements FloodSensor {
static getInterfaces(node: ZWaveNode, valueId: ValueID): string[] {
if (Notification.checkInterface(node, valueId, 'Water leak detected', 'Water leak detected (location provided)')) {
return ['FloodSensor'];
}
return null;
}
static onValueChanged(zwaveDevice: ZwaveDeviceBase, valueId: ZWaveNodeValueUpdatedArgs) {
if (valueId.propertyKey === 'Sensor status') {
const notification = Notification.lookupNotification(zwaveDevice, 'Water Alarm');
// any non idle value works?
zwaveDevice.flooded = !!notification.lookupValue(valueId.newValue as number);
}
}
}