Move motion_blinds service registration to services module (#184464)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
epenet
2026-10-06 15:10:15 +02:00
committed by GitHub
co-authored by Claude Opus 5.5
parent e37cd6fea0
commit d2f5236b2e
3 changed files with 53 additions and 25 deletions
@@ -9,7 +9,8 @@ from motionblinds import DEVICE_TYPES_GATEWAY, DEVICE_TYPES_WIFI, AsyncMotionMul
from homeassistant.const import CONF_API_KEY, CONF_HOST, EVENT_HOMEASSISTANT_STOP
from homeassistant.core import CALLBACK_TYPE, HomeAssistant
from homeassistant.exceptions import ConfigEntryNotReady
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 homeassistant.util.hass_dict import HassKey
from .const import (
@@ -22,6 +23,7 @@ from .const import (
from .coordinator import DataUpdateCoordinatorMotionBlinds, MotionBlindsConfigEntry
from .entity import gateway_device_info
from .gateway import ConnectMotionGateway
from .services import async_setup_services
_LOGGER = logging.getLogger(__name__)
@@ -40,6 +42,15 @@ class MotionBlindsData:
MOTION_BLINDS_DATA: HassKey[MotionBlindsData] = HassKey(DOMAIN)
CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN)
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Set up the Motionblinds integration."""
async_setup_services(hass)
return True
async def async_setup_entry(
hass: HomeAssistant, entry: MotionBlindsConfigEntry
) -> bool:
@@ -4,7 +4,6 @@ import logging
from typing import Any, override
from motionblinds import BlindType
import probatio
from homeassistant.components.cover import (
ATTR_POSITION,
@@ -14,16 +13,13 @@ from homeassistant.components.cover import (
CoverEntityFeature,
)
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 (
ATTR_ABSOLUTE_POSITION,
ATTR_AVAILABLE,
ATTR_WIDTH,
KEY_GATEWAY,
SERVICE_SET_ABSOLUTE_POSITION,
UPDATE_DELAY_STOP,
)
from .coordinator import MotionBlindsConfigEntry
@@ -71,19 +67,6 @@ TDBU_DEVICE_MAP = {
}
SET_ABSOLUTE_POSITION_SCHEMA: VolDictType = {
probatio.Required(ATTR_ABSOLUTE_POSITION): probatio.All(
cv.positive_int, probatio.Range(max=100)
),
probatio.Optional(ATTR_TILT_POSITION): probatio.All(
cv.positive_int, probatio.Range(max=100)
),
probatio.Optional(ATTR_WIDTH): probatio.All(
cv.positive_int, probatio.Range(max=100)
),
}
async def async_setup_entry(
hass: HomeAssistant,
config_entry: MotionBlindsConfigEntry,
@@ -163,13 +146,6 @@ async def async_setup_entry(
async_add_entities(entities)
platform = entity_platform.async_get_current_platform()
platform.async_register_entity_service(
SERVICE_SET_ABSOLUTE_POSITION,
SET_ABSOLUTE_POSITION_SCHEMA,
"async_set_absolute_position",
)
class MotionBaseDevice(MotionCoordinatorEntity, CoverEntity):
"""Representation of a Motionblinds Device."""
@@ -0,0 +1,41 @@
"""Services for the Motionblinds integration."""
import probatio
from homeassistant.components.cover import ATTR_TILT_POSITION, DOMAIN as COVER_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_ABSOLUTE_POSITION,
ATTR_WIDTH,
DOMAIN,
SERVICE_SET_ABSOLUTE_POSITION,
)
SET_ABSOLUTE_POSITION_SCHEMA: VolDictType = {
probatio.Required(ATTR_ABSOLUTE_POSITION): probatio.All(
cv.positive_int, probatio.Range(max=100)
),
probatio.Optional(ATTR_TILT_POSITION): probatio.All(
cv.positive_int, probatio.Range(max=100)
),
probatio.Optional(ATTR_WIDTH): probatio.All(
cv.positive_int, probatio.Range(max=100)
),
}
@callback
def async_setup_services(hass: HomeAssistant) -> None:
"""Set up the services for the Motionblinds integration."""
service.async_register_platform_entity_service(
hass,
DOMAIN,
SERVICE_SET_ABSOLUTE_POSITION,
entity_domain=COVER_DOMAIN,
schema=SET_ABSOLUTE_POSITION_SCHEMA,
func="async_set_absolute_position",
)