Skip to content

Commit

Permalink
Fix flow not starting because of a missing zone name
Browse files Browse the repository at this point in the history
  • Loading branch information
Erikvl87 committed Nov 1, 2024
1 parent 089bd57 commit b08779f
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/TriggerCardAnyDeviceOnOff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b08779f

Please sign in to comment.