mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 04:50:05 +00:00
Use mock_restore_cache in mqtt tests (#77297)
This commit is contained in:
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user