mirror of
https://github.com/home-assistant/core.git
synced 2025-08-02 18:18:21 +00:00
Only render templates if availability is true
This commit is contained in:
parent
d452e957c9
commit
579f44468e
@ -48,7 +48,7 @@ class TriggerEntity( # pylint: disable=hass-enforce-class-module
|
|||||||
**(run_variables or {}),
|
**(run_variables or {}),
|
||||||
}
|
}
|
||||||
|
|
||||||
self._render_availability_template(variables)
|
if self._render_availability_template(variables):
|
||||||
self._render_templates(variables)
|
self._render_templates(variables)
|
||||||
|
|
||||||
self.async_set_context(self.coordinator.data["context"])
|
self.async_set_context(self.coordinator.data["context"])
|
||||||
|
@ -176,7 +176,7 @@ class TriggerBaseEntity(Entity):
|
|||||||
extra_state_attributes[attr] = last_state.attributes[attr]
|
extra_state_attributes[attr] = last_state.attributes[attr]
|
||||||
self._rendered[CONF_ATTRIBUTES] = extra_state_attributes
|
self._rendered[CONF_ATTRIBUTES] = extra_state_attributes
|
||||||
|
|
||||||
def _render_availability_template(self, variables: dict[str, Any]) -> None:
|
def _render_availability_template(self, variables: dict[str, Any]) -> bool:
|
||||||
"""Render availability template."""
|
"""Render availability template."""
|
||||||
rendered = dict(self._static_rendered)
|
rendered = dict(self._static_rendered)
|
||||||
key = CONF_AVAILABILITY
|
key = CONF_AVAILABILITY
|
||||||
@ -191,11 +191,13 @@ class TriggerBaseEntity(Entity):
|
|||||||
self._config[key],
|
self._config[key],
|
||||||
variables,
|
variables,
|
||||||
)
|
)
|
||||||
|
return False
|
||||||
except TemplateError as err:
|
except TemplateError as err:
|
||||||
logging.getLogger(f"{__package__}.{self.entity_id.split('.')[0]}").error(
|
logging.getLogger(f"{__package__}.{self.entity_id.split('.')[0]}").error(
|
||||||
"Error rendering %s template for %s: %s", key, self.entity_id, err
|
"Error rendering %s template for %s: %s", key, self.entity_id, err
|
||||||
)
|
)
|
||||||
self._rendered = rendered
|
self._rendered = rendered
|
||||||
|
return True
|
||||||
|
|
||||||
def _render_templates(self, variables: dict[str, Any]) -> None:
|
def _render_templates(self, variables: dict[str, Any]) -> None:
|
||||||
"""Render templates."""
|
"""Render templates."""
|
||||||
@ -265,7 +267,7 @@ class ManualTriggerEntity(TriggerBaseEntity):
|
|||||||
"this": TemplateStateFromEntityId(self.hass, self.entity_id),
|
"this": TemplateStateFromEntityId(self.hass, self.entity_id),
|
||||||
**(run_variables or {}),
|
**(run_variables or {}),
|
||||||
}
|
}
|
||||||
self._render_availability_template(variables)
|
if self._render_availability_template(variables):
|
||||||
self._render_templates(variables)
|
self._render_templates(variables)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user