Skip to content

Commit

Permalink
Adjust websocket bridge logging in SamsungTV (#67809)
Browse files Browse the repository at this point in the history
Co-authored-by: epenet <epenet@users.noreply.github.com>
  • Loading branch information
epenet and epenet committed Mar 7, 2022
1 parent d1ef92c commit c70bed8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
24 changes: 15 additions & 9 deletions homeassistant/components/samsungtv/bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ async def _async_get_remote_under_lock(self) -> SamsungTVWSAsyncRemote | None:
"""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,
Expand All @@ -449,20 +449,24 @@ async def _async_get_remote_under_lock(self) -> SamsungTVWSAsyncRemote | None:
# 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,
)
Expand All @@ -477,5 +481,7 @@ async def async_close_remote(self) -> None:
# 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__()
)
2 changes: 1 addition & 1 deletion tests/components/samsungtv/test_media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit c70bed8

Please sign in to comment.