My app registers for all devices a capacity listener (only for onoff) .
But when a device is turned on or off, it fires a random amount of times.
In some cases I saw 4 to 6 times the same event for the same device. It increases and decreases completely unpredictable.
I register the capacity listener per device once during initialization of the app:
protected async wireEvents(api: any, devices: Map<string, HomeyAPITypes.HomeyAPIV3Local.ManagerDevices.Device>): Promise<void> {
//await api.devices.connect();
api.devices.on("device.create", (device: any) => { this.addEntity(device as HomeyAPITypes.HomeyAPIV3Local.ManagerDevices.Device); });
api.devices.on("device.update", (device: any) => { this.updateEntity(device as HomeyAPITypes.HomeyAPIV3Local.ManagerDevices.Device); });
api.devices.on("device.delete", (device: any) => { this.deleteEntity(device as HomeyAPITypes.HomeyAPIV3Local.ManagerDevices.Device); });
for(let deviceId of devices.keys()) {
let device = devices.get(deviceId)!;
if(!device.capabilities.includes(DeviceCapabilities.onOff)) continue;
device.makeCapabilityInstance(DeviceCapabilities.onOff, async (newValue: any) => { await this.updateOnOffCapability(device.id, newValue); });
}
}
I’ve tried removing the api.devices.on("device.xxx", …) listeners, but they are unrelated.
private async updateOnOffCapability(deviceId: string, newValue: any): Promise<void> {
// LOGGING IN SCREENSHOT ↓
this.app.log(`Device '${deviceId}' onoff capability changed to '${newValue}'.`);
let device = this.getDeviceById(deviceId);
if(device === null) {
throw new Error(`Device with ID '${deviceId}' not found.`);
}
this.app.emit(EventNames.deviceOnOffChange, new DeviceOnOffChangeEventArguments(device, newValue));
}
Does anyone have an idea why this is happening?
Please help, I have the feeling I’ve tried everything.
I’ve compare the behavior of my app with Device Capabilities App, and that app works perfectly, so I must be doing something wrong…
Thanks in advance for any help.
device-capabilities
