mirror of
https://github.com/home-assistant/core.git
synced 2025-07-14 08:47:10 +00:00
Fix trigger template entity issue when coordinator data is None (#143830)
Fix issue when coordinator data is None
This commit is contained in:
parent
3ece672890
commit
469176c59b
@ -63,7 +63,9 @@ class TriggerEntity( # pylint: disable=hass-enforce-class-module
|
|||||||
@callback
|
@callback
|
||||||
def _render_script_variables(self) -> dict:
|
def _render_script_variables(self) -> dict:
|
||||||
"""Render configured variables."""
|
"""Render configured variables."""
|
||||||
return self.coordinator.data["run_variables"]
|
if self.coordinator.data is None:
|
||||||
|
return {}
|
||||||
|
return self.coordinator.data["run_variables"] or {}
|
||||||
|
|
||||||
def _render_templates(self, variables: dict[str, Any]) -> None:
|
def _render_templates(self, variables: dict[str, Any]) -> None:
|
||||||
"""Render templates."""
|
"""Render templates."""
|
||||||
|
@ -118,3 +118,19 @@ async def test_template_state_syntax_error(
|
|||||||
assert entity.state is None
|
assert entity.state is None
|
||||||
assert entity.icon is None
|
assert entity.icon is None
|
||||||
assert entity.entity_picture is None
|
assert entity.entity_picture is None
|
||||||
|
|
||||||
|
|
||||||
|
async def test_script_variables_from_coordinator(hass: HomeAssistant) -> None:
|
||||||
|
"""Test script variables."""
|
||||||
|
coordinator = TriggerUpdateCoordinator(hass, {})
|
||||||
|
entity = TestEntity(hass, coordinator, {})
|
||||||
|
|
||||||
|
assert entity._render_script_variables() == {}
|
||||||
|
|
||||||
|
coordinator.data = {"run_variables": None}
|
||||||
|
|
||||||
|
assert entity._render_script_variables() == {}
|
||||||
|
|
||||||
|
coordinator._execute_update({"value": STATE_ON})
|
||||||
|
|
||||||
|
assert entity._render_script_variables() == {"value": STATE_ON}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user