UNPKG

homebridge-flume

Version:

Homebridge plugin to integrate Flume devices into HomeKit.

41 lines 1.27 kB
const BATTERY_LEVEL_LOW = 'low'; export class Device { id; locationId; productName; isBatteryLow; isDisconnected; isLeakDetected = false; usageToday = 0; usageMonth = 0; usageLastMonth = 0; _onUpdateCallback = null; constructor(data) { this.id = data.id; this.locationId = data.location_id; this.productName = data.product; this.isDisconnected = !data.connected; this.isBatteryLow = data.battery_level === BATTERY_LEVEL_LOW; } setOnUpdateCallback(callback) { this._onUpdateCallback = callback; } update(deviceData, leakData, usageData) { if (deviceData) { this.isBatteryLow = deviceData.battery_level === BATTERY_LEVEL_LOW; this.isDisconnected = !deviceData.connected; } if (leakData) { this.isLeakDetected = leakData.active; } if (usageData) { this.usageToday = usageData.today[0]?.value || 0; this.usageMonth = usageData.month[0]?.value || 0; this.usageLastMonth = usageData.lastMonth[0]?.value || 0; } if (this._onUpdateCallback) { this._onUpdateCallback(this.id); } } } //# sourceMappingURL=device.js.map