From 3223332c1e53f437451b1d1bcb1de63524baa640 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Wed, 8 Dec 2021 12:19:22 -0800 Subject: [PATCH] Use correct template parameter in Rest template rendering (#61269) --- homeassistant/components/rest/data.py | 4 ++-- homeassistant/components/rest/switch.py | 8 ++++---- homeassistant/components/rest/utils.py | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/homeassistant/components/rest/data.py b/homeassistant/components/rest/data.py index 513f2393127..e9fbb5718a5 100644 --- a/homeassistant/components/rest/data.py +++ b/homeassistant/components/rest/data.py @@ -52,8 +52,8 @@ class RestData: self._hass, verify_ssl=self._verify_ssl ) - rendered_headers = render_templates(self._headers) - rendered_params = render_templates(self._params) + rendered_headers = render_templates(self._headers, False) + rendered_params = render_templates(self._params, True) _LOGGER.debug("Updating from %s", self._resource) try: diff --git a/homeassistant/components/rest/switch.py b/homeassistant/components/rest/switch.py index 3448b79979c..1fd04b66559 100644 --- a/homeassistant/components/rest/switch.py +++ b/homeassistant/components/rest/switch.py @@ -207,8 +207,8 @@ class RestSwitch(SwitchEntity): """Send a state update to the device.""" websession = async_get_clientsession(self.hass, self._verify_ssl) - rendered_headers = render_templates(self._headers) - rendered_params = render_templates(self._params) + rendered_headers = render_templates(self._headers, False) + rendered_params = render_templates(self._params, True) async with async_timeout.timeout(self._timeout): req = await getattr(websession, self._method)( @@ -233,8 +233,8 @@ class RestSwitch(SwitchEntity): """Get the latest data from REST API and update the state.""" websession = async_get_clientsession(hass, self._verify_ssl) - rendered_headers = render_templates(self._headers) - rendered_params = render_templates(self._params) + rendered_headers = render_templates(self._headers, False) + rendered_params = render_templates(self._params, True) async with async_timeout.timeout(self._timeout): req = await websession.get( diff --git a/homeassistant/components/rest/utils.py b/homeassistant/components/rest/utils.py index 35b3c22db31..f3fdba651ac 100644 --- a/homeassistant/components/rest/utils.py +++ b/homeassistant/components/rest/utils.py @@ -15,13 +15,13 @@ def inject_hass_in_templates_list( tpl.hass = hass -def render_templates(tpl_dict: dict[str, Template] | None): +def render_templates(tpl_dict: dict[str, Template] | None, parse_result: bool): """Render a dict of templates.""" if tpl_dict is None: return None rendered_items = {} - for item_name, template_header in tpl_dict.items(): - if (value := template_header.async_render()) is not None: - rendered_items[item_name] = str(value) + for item_name, template in tpl_dict.items(): + if (value := template.async_render(parse_result=parse_result)) is not None: + rendered_items[item_name] = value return rendered_items