8000 Adjust ConnectionFailure logging in SamsungTV (#146044) · home-assistant/core@d1e0225 · GitHub
[go: up one dir, main page]

Skip to content

Commit d1e0225

Browse files
authored
Adjust ConnectionFailure logging in SamsungTV (#146044)
1 parent d439bb6 commit d1e0225

File tree

2 files changed

+47
-9
lines changed

2 files changed

+47
-9
lines changed

homeassistant/components/samsungtv/bridge.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -636,14 +636,21 @@ async def _async_get_remote_under_lock(self) -> SamsungTVWSAsyncRemote | None:
636636
)
637637
self._remote = None
638638
except ConnectionFailure as err:
639-
LOGGER.warning(
640-
(
639+
error_details = err.args[0]
640+
if "ms.channel.timeOut" in (error_details := repr(err)):
641+
# The websocket was connected, but the TV is probably asleep
642+
LOGGER.debug(
643+
"Channel timeout occurred trying to get remote for %s: %s",
644+
self.host,
645+
error_details,
646+
)
647+
else:
648+
LOGGER.warning(
641649
"Unexpected ConnectionFailure trying to get remote for %s, "
642-
"please report this issue: %s"
643-
),
644-
self.host,
645-
repr(err),
646-
)
650+
"please report this issue: %s",
651+
self.host,
652+
error_details,
653+
)
647654
self._remote = None
648655
except (WebSocketException, AsyncioTimeoutError, OSError) as err:
649656
LOGGER.debug("Failed to get remote for %s: %s", self.host, repr(err))

tests/components/samsungtv/test_media_player.py

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ async def test_update_ws_connection_failure(
409409
patch.object(
410410
remote_websocket,
411411
"start_listening",
412-
side_effect=ConnectionFailure('{"event": "ms.voiceApp.hide"}'),
412+
side_effect=ConnectionFailure({"event": "ms.voiceApp.hide"}),
413413
),
414414
patch.object(remote_websocket, "is_alive", return_value=False),
415415
):
@@ -419,14 +419,45 @@ async def test_update_ws_connection_failure(
419419

420420
assert (
421421
"Unexpected ConnectionFailure trying to get remote for fake_host, please "
422-
'report this issue: ConnectionFailure(\'{"event": "ms.voiceApp.hide"}\')'
422+
"report this issue: ConnectionFailure({'event': 'ms.voiceApp.hide'})"
423423
in caplog.text
424424
)
425425

426426
state = hass.states.get(ENTITY_ID)
427427
assert state.state == STATE_OFF
428428

429429

430+
@pytest.mark.usefixtures("rest_api")
431+
async def test_update_ws_connection_failure_channel_timeout(
432+
hass: HomeAssistant,
433+
freezer: FrozenDateTimeFactory,
434+
remote_websocket: Mock,
435+
caplog: pytest.LogCaptureFixture,
436+
) -> None:
437+
"""Testing update tv connection failure exception."""
438+
await setup_samsungtv_entry(hass, MOCK_CONFIGWS)
439+
440+
with (
441+
patch.object(
442+
remote_websocket,
443+
"start_listening",
444+
side_effect=ConnectionFailure({"event": "ms.channel.timeOut"}),
445+
),
446+
patch.object(remote_websocket, "is_alive", return_value=False),
447+
):
448+
freezer.tick(timedelta(minutes=5))
449+
async_fire_time_changed(hass)
450+
await hass.async_block_till_done(wait_background_tasks=True)
451+
452+
assert (
453+
"Channel timeout occurred trying to get remote for fake_host: "
454+
"ConnectionFailure({'event': 'ms.channel.timeOut'})" in caplog.text
455+
)
456+
457+
state = hass.states.get(ENTITY_ID)
458+
assert state.state == STATE_OFF
459+
460+
430461
@pytest.mark.usefixtures("rest_api")
431462
async def test_update_ws_connection_closed(
432463
hass: HomeAssistant, freezer: FrozenDateTimeFactory, remote_websocket: Mock

0 commit comments

Comments
 (0)
0