From 0df9006bf7734a8d5d9185f42b7e6e93dacbb6d5 Mon Sep 17 00:00:00 2001 From: mk-81 <63057155+mk-81@users.noreply.github.com> Date: Tue, 14 May 2024 21:02:17 +0200 Subject: [PATCH] Fix Kodi on/off status (#117436) * Fix Kodi Issue 104603 Fixes issue, that Kodi media player is displayed as online even when offline. The issue occurrs when using HTTP(S) only (no web Socket) integration after kodi was found online once. Issue: In async_update the connection exceptions from self._kodi.get_players are not catched and therefore self._players (and the like) are not reset. The call of self._connection.connected returns always true for HTTP(S) connections. Solution: Catch Exceptions from self._kodi.get_players und reset state in case of HTTP(S) only connection. Otherwise keep current behaviour. * Fix Kodi Issue 104603 / code style adjustments as requested --- homeassistant/components/kodi/media_player.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/kodi/media_player.py b/homeassistant/components/kodi/media_player.py index 74140ca873c..27b2d3e0199 100644 --- a/homeassistant/components/kodi/media_player.py +++ b/homeassistant/components/kodi/media_player.py @@ -480,7 +480,13 @@ class KodiEntity(MediaPlayerEntity): self._reset_state() return - self._players = await self._kodi.get_players() + try: + self._players = await self._kodi.get_players() + except (TransportError, ProtocolError): + if not self._connection.can_subscribe: + self._reset_state() + return + raise if self._kodi_is_off: self._reset_state()