diff --git a/homeassistant/components/snooz/__init__.py b/homeassistant/components/snooz/__init__.py index 2aada56a8c4d..2b30195d5a82 100644 --- a/homeassistant/components/snooz/__init__.py +++ b/homeassistant/components/snooz/__init__.py @@ -14,9 +14,20 @@ from homeassistant.components.bluetooth import ( from homeassistant.const import CONF_ADDRESS, CONF_TOKEN from homeassistant.core import HomeAssistant from homeassistant.exceptions import ConfigEntryNotReady +from homeassistant.helpers import config_validation as cv +from homeassistant.helpers.typing import ConfigType from .const import DOMAIN, PLATFORMS from .models import SnoozConfigEntry, SnoozConfigurationData +from .services import async_setup_services + +CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN) + + +async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: + """Set up the Snooz integration.""" + async_setup_services(hass) + return True async def async_setup_entry(hass: HomeAssistant, entry: SnoozConfigEntry) -> bool: diff --git a/homeassistant/components/snooz/fan.py b/homeassistant/components/snooz/fan.py index 2eb712a4da0d..754343a0aff7 100644 --- a/homeassistant/components/snooz/fan.py +++ b/homeassistant/components/snooz/fan.py @@ -4,7 +4,6 @@ from collections.abc import Callable from datetime import timedelta from typing import Any, override -import probatio from pysnooz import UnknownSnoozState from pysnooz.commands import ( SnoozCommandData, @@ -22,19 +21,11 @@ from homeassistant.components.fan import ( from homeassistant.const import STATE_OFF, STATE_ON from homeassistant.core import HomeAssistant, callback from homeassistant.exceptions import HomeAssistantError -from homeassistant.helpers import entity_platform from homeassistant.helpers.device_registry import CONNECTION_BLUETOOTH, DeviceInfo from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback from homeassistant.helpers.restore_state import RestoreEntity -from .const import ( - ATTR_DURATION, - ATTR_VOLUME, - DEFAULT_TRANSITION_DURATION, - DOMAIN, - SERVICE_TRANSITION_OFF, - SERVICE_TRANSITION_ON, -) +from .const import DOMAIN from .models import SnoozConfigEntry, SnoozConfigurationData @@ -45,29 +36,6 @@ async def async_setup_entry( ) -> None: """Set up Snooz device from a config entry.""" - platform = entity_platform.async_get_current_platform() - platform.async_register_entity_service( - SERVICE_TRANSITION_ON, - { - probatio.Optional(ATTR_VOLUME): probatio.All( - probatio.Coerce(int), probatio.Percentage() - ), - probatio.Optional( - ATTR_DURATION, default=DEFAULT_TRANSITION_DURATION - ): probatio.All(probatio.Coerce(int), probatio.Range(min=1, max=300)), - }, - "async_transition_on", - ) - platform.async_register_entity_service( - SERVICE_TRANSITION_OFF, - { - probatio.Optional( - ATTR_DURATION, default=DEFAULT_TRANSITION_DURATION - ): probatio.All(probatio.Coerce(int), probatio.Range(min=1, max=300)), - }, - "async_transition_off", - ) - async_add_entities([SnoozFan(entry.runtime_data)]) diff --git a/homeassistant/components/snooz/services.py b/homeassistant/components/snooz/services.py new file mode 100644 index 000000000000..5fecccd86be4 --- /dev/null +++ b/homeassistant/components/snooz/services.py @@ -0,0 +1,50 @@ +"""Services for the Snooz integration.""" + +import probatio + +from homeassistant.components.fan import DOMAIN as FAN_DOMAIN +from homeassistant.core import HomeAssistant, callback +from homeassistant.helpers import service + +from .const import ( + ATTR_DURATION, + ATTR_VOLUME, + DEFAULT_TRANSITION_DURATION, + DOMAIN, + SERVICE_TRANSITION_OFF, + SERVICE_TRANSITION_ON, +) + + +@callback +def async_setup_services(hass: HomeAssistant) -> None: + """Set up the services for the Snooz integration.""" + + service.async_register_platform_entity_service( + hass, + DOMAIN, + SERVICE_TRANSITION_ON, + entity_domain=FAN_DOMAIN, + schema={ + probatio.Optional(ATTR_VOLUME): probatio.All( + probatio.Coerce(int), probatio.Percentage() + ), + probatio.Optional( + ATTR_DURATION, default=DEFAULT_TRANSITION_DURATION + ): probatio.All(probatio.Coerce(int), probatio.Range(min=1, max=300)), + }, + func="async_transition_on", + ) + + service.async_register_platform_entity_service( + hass, + DOMAIN, + SERVICE_TRANSITION_OFF, + entity_domain=FAN_DOMAIN, + schema={ + probatio.Optional( + ATTR_DURATION, default=DEFAULT_TRANSITION_DURATION + ): probatio.All(probatio.Coerce(int), probatio.Range(min=1, max=300)) + }, + func="async_transition_off", + )