node-zwave-js icon indicating copy to clipboard operation
node-zwave-js copied to clipboard

Make ZWaveNode class also emit it's events via this.driver.emit

Open sdrsdr opened this issue 2 years ago • 0 comments

Is your feature request related to a problem? Please describe. This library is mostly used for base of home automation systems where every node must be monitored. But to get a node monitored the code must wait for the node to become sufficiently available and then subscribe to it's events. Plus there are multiple ways a node get available: after system boot, after add

Describe the solution you'd like What I really would like is just to subscribe for some driver events where all node events get routed. This can easily be achieved with few lines of code in Node.ts: All value events are "captured" from the value DB and touted to translateValueEvent method were a single line this.driver.emit("node "+event,this, outArg as any) can be added to the bottom so you can now subscribe on the driver object with on.("node value updated",...) and get the value updated events from all the nodes in the WZ network governed by the driver. Similarly in the onStatusChange method of ZWaveNode where a event is this.emit-ted a complementary this.driver.emit can be added again prefixing the event name with "node " so you can get node alive, node dead, node sleep and node wake up events from the driver itself and omit subscribing for these events on every node that goes in or out of the nework

Describe alternatives you've considered This is pure convenience change not effecting any existing code. The performance impact will be minimal if any. The alternatives are somewhat complex first when the driver is ready you have to enumerate all nodes and attach your event handler then when a node is added you have to attach to that node again. There might be other steps needed that I'm not aware of just to get all node events reported to the code using the library.

Additional context I can work on a PR if this feature get approved.

sdrsdr avatar Aug 14 '22 20:08 sdrsdr