diff --git a/homeassistant/components/heos/media_player.py b/homeassistant/components/heos/media_player.py index ed1d9f304c8e..da325a57db60 100644 --- a/homeassistant/components/heos/media_player.py +++ b/homeassistant/components/heos/media_player.py @@ -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.""" diff --git a/homeassistant/components/heos/services.py b/homeassistant/components/heos/services.py index ef558a7525f1..baf813440269 100644 --- a/homeassistant/components/heos/services.py +++ b/homeassistant/components/heos/services.py @@ -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(