1
0
mirror of https://github.com/home-assistant/core.git synced 2026-05-08 17:49:37 +01:00

Move rainbird service registration (#162089)

This commit is contained in:
epenet
2026-02-02 21:02:57 +01:00
committed by GitHub
parent 76c135913e
commit 2076700dc4
3 changed files with 47 additions and 21 deletions
+15 -5
View File
@@ -18,19 +18,26 @@ from homeassistant.const import (
)
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
from homeassistant.helpers import device_registry as dr, entity_registry as er
from homeassistant.helpers import (
config_validation as cv,
device_registry as dr,
entity_registry as er,
)
from homeassistant.helpers.device_registry import format_mac
from homeassistant.helpers.typing import ConfigType
from .const import CONF_SERIAL_NUMBER
from .const import CONF_SERIAL_NUMBER, DOMAIN
from .coordinator import (
RainbirdScheduleUpdateCoordinator,
RainbirdUpdateCoordinator,
async_create_clientsession,
)
from .services import async_setup_services
from .types import RainbirdConfigEntry, RainbirdData
_LOGGER = logging.getLogger(__name__)
CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN)
PLATFORMS = [
Platform.BINARY_SENSOR,
Platform.CALENDAR,
@@ -40,9 +47,6 @@ PLATFORMS = [
]
DOMAIN = "rainbird"
def _async_register_clientsession_shutdown(
hass: HomeAssistant,
entry: RainbirdConfigEntry,
@@ -61,6 +65,12 @@ def _async_register_clientsession_shutdown(
entry.async_on_unload(_async_close_websession)
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Set up the component."""
async_setup_services(hass)
return True
async def async_setup_entry(hass: HomeAssistant, entry: RainbirdConfigEntry) -> bool:
"""Set up the config entry for Rain Bird."""
@@ -0,0 +1,32 @@
"""Rain Bird Irrigation system services."""
from __future__ import annotations
import voluptuous as vol
from homeassistant.components.switch import DOMAIN as SWITCH_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 ATTR_DURATION, DOMAIN
SERVICE_START_IRRIGATION = "start_irrigation"
SERVICE_SCHEMA_IRRIGATION: VolDictType = {
vol.Required(ATTR_DURATION): cv.positive_float,
}
@callback
def async_setup_services(hass: HomeAssistant) -> None:
"""Set up services."""
service.async_register_platform_entity_service(
hass,
DOMAIN,
SERVICE_START_IRRIGATION,
entity_domain=SWITCH_DOMAIN,
schema=SERVICE_SCHEMA_IRRIGATION,
func="async_turn_on",
)
@@ -6,15 +6,12 @@ import logging
from typing import Any
from pyrainbird.exceptions import RainbirdApiException, RainbirdDeviceBusyException
import voluptuous as vol
from homeassistant.components.switch import SwitchEntity
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers import config_validation as cv, entity_platform
from homeassistant.helpers.device_registry import DeviceInfo
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
from homeassistant.helpers.typing import VolDictType
from homeassistant.helpers.update_coordinator import CoordinatorEntity
from .const import ATTR_DURATION, CONF_IMPORTED_NAMES, DOMAIN, MANUFACTURER
@@ -23,12 +20,6 @@ from .types import RainbirdConfigEntry
_LOGGER = logging.getLogger(__name__)
SERVICE_START_IRRIGATION = "start_irrigation"
SERVICE_SCHEMA_IRRIGATION: VolDictType = {
vol.Required(ATTR_DURATION): cv.positive_float,
}
async def async_setup_entry(
hass: HomeAssistant,
@@ -47,13 +38,6 @@ async def async_setup_entry(
for zone in coordinator.data.zones
)
platform = entity_platform.async_get_current_platform()
platform.async_register_entity_service(
SERVICE_START_IRRIGATION,
SERVICE_SCHEMA_IRRIGATION,
"async_turn_on",
)
class RainBirdSwitch(CoordinatorEntity[RainbirdUpdateCoordinator], SwitchEntity):
"""Representation of a Rain Bird switch."""