From b0f226dc75e67e40c90287ff71bea8d24aaa7fae Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Wed, 7 Oct 2026 07:30:29 +0200 Subject: [PATCH] Move hydrawise service registration to services module (#184606) Co-authored-by: Claude Opus 5.5 --- .../components/hydrawise/__init__.py | 13 ++++- .../components/hydrawise/binary_sensor.py | 33 ----------- .../components/hydrawise/services.py | 57 +++++++++++++++++++ 3 files changed, 69 insertions(+), 34 deletions(-) create mode 100644 homeassistant/components/hydrawise/services.py diff --git a/homeassistant/components/hydrawise/__init__.py b/homeassistant/components/hydrawise/__init__.py index c5b74f2f2e29..49ff8ed553af 100644 --- a/homeassistant/components/hydrawise/__init__.py +++ b/homeassistant/components/hydrawise/__init__.py @@ -7,7 +7,8 @@ from pydrawise import Controller, auth, hybrid from homeassistant.const import CONF_API_KEY, CONF_PASSWORD, CONF_USERNAME, Platform from homeassistant.core import HomeAssistant, callback from homeassistant.exceptions import ConfigEntryAuthFailed -from homeassistant.helpers import device_registry as dr +from homeassistant.helpers import config_validation as cv, device_registry as dr +from homeassistant.helpers.typing import ConfigType from .const import APP_ID, DOMAIN, MANUFACTURER from .coordinator import ( @@ -16,6 +17,7 @@ from .coordinator import ( HydrawiseUpdateCoordinators, HydrawiseWaterUseDataUpdateCoordinator, ) +from .services import async_setup_services PLATFORMS: list[Platform] = [ Platform.BINARY_SENSOR, @@ -27,6 +29,15 @@ PLATFORMS: list[Platform] = [ _REQUIRED_AUTH_KEYS = (CONF_USERNAME, CONF_PASSWORD, CONF_API_KEY) +CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN) + + +async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: + """Set up the Hunter Hydrawise integration.""" + async_setup_services(hass) + return True + + async def async_setup_entry( hass: HomeAssistant, config_entry: HydrawiseConfigEntry ) -> bool: diff --git a/homeassistant/components/hydrawise/binary_sensor.py b/homeassistant/components/hydrawise/binary_sensor.py index 00e16fdb7f99..a424ff491314 100644 --- a/homeassistant/components/hydrawise/binary_sensor.py +++ b/homeassistant/components/hydrawise/binary_sensor.py @@ -5,7 +5,6 @@ from dataclasses import dataclass from datetime import datetime from typing import override -import probatio from pydrawise import Controller, Zone from homeassistant.components.binary_sensor import ( @@ -14,11 +13,8 @@ from homeassistant.components.binary_sensor import ( BinarySensorEntityDescription, ) from homeassistant.core import HomeAssistant -from homeassistant.helpers import config_validation as cv, entity_platform from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback -from homeassistant.helpers.typing import VolDictType -from .const import SERVICE_RESUME, SERVICE_START_WATERING, SERVICE_SUSPEND from .coordinator import HydrawiseConfigEntry from .entity import HydrawiseEntity @@ -70,15 +66,6 @@ ZONE_BINARY_SENSORS: tuple[HydrawiseBinarySensorEntityDescription, ...] = ( ), ) -SCHEMA_START_WATERING: VolDictType = { - probatio.Optional("duration"): probatio.All( - probatio.Coerce(int), probatio.Range(min=0, max=1440) - ), -} -SCHEMA_SUSPEND: VolDictType = { - probatio.Required("until"): cv.datetime, -} - async def async_setup_entry( hass: HomeAssistant, @@ -127,26 +114,6 @@ async def async_setup_entry( coordinators.main.new_controllers_callbacks.append(_add_new_controllers) coordinators.main.new_zones_callbacks.append(_add_new_zones) - platform = entity_platform.async_get_current_platform() - platform.async_register_entity_service( - SERVICE_RESUME, - None, - "resume", - entity_device_classes=(BinarySensorDeviceClass.RUNNING,), - ) - platform.async_register_entity_service( - SERVICE_START_WATERING, - SCHEMA_START_WATERING, - "start_watering", - entity_device_classes=(BinarySensorDeviceClass.RUNNING,), - ) - platform.async_register_entity_service( - SERVICE_SUSPEND, - SCHEMA_SUSPEND, - "suspend", - entity_device_classes=(BinarySensorDeviceClass.RUNNING,), - ) - class HydrawiseBinarySensor(HydrawiseEntity, BinarySensorEntity): """A sensor implementation for Hydrawise device.""" diff --git a/homeassistant/components/hydrawise/services.py b/homeassistant/components/hydrawise/services.py new file mode 100644 index 000000000000..b729104f599b --- /dev/null +++ b/homeassistant/components/hydrawise/services.py @@ -0,0 +1,57 @@ +"""Services for the Hunter Hydrawise integration.""" + +import probatio + +from homeassistant.components.binary_sensor import ( + DOMAIN as BINARY_SENSOR_DOMAIN, + BinarySensorDeviceClass, +) +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_RESUME, SERVICE_START_WATERING, SERVICE_SUSPEND + +SCHEMA_START_WATERING: VolDictType = { + probatio.Optional("duration"): probatio.All( + probatio.Coerce(int), probatio.Range(min=0, max=1440) + ), +} +SCHEMA_SUSPEND: VolDictType = { + probatio.Required("until"): cv.datetime, +} + + +@callback +def async_setup_services(hass: HomeAssistant) -> None: + """Set up the services for the Hunter Hydrawise integration.""" + + service.async_register_platform_entity_service( + hass, + DOMAIN, + SERVICE_RESUME, + entity_domain=BINARY_SENSOR_DOMAIN, + schema=None, + func="resume", + entity_device_classes=(BinarySensorDeviceClass.RUNNING,), + ) + + service.async_register_platform_entity_service( + hass, + DOMAIN, + SERVICE_START_WATERING, + entity_domain=BINARY_SENSOR_DOMAIN, + schema=SCHEMA_START_WATERING, + func="start_watering", + entity_device_classes=(BinarySensorDeviceClass.RUNNING,), + ) + + service.async_register_platform_entity_service( + hass, + DOMAIN, + SERVICE_SUSPEND, + entity_domain=BINARY_SENSOR_DOMAIN, + schema=SCHEMA_SUSPEND, + func="suspend", + entity_device_classes=(BinarySensorDeviceClass.RUNNING,), + )