From 5e05739019774f0647f8e442dccfd210ae168cf0 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Mon, 7 Nov 2022 09:41:53 +0100 Subject: [PATCH] Add type hints to template helper (#81308) * Add type hints to template helper * Update homeassistant/helpers/template.py * Adjust use of ensure_compiled --- homeassistant/helpers/template.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/homeassistant/helpers/template.py b/homeassistant/helpers/template.py index dfab80e5223..24852ab5cf3 100644 --- a/homeassistant/helpers/template.py +++ b/homeassistant/helpers/template.py @@ -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(