Skip to content

Commit

Permalink
Ignore 'null' values for the onoff capability
Browse files Browse the repository at this point in the history
  • Loading branch information
Erikvl87 committed Sep 30, 2024
1 parent 813bce0 commit 089bd57
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
13 changes: 10 additions & 3 deletions lib/TriggerCardAnyDeviceOnOff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ export default class TriggerCardAnyDeviceTurnedOn {

capabilityInstances: Map<string, ExtendedDeviceCapability> = 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<void> {
public static async initialize(homey: Homey, homeyApi: ExtendedHomeyAPIV3Local, zonesDb: ZonesDb, log: (...args: unknown[]) => void, error: (...args: unknown[]) => void): Promise<void> {
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();
}
}
Expand All @@ -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,
Expand Down

0 comments on commit 089bd57

Please sign in to comment.