Move harmony service registration to services module (#184611)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
epenet
2026-10-07 07:28:46 +02:00
committed by GitHub
co-authored by Claude Opus 5.5
parent 63fbbf9af7
commit bc7469ce53
4 changed files with 53 additions and 26 deletions
+13 -2
View File
@@ -5,15 +5,26 @@ import logging
from homeassistant.components.remote import ATTR_ACTIVITY, ATTR_DELAY_SECS
from homeassistant.const import CONF_HOST, CONF_NAME, EVENT_HOMEASSISTANT_STOP
from homeassistant.core import Event, HomeAssistant, callback
from homeassistant.helpers import entity_registry as er
from homeassistant.helpers import config_validation as cv, entity_registry as er
from homeassistant.helpers.dispatcher import async_dispatcher_send
from homeassistant.helpers.typing import ConfigType
from .const import HARMONY_OPTIONS_UPDATE, PLATFORMS
from .const import DOMAIN, HARMONY_OPTIONS_UPDATE, PLATFORMS
from .data import HarmonyConfigEntry, HarmonyData
from .services import async_setup_services
_LOGGER = logging.getLogger(__name__)
CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN)
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Set up the Logitech Harmony Hub integration."""
async_setup_services(hass)
return True
async def async_setup_entry(hass: HomeAssistant, entry: HarmonyConfigEntry) -> bool:
"""Set up Logitech Harmony Hub from a config entry."""
# As there currently is no way to import options from yaml
@@ -5,8 +5,6 @@ import json
import logging
from typing import Any, override
import probatio
from homeassistant.components.remote import (
ATTR_ACTIVITY,
ATTR_DELAY_SECS,
@@ -18,11 +16,9 @@ from homeassistant.components.remote import (
RemoteEntityFeature,
)
from homeassistant.core import HassJob, HomeAssistant, callback
from homeassistant.helpers import config_validation as cv, entity_platform
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
from homeassistant.helpers.restore_state import RestoreEntity
from homeassistant.helpers.typing import VolDictType
from .const import (
ACTIVITY_POWER_OFF,
@@ -32,8 +28,6 @@ from .const import (
DOMAIN,
HARMONY_OPTIONS_UPDATE,
PREVIOUS_ACTIVE_ACTIVITY,
SERVICE_CHANGE_CHANNEL,
SERVICE_SYNC,
)
from .data import HarmonyConfigEntry, HarmonyData
from .entity import HarmonyEntity
@@ -44,12 +38,6 @@ _LOGGER = logging.getLogger(__name__)
# We want to fire remote commands right away
PARALLEL_UPDATES = 0
ATTR_CHANNEL = "channel"
HARMONY_CHANGE_CHANNEL_SCHEMA: VolDictType = {
probatio.Required(ATTR_CHANNEL): cv.positive_int,
}
async def async_setup_entry(
hass: HomeAssistant,
@@ -68,17 +56,6 @@ async def async_setup_entry(
device = HarmonyRemote(data, default_activity, delay_secs, harmony_conf_file)
async_add_entities([device])
platform = entity_platform.async_get_current_platform()
platform.async_register_entity_service(
SERVICE_SYNC,
None,
"sync",
)
platform.async_register_entity_service(
SERVICE_CHANGE_CHANNEL, HARMONY_CHANGE_CHANNEL_SCHEMA, "change_channel"
)
class HarmonyRemote(HarmonyEntity, RemoteEntity, RestoreEntity):
"""Remote representation used to control a Harmony device."""
@@ -0,0 +1,38 @@
"""Services for the Logitech Harmony Hub integration."""
import probatio
from homeassistant.components.remote import DOMAIN as REMOTE_DOMAIN
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers import config_validation as cv, service
from homeassistant.helpers.typing import VolDictType
from .const import DOMAIN, SERVICE_CHANGE_CHANNEL, SERVICE_SYNC
ATTR_CHANNEL = "channel"
HARMONY_CHANGE_CHANNEL_SCHEMA: VolDictType = {
probatio.Required(ATTR_CHANNEL): cv.positive_int,
}
@callback
def async_setup_services(hass: HomeAssistant) -> None:
"""Set up the services for the Logitech Harmony Hub integration."""
service.async_register_platform_entity_service(
hass,
DOMAIN,
SERVICE_SYNC,
entity_domain=REMOTE_DOMAIN,
schema=None,
func="sync",
)
service.async_register_platform_entity_service(
hass,
DOMAIN,
SERVICE_CHANGE_CHANNEL,
entity_domain=REMOTE_DOMAIN,
schema=HARMONY_CHANGE_CHANNEL_SCHEMA,
func="change_channel",
)
+2 -1
View File
@@ -10,7 +10,8 @@ from homeassistant.components.harmony.const import (
SERVICE_CHANGE_CHANNEL,
SERVICE_SYNC,
)
from homeassistant.components.harmony.remote import ATTR_CHANNEL, ATTR_DELAY_SECS
from homeassistant.components.harmony.remote import ATTR_DELAY_SECS
from homeassistant.components.harmony.services import ATTR_CHANNEL
from homeassistant.components.remote import (
ATTR_ACTIVITY,
ATTR_COMMAND,