mirror of
https://github.com/home-assistant/core.git
synced 2025-07-14 16:57:10 +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:
|
if self._entity_picture_template is not None:
|
||||||
self.add_template_attribute(
|
self.add_template_attribute(
|
||||||
"_attr_entity_picture", self._entity_picture_template
|
"_attr_entity_picture", self._entity_picture_template, cv.string
|
||||||
)
|
)
|
||||||
if (
|
if (
|
||||||
self._friendly_name_template is not None
|
self._friendly_name_template is not None
|
||||||
and not self._friendly_name_template.is_static
|
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
|
@callback
|
||||||
def async_start_preview(
|
def async_start_preview(
|
||||||
|
@ -12,6 +12,7 @@ from homeassistant.components import sensor, template
|
|||||||
from homeassistant.components.template.sensor import TriggerSensorEntity
|
from homeassistant.components.template.sensor import TriggerSensorEntity
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_ENTITY_PICTURE,
|
ATTR_ENTITY_PICTURE,
|
||||||
|
ATTR_FRIENDLY_NAME,
|
||||||
ATTR_ICON,
|
ATTR_ICON,
|
||||||
EVENT_COMPONENT_LOADED,
|
EVENT_COMPONENT_LOADED,
|
||||||
EVENT_HOMEASSISTANT_START,
|
EVENT_HOMEASSISTANT_START,
|
||||||
@ -983,6 +984,7 @@ async def test_self_referencing_sensor_with_icon_and_picture_entity_loop(
|
|||||||
"test": {
|
"test": {
|
||||||
"value_template": "{{ 1 }}",
|
"value_template": "{{ 1 }}",
|
||||||
"entity_picture_template": "{{ ((states.sensor.test.attributes['entity_picture'] or 0) | int) + 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")
|
state = hass.states.get("sensor.test")
|
||||||
assert int(state.state) == 1
|
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()
|
await hass.async_block_till_done()
|
||||||
assert int(state.state) == 1
|
assert int(state.state) == 1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user