Add native Python types support to templates (#41227)
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
This commit is contained in:
1 parent
cbb4324c84
commit
ee914366a8
29 files changed
+349
-282
No files matched your search
@@ -104,7 +104,7 @@ class TestNotifyDemo(unittest.TestCase):
|
||||
self.hass.block_till_done()
|
||||
last_event = self.events[-1]
|
||||
assert last_event.data[notify.ATTR_TITLE] == "temperature"
|
||||
assert last_event.data[notify.ATTR_MESSAGE] == "10"
|
||||
assert last_event.data[notify.ATTR_MESSAGE] == 10
|
||||
|
||||
def test_method_forwards_correct_data(self):
|
||||
"""Test that all data from the service gets forwarded to service."""
|
||||
|
||||
@@ -65,7 +65,7 @@ DEFAULT_CONFIG_CODE = {
|
||||
"name": "test",
|
||||
"state_topic": "alarm/state",
|
||||
"command_topic": "alarm/command",
|
||||
"code": "1234",
|
||||
"code": "0123",
|
||||
"code_arm_required": True,
|
||||
}
|
||||
}
|
||||
@@ -396,7 +396,7 @@ async def test_disarm_publishes_mqtt_with_template(hass, mqtt_mock):
|
||||
When command_template set to output json
|
||||
"""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG_CODE)
|
||||
config[alarm_control_panel.DOMAIN]["code"] = "1234"
|
||||
config[alarm_control_panel.DOMAIN]["code"] = "0123"
|
||||
config[alarm_control_panel.DOMAIN]["command_template"] = (
|
||||
'{"action":"{{ action }}",' '"code":"{{ code }}"}'
|
||||
)
|
||||
@@ -407,9 +407,9 @@ async def test_disarm_publishes_mqtt_with_template(hass, mqtt_mock):
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
await common.async_alarm_disarm(hass, 1234)
|
||||
await common.async_alarm_disarm(hass, "0123")
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
"alarm/command", '{"action":"DISARM","code":"1234"}', 0, False
|
||||
"alarm/command", {"action": "DISARM", "code": "0123"}, 0, False
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -702,9 +702,7 @@ async def test_set_position_templated(hass, mqtt_mock):
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
"set-position-topic", "38", 0, False
|
||||
)
|
||||
mqtt_mock.async_publish.assert_called_once_with("set-position-topic", 38, 0, False)
|
||||
|
||||
|
||||
async def test_set_position_untemplated(hass, mqtt_mock):
|
||||
|
||||
@@ -123,7 +123,7 @@ async def test_service_call_with_template_payload_renders_template(hass, mqtt_mo
|
||||
mqtt.async_publish_template(hass, "test/topic", "{{ 1+1 }}")
|
||||
await hass.async_block_till_done()
|
||||
assert mqtt_mock.async_publish.called
|
||||
assert mqtt_mock.async_publish.call_args[0][1] == "2"
|
||||
assert mqtt_mock.async_publish.call_args[0][1] == 2
|
||||
|
||||
|
||||
async def test_service_call_with_payload_doesnt_render_template(hass, mqtt_mock):
|
||||
|
||||
@@ -837,7 +837,7 @@ async def test_sending_mqtt_color_temp_command_with_template(hass, mqtt_mock):
|
||||
mqtt_mock.async_publish.assert_has_calls(
|
||||
[
|
||||
call("test_light_color_temp/set", "on", 0, False),
|
||||
call("test_light_color_temp/color_temp/set", "10", 0, False),
|
||||
call("test_light_color_temp/color_temp/set", 10, 0, False),
|
||||
],
|
||||
any_order=True,
|
||||
)
|
||||
|
||||
@@ -705,4 +705,4 @@ async def test_script_variables(hass, caplog):
|
||||
await hass.services.async_call("script", "script3", {"break": 0}, blocking=True)
|
||||
|
||||
assert len(mock_calls) == 4
|
||||
assert mock_calls[3].data["value"] == "1"
|
||||
assert mock_calls[3].data["value"] == 1
|
||||
@@ -402,7 +402,7 @@ async def test_intent_special_slots(hass, mqtt_mock):
|
||||
assert len(calls) == 1
|
||||
assert calls[0].domain == "light"
|
||||
assert calls[0].service == "turn_on"
|
||||
assert calls[0].data["confidenceScore"] == "0.85"
|
||||
assert calls[0].data["confidenceScore"] == 0.85
|
||||
assert calls[0].data["site_id"] == "default"
|
||||
|
||||
|
||||
|
||||
@@ -662,7 +662,7 @@ def _verify(
|
||||
"""Verify fan's state, speed and osc."""
|
||||
state = hass.states.get(_TEST_FAN)
|
||||
attributes = state.attributes
|
||||
assert state.state == expected_state
|
||||
assert state.state == str(expected_state)
|
||||
assert attributes.get(ATTR_SPEED) == expected_speed
|
||||
assert attributes.get(ATTR_OSCILLATING) == expected_oscillating
|
||||
assert attributes.get(ATTR_DIRECTION) == expected_direction
|
||||
|
||||
@@ -550,7 +550,7 @@ class TestTemplateLight:
|
||||
)
|
||||
self.hass.block_till_done()
|
||||
assert len(self.calls) == 1
|
||||
assert self.calls[0].data["white_value"] == "124"
|
||||
assert self.calls[0].data["white_value"] == 124
|
||||
|
||||
state = self.hass.states.get("light.test_template_light")
|
||||
assert state is not None
|
||||
@@ -649,7 +649,7 @@ class TestTemplateLight:
|
||||
common.turn_on(self.hass, "light.test_template_light", **{ATTR_BRIGHTNESS: 124})
|
||||
self.hass.block_till_done()
|
||||
assert len(self.calls) == 1
|
||||
assert self.calls[0].data["brightness"] == "124"
|
||||
assert self.calls[0].data["brightness"] == 124
|
||||
|
||||
state = self.hass.states.get("light.test_template_light")
|
||||
_LOGGER.info(str(state.attributes))
|
||||
@@ -802,7 +802,7 @@ class TestTemplateLight:
|
||||
common.turn_on(self.hass, "light.test_template_light", **{ATTR_COLOR_TEMP: 345})
|
||||
self.hass.block_till_done()
|
||||
assert len(self.calls) == 1
|
||||
assert self.calls[0].data["color_temp"] == "345"
|
||||
assert self.calls[0].data["color_temp"] == 345
|
||||
|
||||
state = self.hass.states.get("light.test_template_light")
|
||||
_LOGGER.info(str(state.attributes))
|
||||
@@ -1008,18 +1008,18 @@ class TestTemplateLight:
|
||||
)
|
||||
self.hass.block_till_done()
|
||||
assert len(self.calls) == 2
|
||||
assert self.calls[0].data["h"] == "40"
|
||||
assert self.calls[0].data["s"] == "50"
|
||||
assert self.calls[1].data["h"] == "40"
|
||||
assert self.calls[1].data["s"] == "50"
|
||||
assert self.calls[0].data["h"] == 40
|
||||
assert self.calls[0].data["s"] == 50
|
||||
assert self.calls[1].data["h"] == 40
|
||||
assert self.calls[1].data["s"] == 50
|
||||
|
||||
state = self.hass.states.get("light.test_template_light")
|
||||
_LOGGER.info(str(state.attributes))
|
||||
assert state is not None
|
||||
assert self.calls[0].data["h"] == "40"
|
||||
assert self.calls[0].data["s"] == "50"
|
||||
assert self.calls[1].data["h"] == "40"
|
||||
assert self.calls[1].data["s"] == "50"
|
||||
assert self.calls[0].data["h"] == 40
|
||||
assert self.calls[0].data["s"] == 50
|
||||
assert self.calls[1].data["h"] == 40
|
||||
assert self.calls[1].data["s"] == 50
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"expected_hs,template",
|
||||
|
||||
@@ -867,7 +867,7 @@ async def test_self_referencing_entity_picture_loop(hass, caplog):
|
||||
|
||||
state = hass.states.get("sensor.test")
|
||||
assert int(state.state) == 1
|
||||
assert state.attributes[ATTR_ENTITY_PICTURE] == "2"
|
||||
assert state.attributes[ATTR_ENTITY_PICTURE] == 2
|
||||
|
||||
await hass.async_block_till_done()
|
||||
assert int(state.state) == 1
|
||||
|
||||
@@ -5,7 +5,7 @@ from homeassistant import config_entries, data_entry_flow, setup
|
||||
from homeassistant.components.vilfo.const import DOMAIN
|
||||
from homeassistant.const import CONF_ACCESS_TOKEN, CONF_HOST, CONF_ID, CONF_MAC
|
||||
|
||||
from tests.async_mock import patch
|
||||
from tests.async_mock import Mock, patch
|
||||
|
||||
|
||||
async def test_form(hass):
|
||||
@@ -29,6 +29,7 @@ async def test_form(hass):
|
||||
result["flow_id"],
|
||||
{CONF_HOST: "testadmin.vilfo.com", CONF_ACCESS_TOKEN: "test-token"},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result2["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
||||
assert result2["title"] == "testadmin.vilfo.com"
|
||||
@@ -142,7 +143,10 @@ async def test_form_unexpected_exception(hass):
|
||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||
)
|
||||
|
||||
with patch("vilfo.Client.ping", side_effect=Exception):
|
||||
with patch(
|
||||
"homeassistant.components.vilfo.config_flow.VilfoClient",
|
||||
) as mock_client:
|
||||
mock_client.return_value.ping = Mock(side_effect=Exception)
|
||||
result2 = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
{"host": "testadmin.vilfo.com", "access_token": "test-token"},
|
||||
|
||||
Reference in new issue
Block a user