Declare capability attributes on ZclPlatformEntity and refresh capabilities on their events
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 25/100
Research direction
Start with ZclPlatformEntity and its handle_attribute_updated() in zha/application/platforms, then compare AnalogOutputNumber, Cover and NumberConfigurationEntity in number/init.py and cover/init.py. Check how _server_cluster_config and AttrConfig are declared, and where Device.recompute_entities() is used by tests. Done means a single declared attribute list on the base class refreshes capabilities and emits state, and both number classes and Cover migrate to it.
Written by the indexing model from the issue text.
Description
Summary
Entities whose capabilities (range, features, device class, name) come from cluster attributes compute them when they are added. Device.recompute_entities() recomputes them too, but only the tests call it, so a later change to one of those attributes leaves the entity stale until the next restart. Three classes refresh on attribute events today, each in its own way:
AnalogOutputNumber:_capability_attribute_ids(attribute ids), checked in itshandle_attribute_updated(), since zigpy/zha#917 (number/init.py, handler).Cover: a hard-codedwindow_covering_typebranch inhandle_attribute_updated()(cover/init.py).NumberConfigurationEntity:_capability_attribute_names(attribute names), since zigpy/zha#1059, used by the min/max heat setpoint limit numbers (number/init.py, handler).
The idea: one declaration on ZclPlatformEntity, handled in one place (recompute the capabilities, then emit the state), so a class opts in by listing its attributes instead of overriding handle_attribute_updated(). Raised on zigpy/zha#1059.
Design points
- Per cluster. Some inputs live on a cluster other than
self._cluster(the Thermostat's fan cluster, the Light's color cluster), so a flat set of attribute names or ids is not enough. One option is a flag onAttrConfigin_server_cluster_config(e.g.capability=True): that config already lists these attributes per cluster with their read settings, and the base class would subscribe to the flagged ones. The other is a class attribute mapping cluster id to attribute ids. - Ids or names. The two number classes key by different things today; the shared version should pick one and migrate both.
- Subclass handlers. Most
handle_attribute_updated()overrides return early for attributes they don't track, so the generic refresh has to run independently of them, not as a branch a subclass can skip. Lightcan't opt in as is.Light.recompute_capabilities()also seeds live state from the cache and would bypass the transition buffer, see zigpy/zha#940 section 2. Its state seeding has to move out first.
Candidates on dev that don't refresh today
StartUpColorTemperatureConfigurationEntity:color_temp_physical_min/color_temp_physical_maxset the range.AnalogInputSensor:description,application_type, the units andresolution(the example in zigpy/zha#940).BinaryInputWithDescription/BinaryOutputSwitch:descriptionsets the fallback name.IASZone:zone_typesets the device class and translation key.Thermostat:ctrl_sequence_of_operdecides theTARGET_TEMPERATURE_RANGEfeature (the HVAC mode list itself is read live).SmartEnergyMetering:unit_of_measurepicks the entity description.
Most of these are fixed by the device, so the realistic trigger is a first successful read after the entity was added, the re-initialization case of zigpy/zha#940 section 2. A read fires an attribute event, so an event-driven refresh of the declared attributes is the generic form of that issue's "per-class refreshes on attribute events" option.
Related
- zigpy/zha#940: compute capabilities centrally, and stale capabilities after re-initialization.
- zigpy/zha#917 and zigpy/zha#1059: the two per-class refreshes above.
- Dominant language
- Python
- Stars
- 96
- Forks
- 84
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 30
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from zigpy/zha
-
Device override creates the generic entity instead of the vendor-specific one (Light instead of HueLight, ForceOnLight, MinTransitionLight)Possibly taken @zigpy-review-bot claimed this today. Openbot: code audit
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
Each time a device becomes available again, ZHA adds another firmware update listener that is never releasedPossibly taken @zigpy-review-bot claimed this 1 day ago. Openbot: code audit
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
Maintainers usually reply within 1 day
-
Devices that left the network are re-initialized on every availability check, reading attributes from a device that is gonePossibly taken @zigpy-review-bot claimed this 1 day ago. Openbot: code audit
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
Maintainers usually reply within 1 day
-
device specific quirks
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
pimutils/vdirsyncer#1242 ·
-
priority:P2
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
QuantConnect/lean-cli#792 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
open-webui/open-webui#35360 · 1 comment ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
Suggest link: Destiny Verify (MIT zero-dependency pre-commit security, citation & link hygiene CLI)Open
Difficulty 1/5 Under an hour Newbie friendliness 68/100