From 8fc8778995522120238e08339041d0fc94b2ec91 Mon Sep 17 00:00:00 2001 From: cvwillegen Date: Tue, 29 Mar 2022 11:09:59 +0200 Subject: [PATCH] Improve log when connection to kodi media player cannot be created (#68458) * Make clearer in log files that connection to media player cannot be created. * Only give connection error once. When connection is lost, only give an error message once. When connection is restored and lost again, give error message again. --- homeassistant/components/kodi/media_player.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/kodi/media_player.py b/homeassistant/components/kodi/media_player.py index e1dae879bf8..58fbb930cc3 100644 --- a/homeassistant/components/kodi/media_player.py +++ b/homeassistant/components/kodi/media_player.py @@ -306,6 +306,7 @@ class KodiEntity(MediaPlayerEntity): self._app_properties = {} self._media_position_updated_at = None self._media_position = None + self._connect_error = False def _reset_state(self, players=None): self._players = players @@ -314,6 +315,7 @@ class KodiEntity(MediaPlayerEntity): self._app_properties = {} self._media_position_updated_at = None self._media_position = None + self._connect_error = False @property def _kodi_is_off(self): @@ -420,6 +422,7 @@ class KodiEntity(MediaPlayerEntity): async def _on_ws_connected(self): """Call after ws is connected.""" + self._connect_error = False self._register_ws_callbacks() version = (await self._kodi.get_application_properties(["version"]))["version"] @@ -436,14 +439,18 @@ class KodiEntity(MediaPlayerEntity): await self._connection.connect() await self._on_ws_connected() except (jsonrpc_base.jsonrpc.TransportError, CannotConnectError): - _LOGGER.debug("Unable to connect to Kodi via websocket", exc_info=True) + if not self._connect_error: + self._connect_error = True + _LOGGER.error("Unable to connect to Kodi via websocket", exc_info=True) await self._clear_connection(False) async def _ping(self): try: await self._kodi.ping() except (jsonrpc_base.jsonrpc.TransportError, CannotConnectError): - _LOGGER.debug("Unable to ping Kodi via websocket", exc_info=True) + if not self._connect_error: + self._connect_error = True + _LOGGER.error("Unable to ping Kodi via websocket", exc_info=True) await self._clear_connection() async def _async_connect_websocket_if_disconnected(self, *_):