Is there a way for a device to listen to events emitted for a different device in the same driver? For example, Device B wants to update when Device A comes online.
I am calling deviceA:online() and want deviceB to react
Is there a way for a device to listen to events emitted for a different device in the same driver? For example, Device B wants to update when Device A comes online.
I am calling deviceA:online() and want deviceB to react
What are you looking for deviceB to do? driver:get_devices()
returns a list of all the device objects that belong to that driver, and then you can do whatever you want to each of them based on the logic defined. I would assume you’d identify deviceB and kick off whatever activity you want in the same function where you’re setting deviceA to online.
I currently have deviceA find and call deviceB as you laid out above. From a coding standpoint, I prefer for deviceA not to know about the other devices and their capabilities. All devices know about deviceA already as deviceA is a hub.
I haven’t come across anything that would allow a device to subscribe to/react to another device’s (or even its own) events. I think the hub would have to prompt the child devices to take action.
Would inject_capability_command get you closer to what you’re looking for? If the hub comes back online, I could see it being reasonable to have it inject a refresh command for each of the child devices, which would then be processed by the refresh handler in the sub-driver. All that the hub would need to know about the children is that they each have the refresh capability (or whichever capability you choose to use) on their main component.
This could work. I will try this route. I know the child devices. I just don’t want to know what they are.
@philh30 for the win. That did it. Works great. When the bridge comes online, I get its child devices, ask if they support refresh, and then send them a capability command.