Reduce number of virtual entities#782
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #782 +/- ##
==========================================
+ Coverage 97.41% 97.42% +0.01%
==========================================
Files 50 50
Lines 10419 10463 +44
==========================================
+ Hits 10150 10194 +44
Misses 269 269 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| async def async_initialize_cluster(self, cluster: zigpy.zcl.Cluster) -> None: | ||
| """Mirror detection_interval into the sibling IAS Zone handler.""" | ||
| interval = cluster.get("detection_interval", cluster.get(0x0102)) | ||
| if interval is None: | ||
| return | ||
| ias_zone = getattr(cluster.endpoint, "ias_zone", None) | ||
| if ias_zone is None: | ||
| return | ||
| self.debug("Loaded detection interval at startup: %s", interval) | ||
| ias_zone.reset_s = int(interval) |
There was a problem hiding this comment.
This logic was always weird to have inside of ZHA. We still need to keep it somewhere (and not just delete it completely). But I don't think we can restore reset_s on startup / appdb load entirely in quirks. __init__ won't have any cached attributes loaded, and I'm not sure where else this could be put to load on startup.
But maybe we can just add a "reset_after" property to the cluster, with it defaulting to the local reset_s attribute, but then override it with the attribute access to detection_interval in the Aqara quirk?
That way, we don't need to load reset_s right on startup / appdb load, but just when it's needed. And we always have the fresh value, so we can also remove the override when changing/writing the attribute (here). I think that's a bit cleaner in general.
This PR reduces the number of virtual entities by propagating some of the implicit attribute config to their respective entities. The few remaining virtual entities can be moved to quirks in the near future.