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.
pull/68840/head
cvwillegen 2022-03-29 11:09:59 +02:00 committed by GitHub
parent 112d232c2e
commit 8fc8778995
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 2 deletions

View File

@ -306,6 +306,7 @@ class KodiEntity(MediaPlayerEntity):
self._app_properties = {} self._app_properties = {}
self._media_position_updated_at = None self._media_position_updated_at = None
self._media_position = None self._media_position = None
self._connect_error = False
def _reset_state(self, players=None): def _reset_state(self, players=None):
self._players = players self._players = players
@ -314,6 +315,7 @@ class KodiEntity(MediaPlayerEntity):
self._app_properties = {} self._app_properties = {}
self._media_position_updated_at = None self._media_position_updated_at = None
self._media_position = None self._media_position = None
self._connect_error = False
@property @property
def _kodi_is_off(self): def _kodi_is_off(self):
@ -420,6 +422,7 @@ class KodiEntity(MediaPlayerEntity):
async def _on_ws_connected(self): async def _on_ws_connected(self):
"""Call after ws is connected.""" """Call after ws is connected."""
self._connect_error = False
self._register_ws_callbacks() self._register_ws_callbacks()
version = (await self._kodi.get_application_properties(["version"]))["version"] version = (await self._kodi.get_application_properties(["version"]))["version"]
@ -436,14 +439,18 @@ class KodiEntity(MediaPlayerEntity):
await self._connection.connect() await self._connection.connect()
await self._on_ws_connected() await self._on_ws_connected()
except (jsonrpc_base.jsonrpc.TransportError, CannotConnectError): 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) await self._clear_connection(False)
async def _ping(self): async def _ping(self):
try: try:
await self._kodi.ping() await self._kodi.ping()
except (jsonrpc_base.jsonrpc.TransportError, CannotConnectError): 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() await self._clear_connection()
async def _async_connect_websocket_if_disconnected(self, *_): async def _async_connect_websocket_if_disconnected(self, *_):