Use Attribute enum in light - #175362
Conversation
|
Hey there @home-assistant/core, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
There was a problem hiding this comment.
Pull request overview
This PR continues the epic (#104) started in #174589, which introduced the LightEntityStateAttribute and LightEntityCapabilityAttribute StrEnums in light/const.py. It replaces raw ATTR_* string constants used to read/compare light entity state and capability attributes with the corresponding enum members, improving type safety and clarity. Since each enum member's value is identical to the original constant string, the change is behavior-preserving.
Changes:
- Migrated state-attribute reads/comparisons in
trigger.py,condition.py,significant_change.py, andreproduce_state.pytoLightEntityStateAttribute. - Migrated capability-attribute reads in
__init__.pytoLightEntityCapabilityAttribute.SUPPORTED_COLOR_MODES. - Restructured
reproduce_state.py'sATTR_GROUP/COLOR_GROUPinto(state_attribute_enum, service_parameter_str)tuples to clearly separate the state attribute (used for reads) from the service-call parameter (used for writes).
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| homeassistant/components/light/trigger.py | Uses LightEntityStateAttribute.BRIGHTNESS in the brightness domain spec and drops the now-unused ATTR_BRIGHTNESS import. |
| homeassistant/components/light/condition.py | Same enum substitution for the brightness condition domain spec. |
| homeassistant/components/light/significant_change.py | Replaces ATTR_* reads with enum members and simplifies imports to LightEntityStateAttribute. |
| homeassistant/components/light/reproduce_state.py | Converts attribute groups to (enum, service_arg) tuples, updates helpers/typing, and removes the unused ATTR_COLOR_MODE import. |
| homeassistant/components/light/init.py | Reads supported_color_modes from state/registry via LightEntityCapabilityAttribute.SUPPORTED_COLOR_MODES. |
I verified that every enum member value matches its original ATTR_* string constant, that no stale ATTR_* references remain after the import changes, and that the reproduce_state.py restructuring keeps reads keyed on the state attribute and writes keyed on the service parameter (identical strings for these groups, so no behavioral change). check_attr_equal is only used within its own module, so its narrowed parameter type is safe.
Proposed change
As follow-up to #174589
Linked to home-assistant/epics#104
Type of change
Additional information
Checklist
ruff format homeassistant tests)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest.requirements_all.txt.Updated by running
python3 -m script.gen_requirements_all.To help with the load of incoming pull requests: