Use new samsungtv exception to detect when reauth is needed (#68762)
parent
42a5e2d4fe
commit
b5496441ae
|
@ -534,16 +534,21 @@ class SamsungTVWSBridge(SamsungTVBridge):
|
|||
)
|
||||
try:
|
||||
await self._remote.start_listening(self._remote_event)
|
||||
except ConnectionClosedError as err:
|
||||
# This is only happening when the auth was switched to DENY
|
||||
# A removed auth will lead to socket timeout because waiting
|
||||
# for auth popup is just an open socket
|
||||
except UnauthorizedError as err:
|
||||
LOGGER.info(
|
||||
"Failed to get remote for %s, re-authentication required: %s",
|
||||
self.host,
|
||||
err.__repr__(),
|
||||
)
|
||||
self._notify_reauth_callback()
|
||||
self._remote = None
|
||||
except ConnectionClosedError as err:
|
||||
LOGGER.info(
|
||||
"Failed to get remote for %s: %s",
|
||||
self.host,
|
||||
err.__repr__(),
|
||||
)
|
||||
self._remote = None
|
||||
except ConnectionFailure as err:
|
||||
LOGGER.warning(
|
||||
"Unexpected ConnectionFailure trying to get remote for %s, "
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue