I'm writing an app to control linked switches with a master switch.
What I have encountered is when a switch is toggled manually i get a single event, e.g:
dev:2682019-10-08 11:04:48.813 pm infoHallway Light (Virtual) was turned off
dev:2682019-10-08 11:04:41.730 pm infoHallway Light (Virtual) was turned on
However when the same switch is toggled using a command it fires 2 events, e.g:
dev:2682019-10-08 11:06:03.993 pm infoHallway Light (Virtual) was turned off
dev:2682019-10-08 11:06:03.986 pm infoHallway Light (Virtual) was turned off
dev:2682019-10-08 11:06:02.769 pm infoHallway Light (Virtual) was turned on
dev:2682019-10-08 11:06:02.724 pm infoHallway Light (Virtual) was turned on
This creates additional problem of handling the duplicate events, which will result in adding workarounds and complicate the code unnecessary.
Ideally there should be no duplicate event or there should be a way to differentiate the 2 events. I am using Nue Zigbee Switch
driver and I suspect the driver is firing the event from inside the on
and off
commands and also from the parse
method.
So my thoughts on possible solution:
- I guess simplest is to update the driver not to fire a second event if state has not changed (e.g. if
on()
command was called it would fire the event, changing state toon
, then inparse()
it would check the state and not fire the on event since alreadyon
) - Alternatively could extend the event model to be able to pass additional data to indicate what triggered the event, e.g.
src = "command"
orsrc = "device"
).
Is there anything else I could use instead?