mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 21:06:19 +00:00
Parse template result in async_render_with_possible_json_value (#99670)
* Optionally parse templates rendered with possible json * Remove duplicate strip * Add tests for parsing template result
This commit is contained in:
@@ -1728,6 +1728,26 @@ def test_render_with_possible_json_value_non_string_value(hass: HomeAssistant) -
|
||||
assert tpl.async_render_with_possible_json_value(value) == expected
|
||||
|
||||
|
||||
def test_render_with_possible_json_value_and_parse_result(hass: HomeAssistant) -> None:
|
||||
"""Render with possible JSON value with valid JSON."""
|
||||
tpl = template.Template("{{ value_json.hello }}", hass)
|
||||
result = tpl.async_render_with_possible_json_value(
|
||||
"""{"hello": {"world": "value1"}}""", parse_result=True
|
||||
)
|
||||
assert isinstance(result, dict)
|
||||
|
||||
|
||||
def test_render_with_possible_json_value_and_dont_parse_result(
|
||||
hass: HomeAssistant,
|
||||
) -> None:
|
||||
"""Render with possible JSON value with valid JSON."""
|
||||
tpl = template.Template("{{ value_json.hello }}", hass)
|
||||
result = tpl.async_render_with_possible_json_value(
|
||||
"""{"hello": {"world": "value1"}}""", parse_result=False
|
||||
)
|
||||
assert isinstance(result, str)
|
||||
|
||||
|
||||
def test_if_state_exists(hass: HomeAssistant) -> None:
|
||||
"""Test if state exists works."""
|
||||
hass.states.async_set("test.object", "available")
|
||||
|
||||
Reference in New Issue
Block a user