mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 00:37:53 +00:00
Ensure all template names are strings (#129921)
This commit is contained in:
parent
5f13db2356
commit
a927312fb5
@ -535,13 +535,15 @@ class TemplateEntity(Entity): # pylint: disable=hass-enforce-class-module
|
||||
)
|
||||
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(
|
||||
|
@ -12,6 +12,7 @@ from homeassistant.components import sensor, template
|
||||
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,
|
||||
@ -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 }}",
|
||||
},
|
||||
},
|
||||
}
|
||||
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user