From b08779f73a90781902b4bb3c9a9b64071b22b75d Mon Sep 17 00:00:00 2001 From: Erik van Leeuwen Date: Fri, 1 Nov 2024 11:03:26 +0100 Subject: [PATCH] Fix flow not starting because of a missing zone name --- lib/TriggerCardAnyDeviceOnOff.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/TriggerCardAnyDeviceOnOff.ts b/lib/TriggerCardAnyDeviceOnOff.ts index f4d975a..8755884 100644 --- a/lib/TriggerCardAnyDeviceOnOff.ts +++ b/lib/TriggerCardAnyDeviceOnOff.ts @@ -40,16 +40,23 @@ export default class TriggerCardAnyDeviceTurnedOn { this.log('Creating capability instance for device.', { deviceId: device.id, deviceName: device.name }); const onOffInstance = device.makeCapabilityInstance('onoff', async value => { + if (value === null) { // 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); + if (zone === null) { + // Not expected to happen but occasionally it does. Log it. + this.error('Zone not found for device.', { deviceId: device.id, zoneId: device.zone }); + } + + const zoneName = zone?.name ?? '[Zone name not found]'; + const tokens = { - zone: zone?.name, + zone: zoneName, deviceName: device.name, deviceClass: this.homey.__(device.class) ?? device.class, state: value