mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Improve MQTT binary_sensor test (#66688)
This commit is contained in:
parent
bccfaceedb
commit
f89de613d9
@ -887,8 +887,12 @@ async def test_reloadable_late(hass, mqtt_client_mock, caplog, tmp_path):
|
||||
await help_test_reloadable_late(hass, caplog, tmp_path, domain, config)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"payload1, state1, payload2, state2",
|
||||
[("ON", "on", "OFF", "off"), ("OFF", "off", "ON", "on")],
|
||||
)
|
||||
async def test_cleanup_triggers_and_restoring_state(
|
||||
hass, mqtt_mock, caplog, tmp_path, freezer
|
||||
hass, mqtt_mock, caplog, tmp_path, freezer, payload1, state1, payload2, state2
|
||||
):
|
||||
"""Test cleanup old triggers at reloading and restoring the state."""
|
||||
domain = binary_sensor.DOMAIN
|
||||
@ -909,13 +913,13 @@ async def test_cleanup_triggers_and_restoring_state(
|
||||
{binary_sensor.DOMAIN: [config1, config2]},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
async_fire_mqtt_message(hass, "test-topic1", "ON")
|
||||
async_fire_mqtt_message(hass, "test-topic1", payload1)
|
||||
state = hass.states.get("binary_sensor.test1")
|
||||
assert state.state == "on"
|
||||
assert state.state == state1
|
||||
|
||||
async_fire_mqtt_message(hass, "test-topic2", "ON")
|
||||
async_fire_mqtt_message(hass, "test-topic2", payload1)
|
||||
state = hass.states.get("binary_sensor.test2")
|
||||
assert state.state == "on"
|
||||
assert state.state == state1
|
||||
|
||||
freezer.move_to("2022-02-02 12:01:10+01:00")
|
||||
|
||||
@ -931,18 +935,18 @@ async def test_cleanup_triggers_and_restoring_state(
|
||||
assert "State recovered after reload for binary_sensor.test2" not in caplog.text
|
||||
|
||||
state = hass.states.get("binary_sensor.test1")
|
||||
assert state.state == "on"
|
||||
assert state.state == state1
|
||||
|
||||
state = hass.states.get("binary_sensor.test2")
|
||||
assert state.state == STATE_UNAVAILABLE
|
||||
|
||||
async_fire_mqtt_message(hass, "test-topic1", "OFF")
|
||||
async_fire_mqtt_message(hass, "test-topic1", payload2)
|
||||
state = hass.states.get("binary_sensor.test1")
|
||||
assert state.state == "off"
|
||||
assert state.state == state2
|
||||
|
||||
async_fire_mqtt_message(hass, "test-topic2", "OFF")
|
||||
async_fire_mqtt_message(hass, "test-topic2", payload2)
|
||||
state = hass.states.get("binary_sensor.test2")
|
||||
assert state.state == "off"
|
||||
assert state.state == state2
|
||||
|
||||
|
||||
async def test_skip_restoring_state_with_over_due_expire_trigger(
|
||||
|
Loading…
x
Reference in New Issue
Block a user