From 40096110888a026df776d9098bbc1f6efaea9ea8 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Tue, 6 Oct 2026 14:10:44 +0200 Subject: [PATCH] Move bluesound service registration to services module (#184461) Co-authored-by: Claude Opus 5.5 --- .../components/bluesound/__init__.py | 24 +++------------ .../components/bluesound/services.py | 30 +++++++++++++++++++ 2 files changed, 34 insertions(+), 20 deletions(-) create mode 100644 homeassistant/components/bluesound/services.py diff --git a/homeassistant/components/bluesound/__init__.py b/homeassistant/components/bluesound/__init__.py index a3dc5d4bf88c..26a15e2c3e4d 100644 --- a/homeassistant/components/bluesound/__init__.py +++ b/homeassistant/components/bluesound/__init__.py @@ -1,24 +1,23 @@ """The bluesound component.""" -import probatio from pyblu import Player from pyblu.errors import PlayerUnreachableError -from homeassistant.components.media_player import DOMAIN as MEDIA_PLAYER_DOMAIN from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_HOST, CONF_PORT, Platform from homeassistant.core import HomeAssistant from homeassistant.exceptions import ConfigEntryNotReady -from homeassistant.helpers import config_validation as cv, service +from homeassistant.helpers import config_validation as cv from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.helpers.typing import ConfigType -from .const import ATTR_MASTER, DOMAIN, SERVICE_JOIN, SERVICE_UNJOIN +from .const import DOMAIN from .coordinator import ( BluesoundConfigEntry, BluesoundCoordinator, BluesoundRuntimeData, ) +from .services import async_setup_services CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN) @@ -30,22 +29,7 @@ PLATFORMS = [ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: """Set up the Bluesound.""" - service.async_register_platform_entity_service( - hass, - DOMAIN, - SERVICE_JOIN, - entity_domain=MEDIA_PLAYER_DOMAIN, - schema={probatio.Required(ATTR_MASTER): cv.entity_id}, - func="async_bluesound_join", - ) - service.async_register_platform_entity_service( - hass, - DOMAIN, - SERVICE_UNJOIN, - entity_domain=MEDIA_PLAYER_DOMAIN, - schema=None, - func="async_bluesound_unjoin", - ) + async_setup_services(hass) return True diff --git a/homeassistant/components/bluesound/services.py b/homeassistant/components/bluesound/services.py new file mode 100644 index 000000000000..68f5bd9afc67 --- /dev/null +++ b/homeassistant/components/bluesound/services.py @@ -0,0 +1,30 @@ +"""Services for the Bluesound integration.""" + +import probatio + +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 ATTR_MASTER, DOMAIN, SERVICE_JOIN, SERVICE_UNJOIN + + +@callback +def async_setup_services(hass: HomeAssistant) -> None: + """Set up the services for the Bluesound integration.""" + service.async_register_platform_entity_service( + hass, + DOMAIN, + SERVICE_JOIN, + entity_domain=MEDIA_PLAYER_DOMAIN, + schema={probatio.Required(ATTR_MASTER): cv.entity_id}, + func="async_bluesound_join", + ) + service.async_register_platform_entity_service( + hass, + DOMAIN, + SERVICE_UNJOIN, + entity_domain=MEDIA_PLAYER_DOMAIN, + schema=None, + func="async_bluesound_unjoin", + )