Move channels service registration to services module (#184636)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
epenet
2026-10-07 09:05:51 +02:00
committed by GitHub
co-authored by Claude Opus 5.5
parent 0762cc80d4
commit a76e6c35e4
3 changed files with 59 additions and 22 deletions
@@ -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
@@ -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."""
@@ -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",
)