Add a test for template entities that reuse the template (#42404)
This commit is contained in:
parent
45aba9bdf2
commit
935c2df7cb
1 changed files with 37 additions and 0 deletions
|
@ -946,3 +946,40 @@ async def test_self_referencing_icon_with_no_loop(hass, caplog):
|
|||
assert state.state == "extreme"
|
||||
assert state.attributes[ATTR_ICON] == "mdi:hazard-lights"
|
||||
assert "Template loop detected" not in caplog.text
|
||||
|
||||
|
||||
async def test_duplicate_templates(hass):
|
||||
"""Test template entity where the value and friendly name as the same template."""
|
||||
hass.states.async_set("sensor.test_state", "Abc")
|
||||
|
||||
with assert_setup_component(1, sensor.DOMAIN):
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
sensor.DOMAIN,
|
||||
{
|
||||
"sensor": {
|
||||
"platform": "template",
|
||||
"sensors": {
|
||||
"test_template_sensor": {
|
||||
"value_template": "{{ states.sensor.test_state.state }}",
|
||||
"friendly_name_template": "{{ states.sensor.test_state.state }}",
|
||||
}
|
||||
},
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_start()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get("sensor.test_template_sensor")
|
||||
assert state.attributes["friendly_name"] == "Abc"
|
||||
assert state.state == "Abc"
|
||||
|
||||
hass.states.async_set("sensor.test_state", "Def")
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get("sensor.test_template_sensor")
|
||||
assert state.attributes["friendly_name"] == "Def"
|
||||
assert state.state == "Def"
|
||||
|
|
Loading…
Add table
Reference in a new issue