mirror of
https://github.com/home-assistant/core.git
synced 2026-02-15 07:36:16 +00:00
Move roon service registration (#162129)
This commit is contained in:
@@ -3,14 +3,23 @@
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_HOST, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import device_registry as dr
|
||||
from homeassistant.helpers import config_validation as cv, device_registry as dr
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
|
||||
from .const import CONF_ROON_NAME, DOMAIN
|
||||
from .server import RoonServer
|
||||
from .services import async_setup_services
|
||||
|
||||
CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN)
|
||||
PLATFORMS = [Platform.EVENT, Platform.MEDIA_PLAYER]
|
||||
|
||||
|
||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
"""Set up the component."""
|
||||
async_setup_services(hass)
|
||||
return True
|
||||
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Set up a roonserver from a config entry."""
|
||||
hass.data.setdefault(DOMAIN, {})
|
||||
|
||||
@@ -6,7 +6,6 @@ import logging
|
||||
from typing import Any, cast
|
||||
|
||||
from roonapi import split_media_path
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.media_player import (
|
||||
BrowseMedia,
|
||||
@@ -19,7 +18,6 @@ from homeassistant.components.media_player import (
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import DEVICE_DEFAULT_NAME
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers import config_validation as cv, entity_platform
|
||||
from homeassistant.helpers.device_registry import DeviceInfo
|
||||
from homeassistant.helpers.dispatcher import (
|
||||
async_dispatcher_connect,
|
||||
@@ -34,10 +32,6 @@ from .media_browser import browse_media
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
SERVICE_TRANSFER = "transfer"
|
||||
|
||||
ATTR_TRANSFER = "transfer_id"
|
||||
|
||||
REPEAT_MODE_MAPPING_TO_HA = {
|
||||
"loop": RepeatMode.ALL,
|
||||
"disabled": RepeatMode.OFF,
|
||||
@@ -58,14 +52,6 @@ async def async_setup_entry(
|
||||
roon_server = hass.data[DOMAIN][config_entry.entry_id]
|
||||
media_players = set()
|
||||
|
||||
# Register entity services
|
||||
platform = entity_platform.async_get_current_platform()
|
||||
platform.async_register_entity_service(
|
||||
SERVICE_TRANSFER,
|
||||
{vol.Required(ATTR_TRANSFER): cv.entity_id},
|
||||
"async_transfer",
|
||||
)
|
||||
|
||||
@callback
|
||||
def async_update_media_player(player_data):
|
||||
"""Add or update Roon MediaPlayer."""
|
||||
|
||||
28
homeassistant/components/roon/services.py
Normal file
28
homeassistant/components/roon/services.py
Normal file
@@ -0,0 +1,28 @@
|
||||
"""MediaPlayer platform for Roon integration."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.media_player import DOMAIN as MEDIA_PLAYER_DOMAIN
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers import config_validation as cv, service
|
||||
|
||||
from .const import DOMAIN
|
||||
|
||||
SERVICE_TRANSFER = "transfer"
|
||||
|
||||
ATTR_TRANSFER = "transfer_id"
|
||||
|
||||
|
||||
@callback
|
||||
def async_setup_services(hass: HomeAssistant) -> None:
|
||||
"""Set up services."""
|
||||
service.async_register_platform_entity_service(
|
||||
hass,
|
||||
DOMAIN,
|
||||
SERVICE_TRANSFER,
|
||||
entity_domain=MEDIA_PLAYER_DOMAIN,
|
||||
schema={vol.Required(ATTR_TRANSFER): cv.entity_id},
|
||||
func="async_transfer",
|
||||
)
|
||||
Reference in New Issue
Block a user