Use mock_restore_cache in mqtt tests (#77297)

This commit is contained in:
Erik Montnemery 2022-08-25 09:27:38 +02:00 committed by GitHub
parent cef6ffb552
commit c55505b47b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 152 additions and 170 deletions

View file

@ -43,6 +43,7 @@ from tests.common import (
async_fire_time_changed,
mock_device_registry,
mock_registry,
mock_restore_cache,
)
from tests.testing_config.custom_components.test.sensor import DEVICE_CLASSES
@ -284,27 +285,24 @@ async def test_command_template_variables(hass, mqtt_mock_entry_with_yaml_config
"""Test the rendering of entity variables."""
topic = "test/select"
fake_state = ha.State("select.test", "milk")
fake_state = ha.State("select.test_select", "milk")
mock_restore_cache(hass, (fake_state,))
with patch(
"homeassistant.helpers.restore_state.RestoreEntity.async_get_last_state",
return_value=fake_state,
):
assert await async_setup_component(
hass,
"select",
{
"select": {
"platform": "mqtt",
"command_topic": topic,
"name": "Test Select",
"options": ["milk", "beer"],
"command_template": '{"option": "{{ value }}", "entity_id": "{{ entity_id }}", "name": "{{ name }}", "this_object_state": "{{ this.state }}"}',
}
},
)
await hass.async_block_till_done()
mqtt_mock = await mqtt_mock_entry_with_yaml_config()
assert await async_setup_component(
hass,
"select",
{
"select": {
"platform": "mqtt",
"command_topic": topic,
"name": "Test Select",
"options": ["milk", "beer"],
"command_template": '{"option": "{{ value }}", "entity_id": "{{ entity_id }}", "name": "{{ name }}", "this_object_state": "{{ this.state }}"}',
}
},
)
await hass.async_block_till_done()
mqtt_mock = await mqtt_mock_entry_with_yaml_config()
state = hass.states.get("select.test_select")
assert state.state == "milk"