From 089bd57690801728c2098f1491a693bcb1b9f80c Mon Sep 17 00:00:00 2001 From: Erik van Leeuwen Date: Mon, 30 Sep 2024 18:12:15 +0200 Subject: [PATCH] Ignore 'null' values for the onoff capability --- app.ts | 2 +- lib/TriggerCardAnyDeviceOnOff.ts | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/app.ts b/app.ts index 0742852..b4ec133 100644 --- a/app.ts +++ b/app.ts @@ -33,7 +33,7 @@ class ZoneActivity extends Homey.App { await ConditionCardZoneInactiveForMinutes.initialize(this.homey, this.homeyApi, zonesDb, this.log); // Deprecated await ConditionCardZoneActiveForMinutes.initialize(this.homey, this.homeyApi, zonesDb, this.log); await ConditionCardEvaluateSensorCapabilities.initialize(this.homey, this.homeyApi, zonesDb, this.log); - await TriggerCardAnyDeviceTurnedOn.initialize(this.homey, this.homeyApi, zonesDb, this.log); + await TriggerCardAnyDeviceTurnedOn.initialize(this.homey, this.homeyApi, zonesDb, this.log, this.error); } } diff --git a/lib/TriggerCardAnyDeviceOnOff.ts b/lib/TriggerCardAnyDeviceOnOff.ts index 8aade89..f4d975a 100644 --- a/lib/TriggerCardAnyDeviceOnOff.ts +++ b/lib/TriggerCardAnyDeviceOnOff.ts @@ -16,13 +16,13 @@ export default class TriggerCardAnyDeviceTurnedOn { capabilityInstances: Map = new Map(); - private constructor(private homey: Homey, private homeyApi: ExtendedHomeyAPIV3Local, private zonesDb: ZonesDb, private log: (...args: unknown[]) => void) { + private constructor(private homey: Homey, private homeyApi: ExtendedHomeyAPIV3Local, private zonesDb: ZonesDb, private log: (...args: unknown[]) => void, private error: (...args: unknown[]) => void) { this.triggerCard = this.homey.flow.getTriggerCard('zone-any-device-on-off'); } - public static async initialize(homey: Homey, homeyApi: ExtendedHomeyAPIV3Local, zonesDb: ZonesDb, log: (...args: unknown[]) => void): Promise { + public static async initialize(homey: Homey, homeyApi: ExtendedHomeyAPIV3Local, zonesDb: ZonesDb, log: (...args: unknown[]) => void, error: (...args: unknown[]) => void): Promise { if (TriggerCardAnyDeviceTurnedOn.instance === null) { - TriggerCardAnyDeviceTurnedOn.instance = new TriggerCardAnyDeviceTurnedOn(homey, homeyApi, zonesDb, log); + TriggerCardAnyDeviceTurnedOn.instance = new TriggerCardAnyDeviceTurnedOn(homey, homeyApi, zonesDb, log, error); await TriggerCardAnyDeviceTurnedOn.instance.setup(); } } @@ -40,6 +40,13 @@ export default class TriggerCardAnyDeviceTurnedOn { this.log('Creating capability instance for device.', { deviceId: device.id, deviceName: device.name }); const onOffInstance = device.makeCapabilityInstance('onoff', async value => { + // Some devices have their onoff capability set to null. + // Assuming that as an invalid state and ignoring it. + if (value === null) { + this.error(`${this.constructor.name}: Received 'null' value for onoff capability. Ignoring this state.`, { deviceId: device.id, deviceName: device.name }); + return; + } + const zone = await this.zonesDb.getZone(device.zone); const tokens = { zone: zone?.name,