Skip to content

Add attributes to all template platforms - #178762

Open
Petro31 wants to merge 2 commits into
home-assistant:devfrom
Petro31:add-restricted-attributes
Open

Add attributes to all template platforms#178762
Petro31 wants to merge 2 commits into
home-assistant:devfrom
Petro31:add-restricted-attributes

Conversation

@Petro31

@Petro31 Petro31 commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Breaking change

Proposed change

Add attribute templates to the following template entity platforms:

  • alarm_control_panel
  • button
  • cover
  • device_tracker
  • fan
  • image
  • light
  • lock
  • number
  • select
  • switch
  • update
  • weather

Each platform blocks the ability to overwrite CapabilityAttributes and StateAttributes. For example, users cannot set brightness through 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

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

Checklist

  • I understand the code I am submitting and can explain how it works.
  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.
  • Any generated code has been carefully reviewed for correctness and compliance with project standards.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies a diff between library versions and ideally a link to the changelog/release notes is added to the PR description.

To help with the load of incoming pull requests:

@Petro31
Petro31 requested a review from a team as a code owner August 11, 2026 16:52
Copilot AI balanced review requested due to automatic review settings August 11, 2026 16:52

@home-assistant home-assistant Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@home-assistant

Copy link
Copy Markdown
Contributor

Hey there @home-assistant/core, mind taking a look at this pull request as it has been labeled with an integration (template) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of template can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant mark-draft Mark the pull request as draft.
  • @home-assistant ready-for-review Remove the draft status from the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign template Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant update-branch Update the pull request branch with the base branch.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component, problem in config, problem in device, feature-request) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component, problem in config, problem in device, feature-request) on the pull request.

@home-assistant
home-assistant Bot marked this pull request as draft August 11, 2026 16:52
@home-assistant

Copy link
Copy Markdown
Contributor

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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,
Comment on lines +97 to +103
vol.Optional(CONF_ATTRIBUTES): vol.Schema(
vol.All(
{cv.string: cv.template},
_blocked_attributes(
default_name, blocked_attributes, block_device_class
),
)
Comment on lines +79 to +84
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:
@Petro31
Petro31 marked this pull request as ready for review August 11, 2026 16:57
@Petro31 Petro31 added docs-missing new-feature Top 200 Integration is ranked within the top 200 by usage Top 50 Integration is ranked within the top 50 by usage Top 100 Integration is ranked within the top 100 by usage and removed new-integration labels Aug 11, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 attribute fixture with its enum type so every new test parameter has the required type annotation.
    tests/components/template/test_update.py:1012
  • Annotate the parametrized attribute fixture so every new test parameter has the required type annotation.
    tests/components/template/test_select.py:718
  • Annotate the parametrized attribute fixture 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 attribute fixture so every new test parameter has the required type annotation.
    attribute,

tests/components/template/test_lock.py:1191

  • Annotate the parametrized attribute fixture 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 attribute fixture 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 attribute fixture 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 attribute fixture 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 attribute annotation because this parametrization also passes the plain string "device_class".
    attribute: CoverEntityStateAttribute,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

by-code-owner cla-signed has-tests integration: template new-feature Quality Scale: internal Top 50 Integration is ranked within the top 50 by usage Top 100 Integration is ranked within the top 100 by usage Top 200 Integration is ranked within the top 200 by usage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants