mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Use new samsungtv exception to detect when reauth is needed (#68762)
This commit is contained in:
parent
42a5e2d4fe
commit
b5496441ae
@ -534,16 +534,21 @@ class SamsungTVWSBridge(SamsungTVBridge):
|
|||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
await self._remote.start_listening(self._remote_event)
|
await self._remote.start_listening(self._remote_event)
|
||||||
except ConnectionClosedError as err:
|
except UnauthorizedError 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
|
|
||||||
LOGGER.info(
|
LOGGER.info(
|
||||||
"Failed to get remote for %s, re-authentication required: %s",
|
"Failed to get remote for %s, re-authentication required: %s",
|
||||||
self.host,
|
self.host,
|
||||||
err.__repr__(),
|
err.__repr__(),
|
||||||
)
|
)
|
||||||
self._notify_reauth_callback()
|
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:
|
except ConnectionFailure as err:
|
||||||
LOGGER.warning(
|
LOGGER.warning(
|
||||||
"Unexpected ConnectionFailure trying to get remote for %s, "
|
"Unexpected ConnectionFailure trying to get remote for %s, "
|
||||||
|
@ -12,7 +12,7 @@ from samsungtvws.encrypted.remote import (
|
|||||||
SamsungTVEncryptedCommand,
|
SamsungTVEncryptedCommand,
|
||||||
SamsungTVEncryptedWSAsyncRemote,
|
SamsungTVEncryptedWSAsyncRemote,
|
||||||
)
|
)
|
||||||
from samsungtvws.exceptions import ConnectionFailure, HttpApiError
|
from samsungtvws.exceptions import ConnectionFailure, HttpApiError, UnauthorizedError
|
||||||
from samsungtvws.remote import ChannelEmitCommand, SendRemoteKey
|
from samsungtvws.remote import ChannelEmitCommand, SendRemoteKey
|
||||||
from websockets.exceptions import ConnectionClosedError, WebSocketException
|
from websockets.exceptions import ConnectionClosedError, WebSocketException
|
||||||
|
|
||||||
@ -478,6 +478,24 @@ async def test_update_ws_connection_closed(
|
|||||||
async_fire_time_changed(hass, next_update)
|
async_fire_time_changed(hass, next_update)
|
||||||
await hass.async_block_till_done()
|
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 [
|
assert [
|
||||||
flow
|
flow
|
||||||
for flow in hass.config_entries.flow.async_progress()
|
for flow in hass.config_entries.flow.async_progress()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user