Improve MQTT binary_sensor test (#66688)

This commit is contained in:
Erik Montnemery 2022-02-17 00:06:42 +01:00 committed by GitHub
parent bccfaceedb
commit f89de613d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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) 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( 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.""" """Test cleanup old triggers at reloading and restoring the state."""
domain = binary_sensor.DOMAIN domain = binary_sensor.DOMAIN
@ -909,13 +913,13 @@ async def test_cleanup_triggers_and_restoring_state(
{binary_sensor.DOMAIN: [config1, config2]}, {binary_sensor.DOMAIN: [config1, config2]},
) )
await hass.async_block_till_done() 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") 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") 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") 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 assert "State recovered after reload for binary_sensor.test2" not in caplog.text
state = hass.states.get("binary_sensor.test1") state = hass.states.get("binary_sensor.test1")
assert state.state == "on" assert state.state == state1
state = hass.states.get("binary_sensor.test2") state = hass.states.get("binary_sensor.test2")
assert state.state == STATE_UNAVAILABLE 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") 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") 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( async def test_skip_restoring_state_with_over_due_expire_trigger(