10000 Adjust ConnectionFailure logging in SamsungTV by epenet · Pull Request #146044 · home-assistant/core · GitHub
[go: up one dir, main page]

Skip to content

Adjust ConnectionFailure logging in SamsungTV #146044

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Adjust ConnectionFailure logging in SamsungTV
  • Loading branch information
epenet committed Jun 2, 2025
commit 7c506e23304049434d8f28f0b0bb7e110af96ecc
21 changes: 14 additions & 7 deletions homeassistant/components/samsungtv/bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -636,14 +636,21 @@ async def _async_get_remote_under_lock(self) -> SamsungTVWSAsyncRemote | None:
)
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 repor 10000 t 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))
Expand Down
35 changes: 33 additions & 2 deletions tests/components/samsungtv/test_media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
):
Expand All @@ -419,14 +419,45 @@ 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
)

state = hass.states.get(ENTITY_ID)
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
Expand Down
0