mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 21:06:19 +00:00
Add support for using a single endpoint for rest data (#46711)
This commit is contained in:
@@ -91,6 +91,38 @@ async def test_setup_minimum(hass):
|
||||
assert len(hass.states.async_all()) == 1
|
||||
|
||||
|
||||
@respx.mock
|
||||
async def test_manual_update(hass):
|
||||
"""Test setup with minimum configuration."""
|
||||
await async_setup_component(hass, "homeassistant", {})
|
||||
respx.get("http://localhost").respond(status_code=200, json={"data": "first"})
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
sensor.DOMAIN,
|
||||
{
|
||||
"sensor": {
|
||||
"name": "mysensor",
|
||||
"value_template": "{{ value_json.data }}",
|
||||
"platform": "rest",
|
||||
"resource_template": "{% set url = 'http://localhost' %}{{ url }}",
|
||||
"method": "GET",
|
||||
}
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert len(hass.states.async_all()) == 1
|
||||
assert hass.states.get("sensor.mysensor").state == "first"
|
||||
|
||||
respx.get("http://localhost").respond(status_code=200, json={"data": "second"})
|
||||
await hass.services.async_call(
|
||||
"homeassistant",
|
||||
"update_entity",
|
||||
{ATTR_ENTITY_ID: ["sensor.mysensor"]},
|
||||
blocking=True,
|
||||
)
|
||||
assert hass.states.get("sensor.mysensor").state == "second"
|
||||
|
||||
|
||||
@respx.mock
|
||||
async def test_setup_minimum_resource_template(hass):
|
||||
"""Test setup with minimum configuration (resource_template)."""
|
||||
|
||||
Reference in New Issue
Block a user