mirror of
https://github.com/home-assistant/core.git
synced 2026-05-08 17:49:37 +01:00
Move snapcast service registration (#162130)
This commit is contained in:
@@ -4,9 +4,20 @@ from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_HOST, CONF_PORT
|
||||
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
|
||||
from .coordinator import SnapcastUpdateCoordinator
|
||||
from .services import async_setup_services
|
||||
|
||||
CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN)
|
||||
|
||||
|
||||
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:
|
||||
|
||||
@@ -7,11 +7,5 @@ PLATFORMS: list[Platform] = [Platform.MEDIA_PLAYER]
|
||||
CLIENT_PREFIX = "snapcast_client_"
|
||||
CLIENT_SUFFIX = "Snapcast Client"
|
||||
|
||||
SERVICE_SNAPSHOT = "snapshot"
|
||||
SERVICE_RESTORE = "restore"
|
||||
SERVICE_SET_LATENCY = "set_latency"
|
||||
|
||||
ATTR_LATENCY = "latency"
|
||||
|
||||
DOMAIN = "snapcast"
|
||||
DEFAULT_TITLE = "Snapcast"
|
||||
|
||||
@@ -8,7 +8,6 @@ from typing import Any
|
||||
|
||||
from snapcast.control.client import Snapclient
|
||||
from snapcast.control.group import Snapgroup
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.media_player import (
|
||||
DOMAIN as MEDIA_PLAYER_DOMAIN,
|
||||
@@ -21,22 +20,10 @@ from homeassistant.components.media_player import (
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.exceptions import ServiceValidationError
|
||||
from homeassistant.helpers import (
|
||||
config_validation as cv,
|
||||
entity_platform,
|
||||
entity_registry as er,
|
||||
)
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
|
||||
from .const import (
|
||||
ATTR_LATENCY,
|
||||
CLIENT_PREFIX,
|
||||
CLIENT_SUFFIX,
|
||||
DOMAIN,
|
||||
SERVICE_RESTORE,
|
||||
SERVICE_SET_LATENCY,
|
||||
SERVICE_SNAPSHOT,
|
||||
)
|
||||
from .const import CLIENT_PREFIX, CLIENT_SUFFIX, DOMAIN
|
||||
from .coordinator import SnapcastUpdateCoordinator
|
||||
from .entity import SnapcastCoordinatorEntity
|
||||
|
||||
@@ -49,19 +36,6 @@ STREAM_STATUS = {
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def register_services() -> None:
|
||||
"""Register snapcast services."""
|
||||
platform = entity_platform.async_get_current_platform()
|
||||
|
||||
platform.async_register_entity_service(SERVICE_SNAPSHOT, None, "async_snapshot")
|
||||
platform.async_register_entity_service(SERVICE_RESTORE, None, "async_restore")
|
||||
platform.async_register_entity_service(
|
||||
SERVICE_SET_LATENCY,
|
||||
{vol.Required(ATTR_LATENCY): cv.positive_int},
|
||||
"async_set_latency",
|
||||
)
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
@@ -72,8 +46,6 @@ async def async_setup_entry(
|
||||
# Fetch coordinator from global data
|
||||
coordinator: SnapcastUpdateCoordinator = hass.data[DOMAIN][config_entry.entry_id]
|
||||
|
||||
register_services()
|
||||
|
||||
_known_client_ids: set[str] = set()
|
||||
|
||||
@callback
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
"""Support for interacting with Snapcast clients."""
|
||||
|
||||
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_SNAPSHOT = "snapshot"
|
||||
SERVICE_RESTORE = "restore"
|
||||
SERVICE_SET_LATENCY = "set_latency"
|
||||
|
||||
ATTR_LATENCY = "latency"
|
||||
|
||||
|
||||
@callback
|
||||
def async_setup_services(hass: HomeAssistant) -> None:
|
||||
"""Set up services."""
|
||||
service.async_register_platform_entity_service(
|
||||
hass,
|
||||
DOMAIN,
|
||||
SERVICE_SNAPSHOT,
|
||||
entity_domain=MEDIA_PLAYER_DOMAIN,
|
||||
schema=None,
|
||||
func="async_snapshot",
|
||||
)
|
||||
service.async_register_platform_entity_service(
|
||||
hass,
|
||||
DOMAIN,
|
||||
SERVICE_RESTORE,
|
||||
entity_domain=MEDIA_PLAYER_DOMAIN,
|
||||
schema=None,
|
||||
func="async_restore",
|
||||
)
|
||||
service.async_register_platform_entity_service(
|
||||
hass,
|
||||
DOMAIN,
|
||||
SERVICE_SET_LATENCY,
|
||||
entity_domain=MEDIA_PLAYER_DOMAIN,
|
||||
schema={vol.Required(ATTR_LATENCY): cv.positive_int},
|
||||
func="async_set_latency",
|
||||
)
|
||||
Reference in New Issue
Block a user