From c70bed86ff374b59dca22eec7094a61ec56bfbb9 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Mon, 7 Mar 2022 23:31:57 +0100 Subject: [PATCH] Adjust websocket bridge logging in SamsungTV (#67809) Co-authored-by: epenet <epenet@users.noreply.github.com> --- homeassistant/components/samsungtv/bridge.py | 24 ++++++++++++------- .../components/samsungtv/test_media_player.py | 2 +- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/homeassistant/components/samsungtv/bridge.py b/homeassistant/components/samsungtv/bridge.py index fc699909e75..a63ca0f3355 100644 --- a/homeassistant/components/samsungtv/bridge.py +++ b/homeassistant/components/samsungtv/bridge.py @@ -435,7 +435,7 @@ class SamsungTVWSBridge(SamsungTVBridge): """Create or return a remote control instance.""" if self._remote is None or not self._remote.is_alive(): # We need to create a new instance to reconnect. - LOGGER.debug("Create SamsungTVWSBridge for %s (%s)", CONF_NAME, self.host) + LOGGER.debug("Create SamsungTVWSBridge for %s", self.host) assert self.port self._remote = SamsungTVWSAsyncRemote( host=self.host, @@ -449,20 +449,24 @@ class SamsungTVWSBridge(SamsungTVBridge): # 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 ConnectionFailure as err: - LOGGER.debug("ConnectionFailure %s", err.__repr__()) + LOGGER.info( + "Failed to get remote for %s, re-authentication required: %s", + self.host, + err.__repr__(), + ) self._notify_reauth_callback() except (WebSocketException, AsyncioTimeoutError, OSError) as err: - LOGGER.debug("WebSocketException, OSError %s", err.__repr__()) - self._remote = None - else: LOGGER.debug( - "Created SamsungTVWSBridge for %s (%s)", CONF_NAME, self.host + "Failed to get remote for %s: %s", self.host, err.__repr__() ) + self._remote = None + else: + LOGGER.debug("Created SamsungTVWSBridge for %s", self.host) if self._device_info is None: # Initialise device info on first connect await self.async_device_info() if self.token != self._remote.token: - LOGGER.debug( + LOGGER.info( "SamsungTVWSBridge has provided a new token %s", self._remote.token, ) @@ -477,5 +481,7 @@ class SamsungTVWSBridge(SamsungTVBridge): # Close the current remote connection await self._remote.close() self._remote = None - except OSError: - LOGGER.debug("Could not establish connection") + except OSError as err: + LOGGER.debug( + "Error closing connection to %s: %s", self.host, err.__repr__() + ) diff --git a/tests/components/samsungtv/test_media_player.py b/tests/components/samsungtv/test_media_player.py index 913e11e237c..d07ec9404d6 100644 --- a/tests/components/samsungtv/test_media_player.py +++ b/tests/components/samsungtv/test_media_player.py @@ -695,7 +695,7 @@ async def test_turn_off_ws_os_error( assert await hass.services.async_call( DOMAIN, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: ENTITY_ID}, True ) - assert "Could not establish connection" in caplog.text + assert "Error closing connection" in caplog.text async def test_volume_up(hass: HomeAssistant, remote: Mock) -> None: -- GitLab