Emit OnOffClientClusterHandler attribute_updated events first#642
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #642 +/- ##
=======================================
Coverage 97.29% 97.29%
=======================================
Files 62 62
Lines 10712 10712
=======================================
Hits 10422 10422
Misses 290 290 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
For the alternative solutions, we (unfortunately) can't just remove all So, from my understanding, the old behavior was the following:
I think the solution from this PR with just switching the order should work for all blueprints I've looked at. I don't fully like it though.. Only emitting ZHA events for attribute updates we have not caused ourselves might get a bit weird/complicated now. |
|
Yeah, I'll merge this for now to try and unbreak the remote blueprints. I'm not 100% happy with this, but we can always look for a better solution in the future. |
Proposed change
This changes the
OnOffClientClusterHandlerto first process the event, updating attribute cache and emittingattribute_updatedZHA events, then forwarding the cluster command to emit the ZHA event.Additional information
Issue
There are a lot of blueprints available that use the
restartautomation mode and unfortunately trigger on all ZHA events. Even if they're later ignored in the automations "action" section, the automation will still restart for them, aborting the existing run.Ideally, the automation should only trigger for events that actually need to be processed (filter in triggers section or conditions section). But since this is not the case, we need to change our behavior to not break all of the blueprints.
Previous behavior & alternative solutions
The previous behavior did not emit
attribute_updatedevents at all for remotes, as the normalClusterHandlerwas used, not theClientClusterHandler. Only the latter class includes behavior to emit ZHA events for attribute updates:zha/zha/zigbee/cluster_handlers/__init__.py
Lines 753 to 771 in 3adf2db
Alternatively, I'm thinking if we should just call
ClusterHandler._handle_attribute_updated_event()instead, skipping the ZHA event being emitted inClientClusterHandler. I think that should restore old behavior completely?As a third solution, I can only think of skipping ZHA events being emitted depending on which entity is associated with that cluster handler (where the entity already depends on the device type). This likely won't work nicely though.
Previous TODO:
Investigate not emitting
attribute_updatedevents for entireOnOffcluster (OnOffClientClusterHandler).See "Previous behavior & alternative solutions".
-> EDIT: See: #642 (comment)
Reported on Discord:
Related:
OnOffremote handling)OnOffclient cluster commands not updating attribute cache #635 (PR reintroducingOnOffhandling, now inOnOffClientClusterHandler)