Fix race condition in samsungtv turn off (#51716)

- The state would flip flop if the update happened before the TV had fully shutdown
This commit is contained in:
J. Nick Koston
2021-06-10 07:24:30 -10:00
committed by GitHub
parent ab490bc769
commit 4722fdf465
2 changed files with 27 additions and 2 deletions

View File

@@ -419,6 +419,18 @@ async def test_state_without_turnon(hass, remote):
assert await hass.services.async_call(
DOMAIN, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: ENTITY_ID_NOTURNON}, True
)
state = hass.states.get(ENTITY_ID_NOTURNON)
# Should be STATE_UNAVAILABLE after the timer expires
assert state.state == STATE_OFF
next_update = dt_util.utcnow() + timedelta(seconds=20)
with patch(
"homeassistant.components.samsungtv.bridge.Remote",
side_effect=OSError,
), patch("homeassistant.util.dt.utcnow", return_value=next_update):
async_fire_time_changed(hass, next_update)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_ID_NOTURNON)
# Should be STATE_UNAVAILABLE since there is no way to turn it back on
assert state.state == STATE_UNAVAILABLE