diff --git a/homeassistant/components/harmony/__init__.py b/homeassistant/components/harmony/__init__.py index e4b6f1c7c2ca..a8dd6d7cc193 100644 --- a/homeassistant/components/harmony/__init__.py +++ b/homeassistant/components/harmony/__init__.py @@ -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 diff --git a/homeassistant/components/harmony/remote.py b/homeassistant/components/harmony/remote.py index e456f0536ad5..67c4498c04ae 100644 --- a/homeassistant/components/harmony/remote.py +++ b/homeassistant/components/harmony/remote.py @@ -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.""" diff --git a/homeassistant/components/harmony/services.py b/homeassistant/components/harmony/services.py new file mode 100644 index 000000000000..0024c0659d58 --- /dev/null +++ b/homeassistant/components/harmony/services.py @@ -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", + ) diff --git a/tests/components/harmony/test_remote.py b/tests/components/harmony/test_remote.py index 5446ec8f1f6f..37e5bbea68bc 100644 --- a/tests/components/harmony/test_remote.py +++ b/tests/components/harmony/test_remote.py @@ -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,