mirror of
https://github.com/home-assistant/core.git
synced 2025-07-08 13:57:10 +00:00
Handle Kodi shutdown (#39856)
* Handle Kodi shutdown * Core review comments * Make async_on_quit a coroutine
This commit is contained in:
parent
aaa8083d49
commit
cf6b84790f
@ -2,7 +2,7 @@
|
|||||||
"domain": "kodi",
|
"domain": "kodi",
|
||||||
"name": "Kodi",
|
"name": "Kodi",
|
||||||
"documentation": "https://www.home-assistant.io/integrations/kodi",
|
"documentation": "https://www.home-assistant.io/integrations/kodi",
|
||||||
"requirements": ["pykodi==0.1.2"],
|
"requirements": ["pykodi==0.2.0"],
|
||||||
"codeowners": [
|
"codeowners": [
|
||||||
"@OnFreund"
|
"@OnFreund"
|
||||||
],
|
],
|
||||||
|
@ -5,6 +5,7 @@ import logging
|
|||||||
import re
|
import re
|
||||||
|
|
||||||
import jsonrpc_base
|
import jsonrpc_base
|
||||||
|
from pykodi import CannotConnectError
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.media_player import PLATFORM_SCHEMA, MediaPlayerEntity
|
from homeassistant.components.media_player import PLATFORM_SCHEMA, MediaPlayerEntity
|
||||||
@ -324,11 +325,15 @@ class KodiEntity(MediaPlayerEntity):
|
|||||||
self._app_properties["muted"] = data["muted"]
|
self._app_properties["muted"] = data["muted"]
|
||||||
self.async_write_ha_state()
|
self.async_write_ha_state()
|
||||||
|
|
||||||
@callback
|
async def async_on_quit(self, sender, data):
|
||||||
def async_on_quit(self, sender, data):
|
|
||||||
"""Reset the player state on quit action."""
|
"""Reset the player state on quit action."""
|
||||||
|
await self._clear_connection()
|
||||||
|
|
||||||
|
async def _clear_connection(self, close=True):
|
||||||
self._reset_state()
|
self._reset_state()
|
||||||
self.hass.async_create_task(self._connection.close())
|
self.async_write_ha_state()
|
||||||
|
if close:
|
||||||
|
await self._connection.close()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unique_id(self):
|
def unique_id(self):
|
||||||
@ -386,14 +391,23 @@ class KodiEntity(MediaPlayerEntity):
|
|||||||
try:
|
try:
|
||||||
await self._connection.connect()
|
await self._connection.connect()
|
||||||
self._on_ws_connected()
|
self._on_ws_connected()
|
||||||
except jsonrpc_base.jsonrpc.TransportError:
|
except (jsonrpc_base.jsonrpc.TransportError, CannotConnectError):
|
||||||
_LOGGER.info("Unable to connect to Kodi via websocket")
|
|
||||||
_LOGGER.debug("Unable to connect to Kodi via websocket", exc_info=True)
|
_LOGGER.debug("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)
|
||||||
|
await self._clear_connection()
|
||||||
|
|
||||||
async def _async_connect_websocket_if_disconnected(self, *_):
|
async def _async_connect_websocket_if_disconnected(self, *_):
|
||||||
"""Reconnect the websocket if it fails."""
|
"""Reconnect the websocket if it fails."""
|
||||||
if not self._connection.connected:
|
if not self._connection.connected:
|
||||||
await self._async_ws_connect()
|
await self._async_ws_connect()
|
||||||
|
else:
|
||||||
|
await self._ping()
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def _register_ws_callbacks(self):
|
def _register_ws_callbacks(self):
|
||||||
@ -464,7 +478,7 @@ class KodiEntity(MediaPlayerEntity):
|
|||||||
@property
|
@property
|
||||||
def should_poll(self):
|
def should_poll(self):
|
||||||
"""Return True if entity has to be polled for state."""
|
"""Return True if entity has to be polled for state."""
|
||||||
return (not self._connection.can_subscribe) or (not self._connection.connected)
|
return not self._connection.can_subscribe
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def volume_level(self):
|
def volume_level(self):
|
||||||
|
@ -1431,7 +1431,7 @@ pyitachip2ir==0.0.7
|
|||||||
pykira==0.1.1
|
pykira==0.1.1
|
||||||
|
|
||||||
# homeassistant.components.kodi
|
# homeassistant.components.kodi
|
||||||
pykodi==0.1.2
|
pykodi==0.2.0
|
||||||
|
|
||||||
# homeassistant.components.kwb
|
# homeassistant.components.kwb
|
||||||
pykwb==0.0.8
|
pykwb==0.0.8
|
||||||
|
@ -692,7 +692,7 @@ pyisy==2.0.2
|
|||||||
pykira==0.1.1
|
pykira==0.1.1
|
||||||
|
|
||||||
# homeassistant.components.kodi
|
# homeassistant.components.kodi
|
||||||
pykodi==0.1.2
|
pykodi==0.2.0
|
||||||
|
|
||||||
# homeassistant.components.lastfm
|
# homeassistant.components.lastfm
|
||||||
pylast==3.3.0
|
pylast==3.3.0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user