Add type hints to template helper (#81308)
* Add type hints to template helper * Update homeassistant/helpers/template.py * Adjust use of ensure_compiledpull/81352/head^2
parent
9bc029000a
commit
5e05739019
|
@ -559,8 +559,11 @@ class Template:
|
|||
|
||||
@callback
|
||||
def async_render_with_possible_json_value(
|
||||
self, value, error_value=_SENTINEL, variables=None
|
||||
):
|
||||
self,
|
||||
value: Any,
|
||||
error_value: Any = _SENTINEL,
|
||||
variables: dict[str, Any] | None = None,
|
||||
) -> Any:
|
||||
"""Render template with value exposed.
|
||||
|
||||
If valid JSON will expose value_json too.
|
||||
|
@ -570,8 +573,7 @@ class Template:
|
|||
if self.is_static:
|
||||
return self.template
|
||||
|
||||
if self._compiled is None:
|
||||
self._ensure_compiled()
|
||||
compiled = self._compiled or self._ensure_compiled()
|
||||
|
||||
variables = dict(variables or {})
|
||||
variables["value"] = value
|
||||
|
@ -580,9 +582,7 @@ class Template:
|
|||
variables["value_json"] = json_loads(value)
|
||||
|
||||
try:
|
||||
return _render_with_context(
|
||||
self.template, self._compiled, **variables
|
||||
).strip()
|
||||
return _render_with_context(self.template, compiled, **variables).strip()
|
||||
except jinja2.TemplateError as ex:
|
||||
if error_value is _SENTINEL:
|
||||
_LOGGER.error(
|
||||
|
|
Loading…
Reference in New Issue