Fix trigger template entity issue when coordinator data is None (#143830)

Fix issue when coordinator data is None
This commit is contained in:
Petro31 2025-04-28 08:32:16 -04:00 committed by GitHub
parent 3ece672890
commit 469176c59b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 1 deletions

View File

@ -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."""

View File

@ -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}