Extract entity template functions into an entity Jinja2 extension#167992
Open
Extract entity template functions into an entity Jinja2 extension#167992
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request continues the ongoing Home Assistant template refactor by extracting the entity-related template helpers into a dedicated Jinja2 extension, keeping behavior and coverage equivalent while reducing the monolithic template module surface.
Changes:
- Added a new
EntityExtensionthat providesentity_name(global + filter) andis_hidden_entity(global + test). - Removed the legacy
entity_name/is_hidden_entityimplementations and manual registration fromhomeassistant/helpers/template/__init__.py. - Relocated the corresponding unit tests from the template init test module into the extensions test suite.
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 |
|---|---|
tests/helpers/template/test_init.py |
Removes entity-related tests and drops now-unneeded registry imports. |
tests/helpers/template/extensions/test_entities.py |
Adds dedicated extension tests for entity_name and is_hidden_entity. |
homeassistant/helpers/template/extensions/entities.py |
Introduces EntityExtension implementing entity_name and is_hidden_entity. |
homeassistant/helpers/template/extensions/__init__.py |
Exports EntityExtension for extension loading by dotted path. |
homeassistant/helpers/template/__init__.py |
Registers EntityExtension and removes legacy function definitions and limited-template stubs for these names. |
thecode
approved these changes
Apr 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Proposed change
This PR is part of the ongoing effort to refactor our huge single template monolith into something more maintainable. In previous PRs I've moved many categories of template methods out of the monolith template file into their own Jinja2 extension.
This PR moves the entity template functions (
entity_name,is_hidden_entity) into their own Jinja2 extension. Moves all tests as well.There is no functional change in this PR, it is only moving these methods and tests into an extension.
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: