Skip to content

Commit

Permalink
Fix rest sensors with resource templates (#42818)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco authored and balloob committed Nov 4, 2020
1 parent 32652fd commit e4f88a0
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions homeassistant/components/rest/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=

if resource_template is not None:
resource_template.hass = hass
resource = resource_template.render(parse_result=False)
resource = resource_template.async_render(parse_result=False)

if value_template is not None:
value_template.hass = hass
Expand Down Expand Up @@ -189,6 +189,6 @@ async def async_will_remove_from_hass(self):
async def async_update(self):
"""Get the latest data from REST API and updates the state."""
if self._resource_template is not None:
self.rest.set_url(self._resource_template.render(parse_result=False))
self.rest.set_url(self._resource_template.async_render(parse_result=False))

await self.rest.async_update()
4 changes: 2 additions & 2 deletions homeassistant/components/rest/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=

if resource_template is not None:
resource_template.hass = hass
resource = resource_template.render(parse_result=False)
resource = resource_template.async_render(parse_result=False)

if username and password:
if config.get(CONF_AUTHENTICATION) == HTTP_DIGEST_AUTHENTICATION:
Expand Down Expand Up @@ -202,7 +202,7 @@ def force_update(self):
async def async_update(self):
"""Get the latest data from REST API and update the state."""
if self._resource_template is not None:
self.rest.set_url(self._resource_template.render(parse_result=False))
self.rest.set_url(self._resource_template.async_render(parse_result=False))

await self.rest.async_update()

Expand Down
2 changes: 1 addition & 1 deletion tests/components/rest/test_binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ async def test_setup_minimum_resource_template(hass):
{
"binary_sensor": {
"platform": "rest",
"resource_template": "http://localhost",
"resource_template": "{% set url = 'http://localhost' %}{{ url }}",
}
},
)
Expand Down
2 changes: 1 addition & 1 deletion tests/components/rest/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ async def test_setup_minimum_resource_template(hass):
{
"sensor": {
"platform": "rest",
"resource_template": "http://localhost",
"resource_template": "{% set url = 'http://localhost' %}{{ url }}",
}
},
)
Expand Down

0 comments on commit e4f88a0

Please sign in to comment.