mirror of
https://github.com/home-assistant/core.git
synced 2026-02-15 07:36:16 +00:00
Move sharkiq service registration (#162147)
This commit is contained in:
@@ -16,7 +16,9 @@ from homeassistant import exceptions
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_PASSWORD, CONF_REGION, CONF_USERNAME
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
from homeassistant.helpers.aiohttp_client import async_create_clientsession
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
|
||||
from .const import (
|
||||
API_TIMEOUT,
|
||||
@@ -27,6 +29,9 @@ from .const import (
|
||||
SHARKIQ_REGION_EUROPE,
|
||||
)
|
||||
from .coordinator import SharkIqUpdateCoordinator
|
||||
from .services import async_setup_services
|
||||
|
||||
CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN)
|
||||
|
||||
|
||||
class CannotConnect(exceptions.HomeAssistantError):
|
||||
@@ -49,6 +54,12 @@ async def async_connect_or_timeout(ayla_api: AylaApi) -> bool:
|
||||
return True
|
||||
|
||||
|
||||
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, config_entry: ConfigEntry) -> bool:
|
||||
"""Initialize the sharkiq platform via config entry."""
|
||||
if CONF_REGION not in config_entry.data:
|
||||
|
||||
@@ -12,7 +12,8 @@ PLATFORMS = [Platform.VACUUM]
|
||||
DOMAIN = "sharkiq"
|
||||
SHARK = "Shark"
|
||||
UPDATE_INTERVAL = timedelta(seconds=30)
|
||||
SERVICE_CLEAN_ROOM = "clean_room"
|
||||
|
||||
ATTR_ROOMS = "rooms"
|
||||
|
||||
SHARKIQ_REGION_EUROPE = "europe"
|
||||
SHARKIQ_REGION_ELSEWHERE = "elsewhere"
|
||||
|
||||
32
homeassistant/components/sharkiq/services.py
Normal file
32
homeassistant/components/sharkiq/services.py
Normal file
@@ -0,0 +1,32 @@
|
||||
"""Shark IQ services."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.vacuum import DOMAIN as VACUUM_DOMAIN
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers import config_validation as cv, service
|
||||
|
||||
from .const import ATTR_ROOMS, DOMAIN
|
||||
|
||||
SERVICE_CLEAN_ROOM = "clean_room"
|
||||
|
||||
|
||||
@callback
|
||||
def async_setup_services(hass: HomeAssistant) -> None:
|
||||
"""Set up services."""
|
||||
|
||||
# Vacuum Services
|
||||
service.async_register_platform_entity_service(
|
||||
hass,
|
||||
DOMAIN,
|
||||
SERVICE_CLEAN_ROOM,
|
||||
entity_domain=VACUUM_DOMAIN,
|
||||
schema={
|
||||
vol.Required(ATTR_ROOMS): vol.All(
|
||||
cv.ensure_list, vol.Length(min=1), [cv.string]
|
||||
),
|
||||
},
|
||||
func="async_clean_room",
|
||||
)
|
||||
@@ -6,7 +6,6 @@ from collections.abc import Iterable
|
||||
from typing import Any
|
||||
|
||||
from sharkiq import OperatingModes, PowerModes, Properties, SharkIqVacuum
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.vacuum import (
|
||||
StateVacuumEntity,
|
||||
@@ -16,12 +15,11 @@ from homeassistant.components.vacuum import (
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import ServiceValidationError
|
||||
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.update_coordinator import CoordinatorEntity
|
||||
|
||||
from .const import DOMAIN, LOGGER, SERVICE_CLEAN_ROOM, SHARK
|
||||
from .const import ATTR_ROOMS, DOMAIN, LOGGER, SHARK
|
||||
from .coordinator import SharkIqUpdateCoordinator
|
||||
|
||||
OPERATING_STATE_MAP = {
|
||||
@@ -44,7 +42,6 @@ ATTR_ERROR_CODE = "last_error_code"
|
||||
ATTR_ERROR_MSG = "last_error_message"
|
||||
ATTR_LOW_LIGHT = "low_light"
|
||||
ATTR_RECHARGE_RESUME = "recharge_and_resume"
|
||||
ATTR_ROOMS = "rooms"
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
@@ -63,17 +60,6 @@ async def async_setup_entry(
|
||||
)
|
||||
async_add_entities([SharkVacuumEntity(d, coordinator) for d in devices])
|
||||
|
||||
platform = entity_platform.async_get_current_platform()
|
||||
platform.async_register_entity_service(
|
||||
SERVICE_CLEAN_ROOM,
|
||||
{
|
||||
vol.Required(ATTR_ROOMS): vol.All(
|
||||
cv.ensure_list, vol.Length(min=1), [cv.string]
|
||||
),
|
||||
},
|
||||
"async_clean_room",
|
||||
)
|
||||
|
||||
|
||||
class SharkVacuumEntity(CoordinatorEntity[SharkIqUpdateCoordinator], StateVacuumEntity):
|
||||
"""Shark IQ vacuum entity."""
|
||||
|
||||
@@ -15,15 +15,14 @@ from voluptuous.error import MultipleInvalid
|
||||
|
||||
from homeassistant import exceptions
|
||||
from homeassistant.components.homeassistant import SERVICE_UPDATE_ENTITY
|
||||
from homeassistant.components.sharkiq import DOMAIN
|
||||
from homeassistant.components.sharkiq.const import ATTR_ROOMS, DOMAIN
|
||||
from homeassistant.components.sharkiq.services import SERVICE_CLEAN_ROOM
|
||||
from homeassistant.components.sharkiq.vacuum import (
|
||||
ATTR_ERROR_CODE,
|
||||
ATTR_ERROR_MSG,
|
||||
ATTR_LOW_LIGHT,
|
||||
ATTR_RECHARGE_RESUME,
|
||||
ATTR_ROOMS,
|
||||
FAN_SPEEDS_MAP,
|
||||
SERVICE_CLEAN_ROOM,
|
||||
)
|
||||
from homeassistant.components.vacuum import (
|
||||
ATTR_BATTERY_LEVEL,
|
||||
|
||||
Reference in New Issue
Block a user