mirror of
https://github.com/home-assistant/core.git
synced 2026-12-04 04:41:30 -04:00
Register heos media player actions in async_setup_services (#186077)
This commit is contained in:
@@ -46,7 +46,6 @@ from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
from homeassistant.util.dt import utcnow
|
||||
|
||||
from . import services
|
||||
from .const import DOMAIN
|
||||
from .coordinator import HeosConfigEntry, HeosCoordinator
|
||||
|
||||
@@ -119,7 +118,6 @@ async def async_setup_entry(
|
||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||
) -> None:
|
||||
"""Add media players for a config entry."""
|
||||
services.register_media_player_services()
|
||||
|
||||
def add_entities_callback(players: Sequence[HeosPlayer]) -> None:
|
||||
"""Add entities for each player."""
|
||||
|
||||
@@ -7,15 +7,15 @@ from typing import Final
|
||||
import probatio
|
||||
from pyheos import CommandAuthenticationError, Heos, HeosError
|
||||
|
||||
from homeassistant.components.media_player import ATTR_MEDIA_VOLUME_LEVEL
|
||||
from homeassistant.components.media_player import (
|
||||
ATTR_MEDIA_VOLUME_LEVEL,
|
||||
DOMAIN as MEDIA_PLAYER_DOMAIN,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntryState
|
||||
from homeassistant.core import HomeAssistant, ServiceCall, SupportsResponse, callback
|
||||
from homeassistant.exceptions import HomeAssistantError, ServiceValidationError
|
||||
from homeassistant.helpers import (
|
||||
config_validation as cv,
|
||||
entity_platform,
|
||||
issue_registry as ir,
|
||||
)
|
||||
from homeassistant.helpers import config_validation as cv, issue_registry as ir
|
||||
from homeassistant.helpers.service import async_register_platform_entity_service
|
||||
from homeassistant.helpers.typing import VolDictType, VolSchemaType
|
||||
|
||||
from .const import (
|
||||
@@ -62,6 +62,16 @@ def async_setup_services(hass: HomeAssistant) -> None:
|
||||
_sign_out_handler,
|
||||
schema=HEOS_SIGN_OUT_SCHEMA,
|
||||
)
|
||||
for description in MEDIA_PLAYER_ENTITY_SERVICES:
|
||||
async_register_platform_entity_service(
|
||||
hass,
|
||||
DOMAIN,
|
||||
description.name,
|
||||
entity_domain=MEDIA_PLAYER_DOMAIN,
|
||||
schema=description.schema,
|
||||
func=description.method_name,
|
||||
supports_response=description.supports_response,
|
||||
)
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
@@ -73,15 +83,6 @@ class EntityServiceDescription:
|
||||
schema: VolDictType | VolSchemaType | None = None
|
||||
supports_response: SupportsResponse = SupportsResponse.NONE
|
||||
|
||||
def async_register(self, platform: entity_platform.EntityPlatform) -> None:
|
||||
"""Register the service with the platform."""
|
||||
platform.async_register_entity_service(
|
||||
self.name,
|
||||
self.schema,
|
||||
self.method_name,
|
||||
supports_response=self.supports_response,
|
||||
)
|
||||
|
||||
|
||||
REMOVE_FROM_QUEUE_SCHEMA: Final[VolDictType] = {
|
||||
probatio.Required(ATTR_QUEUE_IDS): probatio.All(
|
||||
@@ -126,13 +127,6 @@ MEDIA_PLAYER_ENTITY_SERVICES: Final = (
|
||||
)
|
||||
|
||||
|
||||
def register_media_player_services() -> None:
|
||||
"""Register media_player entity services."""
|
||||
platform = entity_platform.async_get_current_platform()
|
||||
for service in MEDIA_PLAYER_ENTITY_SERVICES:
|
||||
service.async_register(platform)
|
||||
|
||||
|
||||
def _get_controller(hass: HomeAssistant) -> Heos:
|
||||
"""Get the HEOS controller instance."""
|
||||
_LOGGER.warning(
|
||||
|
||||
Reference in New Issue
Block a user