Cache transient templates compiles provided via api (#89065)
* Cache transient templates compiles provided via api
partially fixes #89047 (there is more going on here)
* add a bit more coverage just to be sure
* switch method
* Revert "switch method"
This reverts commit 0e9e1c8cbe
.
* tweak
* hold hass
* empty for github flakey
This commit is contained in:
parent
7365522d1f
commit
48b93e03ee
4 changed files with 70 additions and 4 deletions
|
@ -349,6 +349,52 @@ async def test_api_template(hass: HomeAssistant, mock_api_client: TestClient) ->
|
|||
|
||||
assert body == "10"
|
||||
|
||||
hass.states.async_set("sensor.temperature", 20)
|
||||
resp = await mock_api_client.post(
|
||||
const.URL_API_TEMPLATE,
|
||||
json={"template": "{{ states.sensor.temperature.state }}"},
|
||||
)
|
||||
|
||||
body = await resp.text()
|
||||
|
||||
assert body == "20"
|
||||
|
||||
hass.states.async_remove("sensor.temperature")
|
||||
resp = await mock_api_client.post(
|
||||
const.URL_API_TEMPLATE,
|
||||
json={"template": "{{ states.sensor.temperature.state }}"},
|
||||
)
|
||||
|
||||
body = await resp.text()
|
||||
|
||||
assert body == ""
|
||||
|
||||
|
||||
async def test_api_template_cached(
|
||||
hass: HomeAssistant, mock_api_client: TestClient
|
||||
) -> None:
|
||||
"""Test the template API uses the cache."""
|
||||
hass.states.async_set("sensor.temperature", 30)
|
||||
|
||||
resp = await mock_api_client.post(
|
||||
const.URL_API_TEMPLATE,
|
||||
json={"template": "{{ states.sensor.temperature.state }}"},
|
||||
)
|
||||
|
||||
body = await resp.text()
|
||||
|
||||
assert body == "30"
|
||||
|
||||
hass.states.async_set("sensor.temperature", 40)
|
||||
resp = await mock_api_client.post(
|
||||
const.URL_API_TEMPLATE,
|
||||
json={"template": "{{ states.sensor.temperature.state }}"},
|
||||
)
|
||||
|
||||
body = await resp.text()
|
||||
|
||||
assert body == "40"
|
||||
|
||||
|
||||
async def test_api_template_error(
|
||||
hass: HomeAssistant, mock_api_client: TestClient
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue