mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Fix rest sensors with resource templates (#42818)
This commit is contained in:
parent
b71e28dfac
commit
9e0043fb17
@ -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
|
||||
@ -189,6 +189,6 @@ class RestBinarySensor(BinarySensorEntity):
|
||||
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()
|
||||
|
@ -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:
|
||||
@ -202,7 +202,7 @@ class RestSensor(Entity):
|
||||
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()
|
||||
|
||||
|
@ -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 }}",
|
||||
}
|
||||
},
|
||||
)
|
||||
|
@ -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 }}",
|
||||
}
|
||||
},
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user