Move lawn mower service registration to services module (#182566)

This commit is contained in:
epenet
2026-09-18 20:48:59 +02:00
committed by GitHub
parent 24742fe2e0
commit 8620c85779
3 changed files with 47 additions and 19 deletions
@@ -12,9 +12,9 @@ from homeassistant.helpers import config_validation as cv
from homeassistant.helpers.entity import Entity, EntityDescription
from homeassistant.helpers.entity_component import EntityComponent
from homeassistant.helpers.typing import ConfigType
from homeassistant.util.hass_dict import HassKey
from .const import (
from .const import ( # noqa: F401
DATA_COMPONENT,
DOMAIN,
SERVICE_DOCK,
SERVICE_PAUSE,
@@ -23,10 +23,10 @@ from .const import (
LawnMowerActivity,
LawnMowerEntityFeature,
)
from .services import async_setup_services
_LOGGER = logging.getLogger(__name__)
DATA_COMPONENT: HassKey[EntityComponent[LawnMowerEntity]] = HassKey(DOMAIN)
ENTITY_ID_FORMAT = DOMAIN + ".{}"
PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA
PLATFORM_SCHEMA_BASE = cv.PLATFORM_SCHEMA_BASE
@@ -40,21 +40,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
)
await component.async_setup(config)
component.async_register_entity_service(
SERVICE_START_MOWING,
None,
"async_start_mowing",
[LawnMowerEntityFeature.START_MOWING],
)
component.async_register_entity_service(
SERVICE_PAUSE, None, "async_pause", [LawnMowerEntityFeature.PAUSE]
)
component.async_register_entity_service(
SERVICE_DOCK, None, "async_dock", [LawnMowerEntityFeature.DOCK]
)
component.async_register_entity_service(
SERVICE_STOP, None, "async_stop", [LawnMowerEntityFeature.STOP]
)
async_setup_services(hass)
return True
+9 -1
View File
@@ -1,9 +1,17 @@
"""Constants for the lawn mower integration."""
from enum import IntFlag, StrEnum
from typing import Final
from typing import TYPE_CHECKING, Final
from homeassistant.util.hass_dict import HassKey
if TYPE_CHECKING:
from homeassistant.helpers.entity_component import EntityComponent
from . import LawnMowerEntity
DOMAIN: Final = "lawn_mower"
DATA_COMPONENT: HassKey[EntityComponent[LawnMowerEntity]] = HassKey(DOMAIN)
class LawnMowerActivity(StrEnum):
@@ -0,0 +1,34 @@
"""Services for the Lawn mower integration."""
from homeassistant.core import HomeAssistant, callback
from .const import (
DATA_COMPONENT,
SERVICE_DOCK,
SERVICE_PAUSE,
SERVICE_START_MOWING,
SERVICE_STOP,
LawnMowerEntityFeature,
)
@callback
def async_setup_services(hass: HomeAssistant) -> None:
"""Register the lawn mower services."""
component = hass.data[DATA_COMPONENT]
component.async_register_entity_service(
SERVICE_START_MOWING,
None,
"async_start_mowing",
[LawnMowerEntityFeature.START_MOWING],
)
component.async_register_entity_service(
SERVICE_PAUSE, None, "async_pause", [LawnMowerEntityFeature.PAUSE]
)
component.async_register_entity_service(
SERVICE_DOCK, None, "async_dock", [LawnMowerEntityFeature.DOCK]
)
component.async_register_entity_service(
SERVICE_STOP, None, "async_stop", [LawnMowerEntityFeature.STOP]
)