Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
albaintor committed Apr 24, 2024
1 parent 8197b17 commit 3ac3f6d
Show file tree
Hide file tree
Showing 2 changed files with 286 additions and 42 deletions.
284 changes: 263 additions & 21 deletions intg-kodi/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@

# Taken from https://kodi.wiki/view/JSON-RPC_API/v10#Input.Action
KODI_SIMPLE_COMMANDS = {
"MENU_VIDEO": "showvideomenu",
"MENU_VIDEO": "showvideomenu", # TODO : showvideomenu not working ?
"MODE_FULLSCREEN": "togglefullscreen",
"MODE_ZOOM_IN": "zoomin",
"MODE_ZOOM_OUT": "zoomout",
Expand Down Expand Up @@ -126,28 +126,38 @@ class BUTTON_KEYMAP(TypedDict):
}

KODI_REMOTE_BUTTONS_MAPPING: [DeviceButtonMapping] = [
{"button": Buttons.BACK, "short_press": {"cmd_id": Commands.BACK}},
{"button": Buttons.HOME, "short_press": {"cmd_id": Commands.HOME}},
{"button": Buttons.CHANNEL_DOWN, "short_press": {"cmd_id": Commands.CHANNEL_DOWN}},
{"button": Buttons.CHANNEL_UP, "short_press": {"cmd_id": Commands.CHANNEL_UP}},
{"button": Buttons.DPAD_UP, "short_press": {"cmd_id": Commands.CURSOR_UP}},
{"button": Buttons.DPAD_DOWN, "short_press": {"cmd_id": Commands.CURSOR_DOWN}},
{"button": Buttons.DPAD_LEFT, "short_press": {"cmd_id": Commands.CURSOR_LEFT}},
{"button": Buttons.DPAD_RIGHT, "short_press": {"cmd_id": Commands.CURSOR_RIGHT}},
{"button": Buttons.DPAD_MIDDLE, "short_press": {"cmd_id": Commands.CURSOR_ENTER}},
{"button": Buttons.PLAY, "short_press": {"cmd_id": Commands.PLAY_PAUSE}},
{"button": Buttons.PREV, "short_press": {"cmd_id": Commands.PREVIOUS}},
{"button": Buttons.NEXT, "short_press": {"cmd_id": Commands.NEXT}},
{"button": Buttons.VOLUME_UP, "short_press": {"cmd_id": Commands.VOLUME_UP}},
{"button": Buttons.VOLUME_DOWN, "short_press": {"cmd_id": Commands.VOLUME_DOWN}},
{"button": Buttons.MUTE, "short_press": {"cmd_id": Commands.MUTE_TOGGLE}},
{"button": Buttons.BACK, "short_press": {"cmd_id": Commands.BACK}},
{"button": Buttons.HOME, "short_press": {"cmd_id": Commands.HOME}},
{"button": Buttons.CHANNEL_DOWN, "short_press": {"cmd_id": Commands.CHANNEL_DOWN}},
{"button": Buttons.CHANNEL_UP, "short_press": {"cmd_id": Commands.CHANNEL_UP}},
{"button": Buttons.DPAD_UP, "short_press": {"cmd_id": Commands.CURSOR_UP}},
{"button": Buttons.DPAD_DOWN, "short_press": {"cmd_id": Commands.CURSOR_DOWN}},
{"button": Buttons.DPAD_LEFT, "short_press": {"cmd_id": Commands.CURSOR_LEFT}},
{"button": Buttons.DPAD_RIGHT, "short_press": {"cmd_id": Commands.CURSOR_RIGHT}},
{"button": Buttons.DPAD_MIDDLE, "short_press": {"cmd_id": Commands.CURSOR_ENTER}},
{"button": Buttons.PLAY, "short_press": {"cmd_id": Commands.PLAY_PAUSE}},
{"button": Buttons.PREV, "short_press": {"cmd_id": Commands.PREVIOUS}},
{"button": Buttons.NEXT, "short_press": {"cmd_id": Commands.NEXT}},
{"button": Buttons.VOLUME_UP, "short_press": {"cmd_id": Commands.VOLUME_UP}},
{"button": Buttons.VOLUME_DOWN, "short_press": {"cmd_id": Commands.VOLUME_DOWN}},
{"button": Buttons.MUTE, "short_press": {"cmd_id": Commands.MUTE_TOGGLE}},
]

# All defined commands for remote entity
#TODO rename simple commands to be compliant to expected names in R2
KODI_REMOTE_SIMPLE_COMMANDS = [
*list(KODI_SIMPLE_COMMANDS.keys()),
*list(KODI_ACTIONS_KEYMAP.keys()),
*list(KODI_BUTTONS_KEYMAP.keys())
*list(KODI_BUTTONS_KEYMAP.keys()),
Commands.CONTEXT_MENU,
Commands.VOLUME_UP,
Commands.VOLUME_DOWN,
Commands.MUTE_TOGGLE,
Commands.MUTE,
Commands.UNMUTE,
Commands.PLAY_PAUSE,
Commands.STOP,
Commands.HOME
]

KODI_REMOTE_UI_PAGES: [UiPage] = [
Expand All @@ -156,6 +166,22 @@ class BUTTON_KEYMAP(TypedDict):
"name": "Kodi commands",
"grid": {"width": 4, "height": 6},
"items": [
{
"command": {
"cmd_id": "remote.send",
"params": {"command": Commands.INFO, "repeat": 1}
},
"icon": "uc:info",
"location": {
"x": 0,
"y": 0
},
"size": {
"height": 1,
"width": 1
},
"type": "icon"
},
{
"command": {
"cmd_id": "remote.send",
Expand All @@ -173,7 +199,7 @@ class BUTTON_KEYMAP(TypedDict):
"type": "icon"
},
{
"command": {
"command": {
"cmd_id": "remote.send",
"params": {"command": Commands.SUBTITLE, "repeat": 1}
},
Expand All @@ -190,8 +216,67 @@ class BUTTON_KEYMAP(TypedDict):
},
{
"command": {
"cmd_id": "remote.send",
"params": {"command": Commands.CONTEXT_MENU, "repeat": 1}
"cmd_id": "MODE_SHOW_SUBTITLES"
},
"text": "Toggle subtitles",
"location": {
"x": 3,
"y": 0
},
"size": {
"height": 1,
"width": 1
},
"type": "text"
},
{
"command": {
"cmd_id": "MODE_FULLSCREEN"
},
"text": "Full screen",
"location": {
"x": 0,
"y": 1
},
"size": {
"height": 1,
"width": 1
},
"type": "text"
},
{
"command": {
"cmd_id": "MODE_ZOOM_IN"
},
"text": "Zoom in",
"location": {
"x": 1,
"y": 1
},
"size": {
"height": 1,
"width": 1
},
"type": "text"
},
{
"command": {
"cmd_id": "MODE_ZOOM_OUT"
},
"text": "Zoom out",
"location": {
"x": 2,
"y": 1
},
"size": {
"height": 1,
"width": 1
},
"type": "text"
},
{
"command": {
"cmd_id": Commands.CONTEXT_MENU
},
"icon": "uc:menu",
"location": {
Expand All @@ -205,5 +290,162 @@ class BUTTON_KEYMAP(TypedDict):
"type": "icon"
},
]
},
{
"page_id": "Kodi numbers",
"name": "Kodi numbers",
"grid": { "height": 4, "width": 3 },
"items": [{
"command": {
"cmd_id": "remote.send",
"params": {"command": Commands.DIGIT_1, "repeat": 1}
},
"location": {
"x": 0,
"y": 0
},
"size": {
"height": 1,
"width": 1
},
"text": "1",
"type": "text"
}, {
"command": {
"cmd_id": "remote.send",
"params": {"command": Commands.DIGIT_2, "repeat": 1}
},
"location": {
"x": 1,
"y": 0
},
"size": {
"height": 1,
"width": 1
},
"text": "2",
"type": "text"
}, {
"command": {
"cmd_id": "remote.send",
"params": {"command": Commands.DIGIT_3, "repeat": 1}
},
"location": {
"x": 2,
"y": 0
},
"size": {
"height": 1,
"width": 1
},
"text": "3",
"type": "text"
}, {
"command": {
"cmd_id": "remote.send",
"params": {"command": Commands.DIGIT_4, "repeat": 1}
},
"location": {
"x": 0,
"y": 1
},
"size": {
"height": 1,
"width": 1
},
"text": "4",
"type": "text"
}, {
"command": {
"cmd_id": "remote.send",
"params": {"command": Commands.DIGIT_5, "repeat": 1}
},
"location": {
"x": 1,
"y": 1
},
"size": {
"height": 1,
"width": 1
},
"text": "5",
"type": "text"
}, {
"command": {
"cmd_id": "remote.send",
"params": {"command": Commands.DIGIT_6, "repeat": 1}
},
"location": {
"x": 2,
"y": 1
},
"size": {
"height": 1,
"width": 1
},
"text": "6",
"type": "text"
}, {
"command": {
"cmd_id": "remote.send",
"params": {"command": Commands.DIGIT_7, "repeat": 1}
},
"location": {
"x": 0,
"y": 2
},
"size": {
"height": 1,
"width": 1
},
"text": "7",
"type": "text"
}, {
"command": {
"cmd_id": "remote.send",
"params": {"command": Commands.DIGIT_8, "repeat": 1}
},
"location": {
"x": 1,
"y": 2
},
"size": {
"height": 1,
"width": 1
},
"text": "8",
"type": "text"
}, {
"command": {
"cmd_id": "remote.send",
"params": {"command": Commands.DIGIT_9, "repeat": 1}
},
"location": {
"x": 2,
"y": 2
},
"size": {
"height": 1,
"width": 1
},
"text": "9",
"type": "text"
}, {
"command": {
"cmd_id": "remote.send",
"params": {"command": Commands.DIGIT_0, "repeat": 1}
},
"location": {
"x": 1,
"y": 3
},
"size": {
"height": 1,
"width": 1
},
"text": "0",
"type": "text"
}
]
}
]
]
44 changes: 23 additions & 21 deletions intg-kodi/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,42 +64,44 @@ async def command(self, cmd_id: str, params: dict[str, Any] | None = None) -> St
_LOG.warning("No Kodi instance for entity: %s", self.id)
return StatusCodes.SERVICE_UNAVAILABLE

if cmd_id == MediaPlayerCommands.VOLUME:
command = params.get("command", "")

if command == MediaPlayerCommands.VOLUME:
res = await self._device.set_volume_level(params.get("volume"))
elif cmd_id == MediaPlayerCommands.VOLUME_UP:
elif command == MediaPlayerCommands.VOLUME_UP:
res = await self._device.volume_up()
elif cmd_id == MediaPlayerCommands.VOLUME_DOWN:
elif command == MediaPlayerCommands.VOLUME_DOWN:
res = await self._device.volume_down()
elif cmd_id == MediaPlayerCommands.MUTE_TOGGLE:
elif command == MediaPlayerCommands.MUTE_TOGGLE:
res = await self._device.mute(not self._device.is_volume_muted)
elif cmd_id == MediaPlayerCommands.MUTE:
elif command == MediaPlayerCommands.MUTE:
res = await self._device.mute(True)
elif cmd_id == MediaPlayerCommands.UNMUTE:
elif command == MediaPlayerCommands.UNMUTE:
res = await self._device.mute(False)
elif cmd_id == MediaPlayerCommands.ON:
elif command == MediaPlayerCommands.ON:
return StatusCodes.NOT_IMPLEMENTED
elif cmd_id == MediaPlayerCommands.OFF:
elif command == MediaPlayerCommands.OFF:
res = await self._device.power_off()
elif cmd_id == MediaPlayerCommands.NEXT:
elif command == MediaPlayerCommands.NEXT:
res = await self._device.next()
elif cmd_id == MediaPlayerCommands.PREVIOUS:
elif command == MediaPlayerCommands.PREVIOUS:
res = await self._device.previous()
elif cmd_id == MediaPlayerCommands.PLAY_PAUSE:
elif command == MediaPlayerCommands.PLAY_PAUSE:
res = await self._device.play_pause()
elif cmd_id == MediaPlayerCommands.STOP:
elif command == MediaPlayerCommands.STOP:
res = await self._device.stop()
elif cmd_id == MediaPlayerCommands.HOME:
elif command == MediaPlayerCommands.HOME:
res = await self._device.home()
elif cmd_id == MediaPlayerCommands.SETTINGS:
elif command == MediaPlayerCommands.SETTINGS:
return StatusCodes.NOT_IMPLEMENTED # TODO ?
elif cmd_id == MediaPlayerCommands.CONTEXT_MENU:
elif command == MediaPlayerCommands.CONTEXT_MENU:
res = await self._device.context_menu()
elif cmd_id in KODI_BUTTONS_KEYMAP.keys():
res = await self._device.command_button(KODI_BUTTONS_KEYMAP[cmd_id])
elif cmd_id in KODI_ACTIONS_KEYMAP.keys():
res = await self._device.command_action(KODI_ACTIONS_KEYMAP[cmd_id])
elif cmd_id in self.options[Options.SIMPLE_COMMANDS]:
res = await self._device.command_action(KODI_SIMPLE_COMMANDS[cmd_id])
elif command in KODI_BUTTONS_KEYMAP.keys():
res = await self._device.command_button(KODI_BUTTONS_KEYMAP[command])
elif command in KODI_ACTIONS_KEYMAP.keys():
res = await self._device.command_action(KODI_ACTIONS_KEYMAP[command])
elif command in self.options[Options.SIMPLE_COMMANDS]:
res = await self._device.command_action(KODI_SIMPLE_COMMANDS[command])
elif cmd_id == Commands.SEND_CMD:
command = params.get("command", "")
holdtime = params.get("hold", "")
Expand Down

0 comments on commit 3ac3f6d

Please sign in to comment.