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

Conversation

starkillerOG
Copy link
Contributor

@starkillerOG starkillerOG commented May 21, 2023

Breaking change

Proposed change

Add event for Kodi keypresses which can be configured in the kodi keymap XML or using the Kodi GUI with the Keymap Editor add-on

A example of the Kodi keymap configuration using xml which will overwrite the volume_up/volume_down buttons and instead send notifications to HomeAssistant which will fire the event that can be used in automations to control the volume of for example a AV receiver:

<keymap>
  <global>
    <keyboard>
      <volume_up>NotifyAll("KodiLivingroom", "OnKeyPress", {"key":"volume_up"})</volume_up>
      <volume_down>NotifyAll("KodiLivingroom", "OnKeyPress", {"key":"volume_down"})</volume_down>
    </keyboard>
  </global>
</keymap>

The "KodiLivingroom" can be set to any value and will be present in the event data as the "sender"
The "OnKeyPress" is needed to identify the event in HomeAssistant, do not change this.
The {"key":"volume_up"} can contain any json which will be present in the event data under the "data" key, normally this is used to identitfy which key was pressed.

For possible keyboard key names see: https://kodi.wiki/view/List_of_keynames
For other actions see: https://kodi.wiki/view/Keymap#Keynames

For the example abbove, when the volume up key is pressed, a event in Home Assistant will be fired that looks like:

event_type: kodi_keypress
data:
  type: keypress
  device_id: 72e5g0ay5621f5d719qd8cydj943421a
  entity_id: media_player.kodi_livingroom
  sender: KodiLivingroom
  data:
    key: volume_up

A example of a automation to turn up/down the volume of a receiver:

alias: Kodi keypress
mode: parallel
max: 10
trigger:
 - platform: event
   event_type: kodi_keypress
   event_data:
     entity_id: media_player.kodi_livingroom
action:
  - choose:
      - conditions:
          - condition: template
            value_template: "{{trigger.event.data.data.key == 'volume_up'}}"
        sequence:
          - service: media_player.volume_up
            target:
              entity_id: media_player.receiver
      - conditions:
          - condition: template
            value_template: "{{trigger.event.data.data.key == 'volume_down'}}"
        sequence:
          - service: media_player.volume_down
            target:
              entity_id: media_player.receiver

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Black (black --fast homeassistant tests)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.
  • Untested files have been added to .coveragerc.

To help with the load of incoming pull requests:

@home-assistant
Copy link

Hey there @OnFreund, @cgtobi, mind taking a look at this pull request as it has been labeled with an integration (kodi) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of kodi can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign kodi Removes the current integration label and assignees on the pull request, add the integration domain after the command.

Copy link
Contributor

@emontnemery emontnemery left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the event kodi_keypress is a good idea, but I'm not sure it's suitable for a device trigger because the device trigger needs to be combined with manual YAML configuration for a useable trigger.

Other integrations which map keypresses to device triggers typically know which keypresses to expect and can thus expose a device trigger for each key.

@starkillerOG
Copy link
Contributor Author

@emontnemery in this case I don't think there is a way to know which keys are overwritten from the KODI API.
Schould I therefore remove the device_trigger part of this PR?
Then only the Event part can be merged.

@emontnemery
Copy link
Contributor

@starkillerOG yes, I would suggest to merge only the event for now 👍

@starkillerOG starkillerOG changed the title Add Kodi keypress device triggers Add Kodi keypress event May 24, 2023
@starkillerOG
Copy link
Contributor Author

@emontnemery I have removed the device trigger and only the event is now left in this PR.
Could you maybe review again?

Copy link
Contributor

@emontnemery emontnemery left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks @starkillerOG 👍

@emontnemery emontnemery merged commit 4ef315b into home-assistant:dev May 25, 2023
24 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators May 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants