Move manual trigger entity tests (#130134)

This commit is contained in:
G Johansson
2024-11-10 12:14:13 +01:00
committed by GitHub
parent 7d2d6a82b0
commit d0ad834d93

View File

@ -0,0 +1,40 @@
"""Test template trigger entity."""
from homeassistant.core import HomeAssistant
from homeassistant.helpers import template
from homeassistant.helpers.trigger_template_entity import ManualTriggerEntity
async def test_template_entity_requires_hass_set(hass: HomeAssistant) -> None:
"""Test manual trigger template entity."""
config = {
"name": template.Template("test_entity", hass),
"icon": template.Template(
'{% if value=="on" %} mdi:on {% else %} mdi:off {% endif %}', hass
),
"picture": template.Template(
'{% if value=="on" %} /local/picture_on {% else %} /local/picture_off {% endif %}',
hass,
),
}
entity = ManualTriggerEntity(hass, config)
entity.entity_id = "test.entity"
hass.states.async_set("test.entity", "on")
await entity.async_added_to_hass()
entity._process_manual_data("on")
await hass.async_block_till_done()
assert entity.name == "test_entity"
assert entity.icon == "mdi:on"
assert entity.entity_picture == "/local/picture_on"
hass.states.async_set("test.entity", "off")
await entity.async_added_to_hass()
entity._process_manual_data("off")
await hass.async_block_till_done()
assert entity.name == "test_entity"
assert entity.icon == "mdi:off"
assert entity.entity_picture == "/local/picture_off"