-
-
Notifications
You must be signed in to change notification settings - Fork 38.2k
Move Kodi services from 'media_player' domain to 'kodi' #25753
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
1c653ec
Create const.py
JeffLIrion 5bf5016
Register services to 'kodi' domain, not 'media_player'
JeffLIrion 42f95f2
Add const.py to .coveragerc
JeffLIrion 0983cf1
'DATA_KODI' -> 'DOMAIN'
JeffLIrion 4629bbb
Move the Kodi services descriptions to the Kodi component
JeffLIrion de44c9a
Register Kodi services in __init__.py
JeffLIrion d3f6168
Finish registering Kodi services in __init__.py
JeffLIrion 5dce386
Remove logging statement intended only for testing
JeffLIrion 57393ab
Combine homeassistant.const imports
JeffLIrion b7a29bd
Add __init__.py to .coveragerc
JeffLIrion File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,91 @@ | ||
| """The kodi component.""" | ||
|
|
||
| import asyncio | ||
| import voluptuous as vol | ||
|
|
||
| from homeassistant.const import ATTR_ENTITY_ID, CONF_PLATFORM | ||
| from homeassistant.helpers import config_validation as cv | ||
| from homeassistant.components.kodi.const import DOMAIN | ||
| from homeassistant.components.media_player.const import DOMAIN as MP_DOMAIN | ||
|
|
||
|
|
||
| SERVICE_ADD_MEDIA = "add_to_playlist" | ||
| SERVICE_CALL_METHOD = "call_method" | ||
|
|
||
| ATTR_MEDIA_TYPE = "media_type" | ||
| ATTR_MEDIA_NAME = "media_name" | ||
| ATTR_MEDIA_ARTIST_NAME = "artist_name" | ||
| ATTR_MEDIA_ID = "media_id" | ||
| ATTR_METHOD = "method" | ||
|
|
||
| MEDIA_PLAYER_SCHEMA = vol.Schema({ATTR_ENTITY_ID: cv.comp_entity_ids}) | ||
|
|
||
| KODI_ADD_MEDIA_SCHEMA = MEDIA_PLAYER_SCHEMA.extend( | ||
| { | ||
| vol.Required(ATTR_MEDIA_TYPE): cv.string, | ||
| vol.Optional(ATTR_MEDIA_ID): cv.string, | ||
| vol.Optional(ATTR_MEDIA_NAME): cv.string, | ||
| vol.Optional(ATTR_MEDIA_ARTIST_NAME): cv.string, | ||
| } | ||
| ) | ||
| KODI_CALL_METHOD_SCHEMA = MEDIA_PLAYER_SCHEMA.extend( | ||
| {vol.Required(ATTR_METHOD): cv.string}, extra=vol.ALLOW_EXTRA | ||
| ) | ||
|
|
||
| SERVICE_TO_METHOD = { | ||
| SERVICE_ADD_MEDIA: { | ||
| "method": "async_add_media_to_playlist", | ||
| "schema": KODI_ADD_MEDIA_SCHEMA, | ||
| }, | ||
| SERVICE_CALL_METHOD: { | ||
| "method": "async_call_method", | ||
| "schema": KODI_CALL_METHOD_SCHEMA, | ||
| }, | ||
| } | ||
|
|
||
|
|
||
| async def async_setup(hass, config): | ||
| """Set up the Kodi integration.""" | ||
| if any( | ||
| ((CONF_PLATFORM, DOMAIN) in cfg.items() for cfg in config.get(MP_DOMAIN, [])) | ||
| ): | ||
| # Register the Kodi media_player services | ||
| async def async_service_handler(service): | ||
| """Map services to methods on MediaPlayerDevice.""" | ||
| method = SERVICE_TO_METHOD.get(service.service) | ||
| if not method: | ||
| return | ||
|
|
||
| params = { | ||
| key: value for key, value in service.data.items() if key != "entity_id" | ||
| } | ||
| entity_ids = service.data.get("entity_id") | ||
| if entity_ids: | ||
| target_players = [ | ||
| player | ||
| for player in hass.data[DOMAIN].values() | ||
| if player.entity_id in entity_ids | ||
| ] | ||
| else: | ||
| target_players = hass.data[DOMAIN].values() | ||
|
|
||
| update_tasks = [] | ||
| for player in target_players: | ||
| await getattr(player, method["method"])(**params) | ||
|
|
||
| for player in target_players: | ||
| if player.should_poll: | ||
| update_coro = player.async_update_ha_state(True) | ||
| update_tasks.append(update_coro) | ||
|
|
||
| if update_tasks: | ||
| await asyncio.wait(update_tasks) | ||
|
|
||
| for service in SERVICE_TO_METHOD: | ||
| schema = SERVICE_TO_METHOD[service]["schema"] | ||
| hass.services.async_register( | ||
| DOMAIN, service, async_service_handler, schema=schema | ||
| ) | ||
|
|
||
| # Return boolean to indicate that initialization was successful. | ||
| return True |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| """Constants for the Kodi platform.""" | ||
| DOMAIN = "kodi" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| # Describes the format for available Kodi services | ||
|
|
||
| add_to_playlist: | ||
| description: Add music to the default playlist (i.e. playlistid=0). | ||
| fields: | ||
| entity_id: | ||
| description: Name(s) of the Kodi entities where to add the media. | ||
| example: 'media_player.living_room_kodi' | ||
| media_type: | ||
| description: Media type identifier. It must be one of SONG or ALBUM. | ||
| example: ALBUM | ||
| media_id: | ||
| description: Unique Id of the media entry to add (`songid` or albumid`). If not defined, `media_name` and `artist_name` are needed to search the Kodi music library. | ||
| example: 123456 | ||
| media_name: | ||
| description: Optional media name for filtering media. Can be 'ALL' when `media_type` is 'ALBUM' and `artist_name` is specified, to add all songs from one artist. | ||
| example: 'Highway to Hell' | ||
| artist_name: | ||
| description: Optional artist name for filtering media. | ||
| example: 'AC/DC' | ||
|
|
||
| call_method: | ||
| description: 'Call a Kodi JSONRPC API method with optional parameters. Results of the Kodi API call will be redirected in a Home Assistant event: `kodi_call_method_result`.' | ||
| fields: | ||
| entity_id: | ||
| description: Name(s) of the Kodi entities where to run the API method. | ||
| example: 'media_player.living_room_kodi' | ||
| method: | ||
| description: Name of the Kodi JSONRPC API method to be called. | ||
| example: 'VideoLibrary.GetRecentlyAddedEpisodes' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can mark it as
kodi/*