Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Kodi keypress event #93321

Merged
merged 6 commits into from
May 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 19 additions & 0 deletions homeassistant/components/kodi/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
from homeassistant.const import (
ATTR_ENTITY_ID,
CONF_DEVICE_ID,
CONF_HOST,
CONF_NAME,
CONF_PASSWORD,
CONF_PORT,
CONF_PROXY_SSL,
CONF_SSL,
CONF_TIMEOUT,
CONF_TYPE,
CONF_USERNAME,
EVENT_HOMEASSISTANT_STARTED,
)
Expand Down Expand Up @@ -279,6 +281,7 @@ def __init__(self, connection, kodi, name, uid):
self._connection = connection
self._kodi = kodi
self._unique_id = uid
self._device_id = None
self._players = None
self._properties = {}
self._item = {}
Expand Down Expand Up @@ -336,6 +339,20 @@ def async_on_volume_changed(self, sender, data):
self._app_properties["muted"] = data["muted"]
self.async_write_ha_state()

@callback
def async_on_key_press(self, sender, data):
"""Handle a incoming key press notification."""
self.hass.bus.async_fire(
f"{DOMAIN}_keypress",
{
CONF_TYPE: "keypress",
CONF_DEVICE_ID: self._device_id,
ATTR_ENTITY_ID: self.entity_id,
"sender": sender,
"data": data,
},
)

async def async_on_quit(self, sender, data):
"""Reset the player state on quit action."""
await self._clear_connection()
Expand Down Expand Up @@ -410,6 +427,7 @@ async def _on_ws_connected(self):
dev_reg = dr.async_get(self.hass)
device = dev_reg.async_get_device({(DOMAIN, self.unique_id)})
dev_reg.async_update_device(device.id, sw_version=sw_version)
self._device_id = device.id

self.async_schedule_update_ha_state(True)

Expand Down Expand Up @@ -457,6 +475,7 @@ def _register_ws_callbacks(self):
self._connection.server.Application.OnVolumeChanged = (
self.async_on_volume_changed
)
self._connection.server.Other.OnKeyPress = self.async_on_key_press
self._connection.server.System.OnQuit = self.async_on_quit
self._connection.server.System.OnRestart = self.async_on_quit
self._connection.server.System.OnSleep = self.async_on_quit
Expand Down