Use new samsungtv exception to detect when reauth is needed (#68762)

This commit is contained in:
J. Nick Koston
2022-03-27 12:12:32 -10:00
committed by GitHub
parent 42a5e2d4fe
commit b5496441ae
2 changed files with 28 additions and 5 deletions

View File

@@ -12,7 +12,7 @@ from samsungtvws.encrypted.remote import (
SamsungTVEncryptedCommand,
SamsungTVEncryptedWSAsyncRemote,
)
from samsungtvws.exceptions import ConnectionFailure, HttpApiError
from samsungtvws.exceptions import ConnectionFailure, HttpApiError, UnauthorizedError
from samsungtvws.remote import ChannelEmitCommand, SendRemoteKey
from websockets.exceptions import ConnectionClosedError, WebSocketException
@@ -478,6 +478,24 @@ async def test_update_ws_connection_closed(
async_fire_time_changed(hass, next_update)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_ID)
assert state.state == STATE_OFF
async def test_update_ws_unauthorized_error(
hass: HomeAssistant, mock_now: datetime, remotews: Mock
) -> None:
"""Testing update tv unauthorized failure exception."""
await setup_samsungtv(hass, MOCK_CONFIGWS)
with patch.object(
remotews, "start_listening", side_effect=UnauthorizedError
), patch.object(remotews, "is_alive", return_value=False):
next_update = mock_now + timedelta(minutes=5)
with patch("homeassistant.util.dt.utcnow", return_value=next_update):
async_fire_time_changed(hass, next_update)
await hass.async_block_till_done()
assert [
flow
for flow in hass.config_entries.flow.async_progress()