Skip to content

Commit

Permalink
Ensure all template names are strings (home-assistant#129921)
Browse files Browse the repository at this point in the history
  • Loading branch information
balloob authored and frenck committed Nov 6, 2024
1 parent 995aab8 commit 26d8d53
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
6 changes: 4 additions & 2 deletions homeassistant/components/template/template_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,13 +535,15 @@ def _async_setup_templates(self) -> None:
)
if self._entity_picture_template is not None:
self.add_template_attribute(
"_attr_entity_picture", self._entity_picture_template
"_attr_entity_picture", self._entity_picture_template, cv.string
)
if (
self._friendly_name_template is not None
and not self._friendly_name_template.is_static
):
self.add_template_attribute("_attr_name", self._friendly_name_template)
self.add_template_attribute(
"_attr_name", self._friendly_name_template, cv.string
)

@callback
def async_start_preview(
Expand Down
5 changes: 4 additions & 1 deletion tests/components/template/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from homeassistant.components.template.sensor import TriggerSensorEntity
from homeassistant.const import (
ATTR_ENTITY_PICTURE,
ATTR_FRIENDLY_NAME,
ATTR_ICON,
EVENT_COMPONENT_LOADED,
EVENT_HOMEASSISTANT_START,
Expand Down Expand Up @@ -983,6 +984,7 @@ async def test_self_referencing_sensor_with_icon_and_picture_entity_loop(
"test": {
"value_template": "{{ 1 }}",
"entity_picture_template": "{{ ((states.sensor.test.attributes['entity_picture'] or 0) | int) + 1 }}",
"friendly_name_template": "{{ ((states.sensor.test.attributes['friendly_name'] or 0) | int) + 1 }}",
},
},
}
Expand All @@ -1007,7 +1009,8 @@ async def test_self_referencing_entity_picture_loop(

state = hass.states.get("sensor.test")
assert int(state.state) == 1
assert state.attributes[ATTR_ENTITY_PICTURE] == 2
assert state.attributes[ATTR_ENTITY_PICTURE] == "3"
assert state.attributes[ATTR_FRIENDLY_NAME] == "3"

await hass.async_block_till_done()
assert int(state.state) == 1
Expand Down

0 comments on commit 26d8d53

Please sign in to comment.