Add native Python types support to templates (#41227)
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
This commit is contained in:
parent
cbb4324c84
commit
ee914366a8
29 changed files with 349 additions and 282 deletions
|
@ -194,8 +194,8 @@ async def test_multiple_runs_no_wait(hass):
|
|||
|
||||
calls.append(service)
|
||||
logger.debug("simulated service (%s:%s) started", fire, listen)
|
||||
unsub = hass.bus.async_listen(listen, service_done_cb)
|
||||
hass.bus.async_fire(fire)
|
||||
unsub = hass.bus.async_listen(str(listen), service_done_cb)
|
||||
hass.bus.async_fire(str(fire))
|
||||
await service_done.wait()
|
||||
unsub()
|
||||
|
||||
|
@ -834,14 +834,14 @@ async def test_wait_variables_out(hass, mode, action_type):
|
|||
assert not script_obj.is_running
|
||||
assert len(events) == 1
|
||||
if action_type == "template":
|
||||
assert events[0].data["completed"] == str(mode != "timeout_not_finish")
|
||||
assert events[0].data["completed"] == (mode != "timeout_not_finish")
|
||||
elif mode != "timeout_not_finish":
|
||||
assert "'to_state': <state switch.test=off" in events[0].data["trigger"]
|
||||
else:
|
||||
assert events[0].data["trigger"] == "None"
|
||||
assert events[0].data["trigger"] is None
|
||||
remaining = events[0].data["remaining"]
|
||||
if mode == "no_timeout":
|
||||
assert remaining == "None"
|
||||
assert remaining is None
|
||||
elif mode == "timeout_finish":
|
||||
assert 0.0 < float(remaining) < 5
|
||||
else:
|
||||
|
@ -977,9 +977,9 @@ async def test_repeat_count(hass):
|
|||
|
||||
assert len(events) == count
|
||||
for index, event in enumerate(events):
|
||||
assert event.data.get("first") == str(index == 0)
|
||||
assert event.data.get("index") == str(index + 1)
|
||||
assert event.data.get("last") == str(index == count - 1)
|
||||
assert event.data.get("first") == (index == 0)
|
||||
assert event.data.get("index") == index + 1
|
||||
assert event.data.get("last") == (index == count - 1)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("condition", ["while", "until"])
|
||||
|
@ -1052,8 +1052,8 @@ async def test_repeat_conditional(hass, condition, direct_template):
|
|||
|
||||
assert len(events) == count
|
||||
for index, event in enumerate(events):
|
||||
assert event.data.get("first") == str(index == 0)
|
||||
assert event.data.get("index") == str(index + 1)
|
||||
assert event.data.get("first") == (index == 0)
|
||||
assert event.data.get("index") == index + 1
|
||||
|
||||
|
||||
@pytest.mark.parametrize("condition", ["while", "until"])
|
||||
|
@ -1089,8 +1089,8 @@ async def test_repeat_var_in_condition(hass, condition):
|
|||
@pytest.mark.parametrize(
|
||||
"variables,first_last,inside_x",
|
||||
[
|
||||
(None, {"repeat": "None", "x": "None"}, "None"),
|
||||
(MappingProxyType({"x": 1}), {"repeat": "None", "x": "1"}, "1"),
|
||||
(None, {"repeat": None, "x": None}, None),
|
||||
(MappingProxyType({"x": 1}), {"repeat": None, "x": 1}, 1),
|
||||
],
|
||||
)
|
||||
async def test_repeat_nested(hass, variables, first_last, inside_x):
|
||||
|
@ -1168,14 +1168,14 @@ async def test_repeat_nested(hass, variables, first_last, inside_x):
|
|||
assert events[-1].data == first_last
|
||||
for index, result in enumerate(
|
||||
(
|
||||
("True", "1", "False", inside_x),
|
||||
("True", "1", "False", inside_x),
|
||||
("False", "2", "True", inside_x),
|
||||
("True", "1", "False", inside_x),
|
||||
("False", "2", "True", inside_x),
|
||||
("True", "1", "False", inside_x),
|
||||
("False", "2", "True", inside_x),
|
||||
("False", "2", "True", inside_x),
|
||||
(True, 1, False, inside_x),
|
||||
(True, 1, False, inside_x),
|
||||
(False, 2, True, inside_x),
|
||||
(True, 1, False, inside_x),
|
||||
(False, 2, True, inside_x),
|
||||
(True, 1, False, inside_x),
|
||||
(False, 2, True, inside_x),
|
||||
(False, 2, True, inside_x),
|
||||
),
|
||||
1,
|
||||
):
|
||||
|
@ -1827,8 +1827,8 @@ async def test_set_redefines_variable(hass, caplog):
|
|||
await script_obj.async_run(context=Context())
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert mock_calls[0].data["value"] == "1"
|
||||
assert mock_calls[1].data["value"] == "2"
|
||||
assert mock_calls[0].data["value"] == 1
|
||||
assert mock_calls[1].data["value"] == 2
|
||||
|
||||
|
||||
async def test_validate_action_config(hass):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue