From a76e6c35e41be73d356995cf02e1a59d03bb9d77 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Wed, 7 Oct 2026 09:05:51 +0200 Subject: [PATCH] Move channels service registration to services module (#184636) Co-authored-by: Claude Opus 5.5 --- homeassistant/components/channels/__init__.py | 15 +++++++ .../components/channels/media_player.py | 24 +---------- homeassistant/components/channels/services.py | 42 +++++++++++++++++++ 3 files changed, 59 insertions(+), 22 deletions(-) create mode 100644 homeassistant/components/channels/services.py diff --git a/homeassistant/components/channels/__init__.py b/homeassistant/components/channels/__init__.py index 70a8c0677deb..8a7160fd18a1 100644 --- a/homeassistant/components/channels/__init__.py +++ b/homeassistant/components/channels/__init__.py @@ -1 +1,16 @@ """The channels component.""" + +from homeassistant.core import HomeAssistant +from homeassistant.helpers import config_validation as cv +from homeassistant.helpers.typing import ConfigType + +from .const import DOMAIN +from .services import async_setup_services + +CONFIG_SCHEMA = cv.platform_only_config_schema(DOMAIN) + + +async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: + """Set up the Channels integration.""" + async_setup_services(hass) + return True diff --git a/homeassistant/components/channels/media_player.py b/homeassistant/components/channels/media_player.py index 320c8e6bae18..9e991d8ac2b7 100644 --- a/homeassistant/components/channels/media_player.py +++ b/homeassistant/components/channels/media_player.py @@ -12,14 +12,12 @@ from homeassistant.components.media_player import ( MediaPlayerState, MediaType, ) -from homeassistant.const import ATTR_SECONDS, CONF_HOST, CONF_NAME, CONF_PORT +from homeassistant.const import CONF_HOST, CONF_NAME, CONF_PORT from homeassistant.core import HomeAssistant -from homeassistant.helpers import config_validation as cv, entity_platform +from homeassistant.helpers import config_validation as cv from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType -from .const import SERVICE_SEEK_BACKWARD, SERVICE_SEEK_BY, SERVICE_SEEK_FORWARD - DATA_CHANNELS = "channels" DEFAULT_NAME = "Channels" DEFAULT_PORT = 57000 @@ -43,24 +41,6 @@ async def async_setup_platform( device = ChannelsPlayer(config[CONF_NAME], config[CONF_HOST], config[CONF_PORT]) async_add_entities([device], True) - platform = entity_platform.async_get_current_platform() - - platform.async_register_entity_service( - SERVICE_SEEK_FORWARD, - None, - "seek_forward", - ) - platform.async_register_entity_service( - SERVICE_SEEK_BACKWARD, - None, - "seek_backward", - ) - platform.async_register_entity_service( - SERVICE_SEEK_BY, - {probatio.Required(ATTR_SECONDS): probatio.Coerce(int)}, - "seek_by", - ) - class ChannelsPlayer(MediaPlayerEntity): """Representation of a Channels instance.""" diff --git a/homeassistant/components/channels/services.py b/homeassistant/components/channels/services.py new file mode 100644 index 000000000000..6f05fe3c9dc2 --- /dev/null +++ b/homeassistant/components/channels/services.py @@ -0,0 +1,42 @@ +"""Services for the Channels integration.""" + +import probatio + +from homeassistant.components.media_player import DOMAIN as MEDIA_PLAYER_DOMAIN +from homeassistant.const import ATTR_SECONDS +from homeassistant.core import HomeAssistant, callback +from homeassistant.helpers import service + +from .const import DOMAIN, SERVICE_SEEK_BACKWARD, SERVICE_SEEK_BY, SERVICE_SEEK_FORWARD + + +@callback +def async_setup_services(hass: HomeAssistant) -> None: + """Set up the services for the Channels integration.""" + + service.async_register_platform_entity_service( + hass, + DOMAIN, + SERVICE_SEEK_FORWARD, + entity_domain=MEDIA_PLAYER_DOMAIN, + schema=None, + func="seek_forward", + ) + + service.async_register_platform_entity_service( + hass, + DOMAIN, + SERVICE_SEEK_BACKWARD, + entity_domain=MEDIA_PLAYER_DOMAIN, + schema=None, + func="seek_backward", + ) + + service.async_register_platform_entity_service( + hass, + DOMAIN, + SERVICE_SEEK_BY, + entity_domain=MEDIA_PLAYER_DOMAIN, + schema={probatio.Required(ATTR_SECONDS): probatio.Coerce(int)}, + func="seek_by", + )