mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 09:17:10 +00:00
Adjust ConnectionFailure logging in SamsungTV (#146044)
This commit is contained in:
parent
d439bb68eb
commit
d1e0225520
@ -636,14 +636,21 @@ class SamsungTVWSBridge(
|
||||
)
|
||||
self._remote = None
|
||||
except ConnectionFailure as err:
|
||||
LOGGER.warning(
|
||||
(
|
||||
error_details = err.args[0]
|
||||
if "ms.channel.timeOut" in (error_details := repr(err)):
|
||||
# The websocket was connected, but the TV is probably asleep
|
||||
LOGGER.debug(
|
||||
"Channel timeout occurred trying to get remote for %s: %s",
|
||||
self.host,
|
||||
error_details,
|
||||
)
|
||||
else:
|
||||
LOGGER.warning(
|
||||
"Unexpected ConnectionFailure trying to get remote for %s, "
|
||||
"please report this issue: %s"
|
||||
),
|
||||
self.host,
|
||||
repr(err),
|
||||
)
|
||||
"please report this issue: %s",
|
||||
self.host,
|
||||
error_details,
|
||||
)
|
||||
self._remote = None
|
||||
except (WebSocketException, AsyncioTimeoutError, OSError) as err:
|
||||
LOGGER.debug("Failed to get remote for %s: %s", self.host, repr(err))
|
||||
|
@ -409,7 +409,7 @@ async def test_update_ws_connection_failure(
|
||||
patch.object(
|
||||
remote_websocket,
|
||||
"start_listening",
|
||||
side_effect=ConnectionFailure('{"event": "ms.voiceApp.hide"}'),
|
||||
side_effect=ConnectionFailure({"event": "ms.voiceApp.hide"}),
|
||||
),
|
||||
patch.object(remote_websocket, "is_alive", return_value=False),
|
||||
):
|
||||
@ -419,7 +419,7 @@ async def test_update_ws_connection_failure(
|
||||
|
||||
assert (
|
||||
"Unexpected ConnectionFailure trying to get remote for fake_host, please "
|
||||
'report this issue: ConnectionFailure(\'{"event": "ms.voiceApp.hide"}\')'
|
||||
"report this issue: ConnectionFailure({'event': 'ms.voiceApp.hide'})"
|
||||
in caplog.text
|
||||
)
|
||||
|
||||
@ -427,6 +427,37 @@ async def test_update_ws_connection_failure(
|
||||
assert state.state == STATE_OFF
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("rest_api")
|
||||
async def test_update_ws_connection_failure_channel_timeout(
|
||||
hass: HomeAssistant,
|
||||
freezer: FrozenDateTimeFactory,
|
||||
remote_websocket: Mock,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Testing update tv connection failure exception."""
|
||||
await setup_samsungtv_entry(hass, MOCK_CONFIGWS)
|
||||
|
||||
with (
|
||||
patch.object(
|
||||
remote_websocket,
|
||||
"start_listening",
|
||||
side_effect=ConnectionFailure({"event": "ms.channel.timeOut"}),
|
||||
),
|
||||
patch.object(remote_websocket, "is_alive", return_value=False),
|
||||
):
|
||||
freezer.tick(timedelta(minutes=5))
|
||||
async_fire_time_changed(hass)
|
||||
await hass.async_block_till_done(wait_background_tasks=True)
|
||||
|
||||
assert (
|
||||
"Channel timeout occurred trying to get remote for fake_host: "
|
||||
"ConnectionFailure({'event': 'ms.channel.timeOut'})" in caplog.text
|
||||
)
|
||||
|
||||
state = hass.states.get(ENTITY_ID)
|
||||
assert state.state == STATE_OFF
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("rest_api")
|
||||
async def test_update_ws_connection_closed(
|
||||
hass: HomeAssistant, freezer: FrozenDateTimeFactory, remote_websocket: Mock
|
||||
|
Loading…
x
Reference in New Issue
Block a user