mirror of
https://github.com/home-assistant/core.git
synced 2026-05-08 09:38:58 +01:00
Move linkplay service registration (#162126)
This commit is contained in:
@@ -12,10 +12,15 @@ from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_HOST
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import ConfigEntryNotReady
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
|
||||
from .const import DOMAIN, PLATFORMS, SHARED_DATA, LinkPlaySharedData
|
||||
from .services import async_setup_services
|
||||
from .utils import async_get_client_session
|
||||
|
||||
CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN)
|
||||
|
||||
|
||||
@dataclass
|
||||
class LinkPlayData:
|
||||
@@ -27,6 +32,12 @@ class LinkPlayData:
|
||||
type LinkPlayConfigEntry = ConfigEntry[LinkPlayData]
|
||||
|
||||
|
||||
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: LinkPlayConfigEntry) -> bool:
|
||||
"""Async setup hass config entry. Called when an entry has been setup."""
|
||||
|
||||
|
||||
@@ -10,7 +10,6 @@ from linkplay.bridge import LinkPlayBridge
|
||||
from linkplay.consts import EqualizerMode, LoopMode, PlayingMode, PlayingStatus
|
||||
from linkplay.controller import LinkPlayController, LinkPlayMultiroom
|
||||
from linkplay.exceptions import LinkPlayRequestException
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components import media_source
|
||||
from homeassistant.components.media_player import (
|
||||
@@ -25,7 +24,6 @@ from homeassistant.components.media_player import (
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError, ServiceValidationError
|
||||
from homeassistant.helpers import config_validation as cv, entity_platform
|
||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
from homeassistant.util.dt import utcnow
|
||||
|
||||
@@ -106,15 +104,6 @@ SEEKABLE_FEATURES: MediaPlayerEntityFeature = (
|
||||
| MediaPlayerEntityFeature.SEEK
|
||||
)
|
||||
|
||||
SERVICE_PLAY_PRESET = "play_preset"
|
||||
ATTR_PRESET_NUMBER = "preset_number"
|
||||
|
||||
SERVICE_PLAY_PRESET_SCHEMA = cv.make_entity_service_schema(
|
||||
{
|
||||
vol.Required(ATTR_PRESET_NUMBER): cv.positive_int,
|
||||
}
|
||||
)
|
||||
|
||||
RETRY_POLL_MAXIMUM = 3
|
||||
SCAN_INTERVAL = timedelta(seconds=5)
|
||||
PARALLEL_UPDATES = 1
|
||||
@@ -126,14 +115,6 @@ async def async_setup_entry(
|
||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up a media player from a config entry."""
|
||||
|
||||
# register services
|
||||
platform = entity_platform.async_get_current_platform()
|
||||
platform.async_register_entity_service(
|
||||
SERVICE_PLAY_PRESET, SERVICE_PLAY_PRESET_SCHEMA, "async_play_preset"
|
||||
)
|
||||
|
||||
# add entities
|
||||
async_add_entities([LinkPlayMediaPlayerEntity(entry.runtime_data.bridge)])
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
"""Support for LinkPlay media players."""
|
||||
|
||||
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_PLAY_PRESET = "play_preset"
|
||||
ATTR_PRESET_NUMBER = "preset_number"
|
||||
|
||||
SERVICE_PLAY_PRESET_SCHEMA = cv.make_entity_service_schema(
|
||||
{
|
||||
vol.Required(ATTR_PRESET_NUMBER): cv.positive_int,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@callback
|
||||
def async_setup_services(hass: HomeAssistant) -> None:
|
||||
"""Set up services."""
|
||||
service.async_register_platform_entity_service(
|
||||
hass,
|
||||
DOMAIN,
|
||||
SERVICE_PLAY_PRESET,
|
||||
entity_domain=MEDIA_PLAYER_DOMAIN,
|
||||
schema=SERVICE_PLAY_PRESET_SCHEMA,
|
||||
func="async_play_preset",
|
||||
)
|
||||
Reference in New Issue
Block a user