Skip to content

Commit

Permalink
Template rendering failed: fix #27
Browse files Browse the repository at this point in the history
  • Loading branch information
danieldotnl committed Jun 16, 2021
1 parent c38fce2 commit 958dbde
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
5 changes: 4 additions & 1 deletion custom_components/multiscrape/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,17 @@ def _update_from_rest_data(self):
select = sensor_attribute.get(CONF_SELECT)
if select is not None:
select.hass = self._hass
select = select.async_render()
select = select.render(parse_result=False)
_LOGGER.debug(
"Parsed binary sensor attribute select template: %s", select
)

select_attr = sensor_attribute.get(CONF_ATTR)
index = sensor_attribute.get(CONF_INDEX)

value_template = sensor_attribute.get(CONF_VALUE_TEMPLATE)
if value_template:
value_template.hass = self._hass
attr_value = self._scrape(
self.rest.soup, select, select_attr, index, value_template
)
Expand Down
8 changes: 5 additions & 3 deletions custom_components/multiscrape/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ def extra_state_attributes(self):
def _update_from_rest_data(self):
"""Update state from the rest data."""

self._select = self._select_template.async_render(parse_result=False)
_LOGGER.debug("Parsed select template: %s", self._select)
self._select = self._select_template.async_render(parse_result=True)
_LOGGER.debug("Rendered select template: %s", self._select)

value = self._scrape(
self.rest.soup,
Expand All @@ -169,12 +169,14 @@ def _update_from_rest_data(self):
select = sensor_attribute.get(CONF_SELECT)
if select is not None:
select.hass = self._hass
select = select.async_render(parse_result=False)
select = select.render(parse_result=False)
_LOGGER.debug("Parsed sensor attribute select template: %s", select)

select_attr = sensor_attribute.get(CONF_ATTR)
index = sensor_attribute.get(CONF_INDEX)
value_template = sensor_attribute.get(CONF_VALUE_TEMPLATE)
if value_template:
value_template.hass = self._hass
attr_value = self._scrape(
self.rest.soup, select, select_attr, index, value_template
)
Expand Down

0 comments on commit 958dbde

Please sign in to comment.