Add attributes to all template platforms - #178762
Conversation
There was a problem hiding this comment.
When adding new integrations, limit included platforms to a single platform. While we appreciate the effort, reviewing larger than necessary PRs slows down the review process. Please reduce this PR to a single platform. See the review process for more details.
|
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
|
|
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍 |
There was a problem hiding this comment.
Pull request overview
Adds custom attribute templates across additional Template integration platforms while preventing collisions with platform-managed attributes.
Changes:
- Consolidates shared template entity schemas.
- Enables attribute templates on 12 additional platforms.
- Adds tests for rendering and blocked attributes.
Reviewed changes
Copilot reviewed 31 out of 31 changed files in this pull request and generated 11 comments.
Show a summary per file
| File | Description |
|---|---|
homeassistant/components/template/schemas.py |
Adds shared attribute validation and collision blocking. |
homeassistant/components/template/alarm_control_panel.py |
Enables safe custom attributes. |
homeassistant/components/template/binary_sensor.py |
Adopts the consolidated schema. |
homeassistant/components/template/button.py |
Enables safe custom attributes. |
homeassistant/components/template/cover.py |
Enables safe custom attributes. |
homeassistant/components/template/device_tracker.py |
Enables safe custom attributes. |
homeassistant/components/template/event.py |
Adopts the consolidated schema. |
homeassistant/components/template/fan.py |
Enables safe custom attributes. |
homeassistant/components/template/image.py |
Adopts the consolidated schema. |
homeassistant/components/template/light.py |
Enables safe custom attributes. |
homeassistant/components/template/lock.py |
Enables safe custom attributes. |
homeassistant/components/template/number.py |
Enables safe custom attributes. |
homeassistant/components/template/select.py |
Enables safe custom attributes. |
homeassistant/components/template/sensor.py |
Adopts the consolidated schema. |
homeassistant/components/template/switch.py |
Enables safe custom attributes. |
homeassistant/components/template/update.py |
Enables safe custom attributes. |
homeassistant/components/template/vacuum.py |
Adopts the consolidated schema. |
homeassistant/components/template/weather.py |
Enables safe custom attributes. |
tests/components/template/conftest.py |
Adds reusable attribute test coverage. |
tests/components/template/test_alarm_control_panel.py |
Tests alarm attributes and collisions. |
tests/components/template/test_button.py |
Tests button attributes and collisions. |
tests/components/template/test_cover.py |
Tests cover attributes and collisions. |
tests/components/template/test_device_tracker.py |
Tests tracker attributes and collisions. |
tests/components/template/test_fan.py |
Tests fan attributes and collisions. |
tests/components/template/test_light.py |
Tests light attributes and collisions. |
tests/components/template/test_lock.py |
Tests lock attributes and collisions. |
tests/components/template/test_number.py |
Tests number attributes and collisions. |
tests/components/template/test_select.py |
Tests select attributes and collisions. |
tests/components/template/test_switch.py |
Tests switch attributes and collisions. |
tests/components/template/test_update.py |
Tests update attributes and collisions. |
tests/components/template/test_weather.py |
Tests weather attributes and collisions. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| async def test_blocked_template_attributes( | ||
| hass: HomeAssistant, | ||
| style: ConfigurationStyle, | ||
| attribute, |
| async def test_blocked_template_attributes( | ||
| hass: HomeAssistant, | ||
| style: ConfigurationStyle, | ||
| attribute, |
| async def test_blocked_template_attributes( | ||
| hass: HomeAssistant, | ||
| style: ConfigurationStyle, | ||
| attribute, |
| async def test_blocked_template_attributes( | ||
| hass: HomeAssistant, | ||
| style: ConfigurationStyle, | ||
| attribute, |
| async def test_blocked_template_attributes( | ||
| hass: HomeAssistant, | ||
| style: ConfigurationStyle, | ||
| attribute, |
| async def test_blocked_template_attributes( | ||
| hass: HomeAssistant, | ||
| style: ConfigurationStyle, | ||
| attribute, |
| async def test_blocked_template_attributes( | ||
| hass: HomeAssistant, | ||
| style: ConfigurationStyle, | ||
| attribute, |
| async def test_blocked_template_attributes( | ||
| hass: HomeAssistant, | ||
| style: ConfigurationStyle, | ||
| attribute: CoverEntityStateAttribute, |
| vol.Optional(CONF_ATTRIBUTES): vol.Schema( | ||
| vol.All( | ||
| {cv.string: cv.template}, | ||
| _blocked_attributes( | ||
| default_name, blocked_attributes, block_device_class | ||
| ), | ||
| ) |
| def make_template_entity_common_schema( | ||
| domain: str, | ||
| default_name: str, | ||
| blocked_attributes: tuple[_AttributeEnum, ...] | _AttributeEnum | None = None, | ||
| block_device_class: bool = False, | ||
| ) -> vol.Schema: |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 32 out of 32 changed files in this pull request and generated no new comments.
Suppressed comments (9)
tests/components/template/test_weather.py:1060
- Annotate the parametrized
attributefixture with its enum type so every new test parameter has the required type annotation.
tests/components/template/test_update.py:1012 - Annotate the parametrized
attributefixture so every new test parameter has the required type annotation.
tests/components/template/test_select.py:718 - Annotate the parametrized
attributefixture with its enum type so every new test parameter has the required type annotation.
attribute,
tests/components/template/test_number.py:780
- Annotate the parametrized
attributefixture so every new test parameter has the required type annotation.
attribute,
tests/components/template/test_lock.py:1191
- Annotate the parametrized
attributefixture with its enum type so every new test parameter has the required type annotation.
attribute,
tests/components/template/test_light.py:2263
- Annotate the parametrized
attributefixture with the two enum types so every new test parameter has the required type annotation.
attribute,
tests/components/template/test_fan.py:1643
- Annotate the parametrized
attributefixture with the two enum types so every new test parameter has the required type annotation.
attribute,
tests/components/template/test_device_tracker.py:822
- Annotate the parametrized
attributefixture with its possible enum types so every new test parameter has the required type annotation.
attribute,
tests/components/template/test_cover.py:1315
- Widen the
attributeannotation because this parametrization also passes the plain string"device_class".
attribute: CoverEntityStateAttribute,
Breaking change
Proposed change
Add attribute templates to the following template entity platforms:
Each platform blocks the ability to overwrite CapabilityAttributes and StateAttributes. For example, users cannot set
brightnessthrough attribute templates on template lights.Feature Requests:
https://github.com/orgs/home-assistant/discussions/2782
https://github.com/orgs/home-assistant/discussions/339
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: