mirror of
https://github.com/home-assistant/core.git
synced 2025-09-11 07:41:35 +02:00
Add object_id to modern template syntax (#150489)
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
@@ -26,6 +26,7 @@ TEMPLATE_ENTITY_BASE_SCHEMA = vol.Schema(
|
||||
vol.Optional(CONF_NAME): cv.template,
|
||||
vol.Optional(CONF_PICTURE): cv.template,
|
||||
vol.Optional(CONF_UNIQUE_ID): cv.string,
|
||||
vol.Optional(CONF_OBJECT_ID): cv.string,
|
||||
}
|
||||
)
|
||||
|
||||
|
@@ -18,3 +18,13 @@ async def test_template_entity_requires_hass_set(hass: HomeAssistant) -> None:
|
||||
entity.add_template_attribute("_hello", tpl_with_hass)
|
||||
|
||||
assert len(entity._template_attrs.get(tpl_with_hass, [])) == 1
|
||||
|
||||
|
||||
async def test_object_id(hass: HomeAssistant) -> None:
|
||||
"""Test template entity creates suggested entity_id from the object_id."""
|
||||
|
||||
class TemplateTest(template_entity.TemplateEntity):
|
||||
_entity_id_format = "test.{}"
|
||||
|
||||
entity = TemplateTest(hass, {"object_id": "test"}, "a")
|
||||
assert entity.entity_id == "test.test"
|
||||
|
@@ -17,6 +17,7 @@ class TestEntity(trigger_entity.TriggerEntity):
|
||||
"""Test entity class."""
|
||||
|
||||
__test__ = False
|
||||
_entity_id_format = "test.{}"
|
||||
extra_template_keys = (CONF_STATE,)
|
||||
|
||||
@property
|
||||
@@ -134,3 +135,10 @@ async def test_script_variables_from_coordinator(hass: HomeAssistant) -> None:
|
||||
coordinator._execute_update({"value": STATE_ON})
|
||||
|
||||
assert entity._render_script_variables() == {"value": STATE_ON}
|
||||
|
||||
|
||||
async def test_object_id(hass: HomeAssistant) -> None:
|
||||
"""Test template entity creates suggested entity_id from the object_id."""
|
||||
coordinator = TriggerUpdateCoordinator(hass, {})
|
||||
entity = TestEntity(hass, coordinator, {"object_id": "test"})
|
||||
assert entity.entity_id == "test.test"
|
||||
|
Reference in New Issue
Block a user