mirror of
https://github.com/home-assistant/core.git
synced 2026-12-05 05:14:01 -04:00
Move switcher_kis service registration to services module (#184608)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
7c24762c65
commit
1219a56e6b
@@ -8,10 +8,12 @@ from aioswitcher.device import SwitcherBase
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_TOKEN, EVENT_HOMEASSISTANT_STOP, Platform
|
||||
from homeassistant.core import Event, HomeAssistant, callback
|
||||
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 DOMAIN
|
||||
from .coordinator import SwitcherDataUpdateCoordinator
|
||||
from .services import async_setup_services
|
||||
|
||||
PLATFORMS = [
|
||||
Platform.BUTTON,
|
||||
@@ -28,6 +30,15 @@ _LOGGER = logging.getLogger(__name__)
|
||||
type SwitcherConfigEntry = ConfigEntry[dict[str, SwitcherDataUpdateCoordinator]]
|
||||
|
||||
|
||||
CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN)
|
||||
|
||||
|
||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
"""Set up the Switcher integration."""
|
||||
async_setup_services(hass)
|
||||
return True
|
||||
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: SwitcherConfigEntry) -> bool:
|
||||
"""Set up Switcher from a config entry."""
|
||||
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
"""Services for the Switcher integration."""
|
||||
|
||||
import probatio
|
||||
|
||||
from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN, SwitchDeviceClass
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers import config_validation as cv, service
|
||||
from homeassistant.helpers.typing import VolDictType
|
||||
|
||||
from .const import (
|
||||
CONF_AUTO_OFF,
|
||||
CONF_TIMER_MINUTES,
|
||||
DOMAIN,
|
||||
SERVICE_SET_AUTO_OFF_NAME,
|
||||
SERVICE_TURN_ON_WITH_TIMER_NAME,
|
||||
)
|
||||
|
||||
SERVICE_SET_AUTO_OFF_SCHEMA: VolDictType = {
|
||||
probatio.Required(CONF_AUTO_OFF): cv.time_period_str,
|
||||
}
|
||||
SERVICE_TURN_ON_WITH_TIMER_SCHEMA: VolDictType = {
|
||||
probatio.Required(CONF_TIMER_MINUTES): probatio.All(
|
||||
cv.positive_int, probatio.Range(min=1, max=150)
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
@callback
|
||||
def async_setup_services(hass: HomeAssistant) -> None:
|
||||
"""Set up the services for the Switcher integration."""
|
||||
|
||||
service.async_register_platform_entity_service(
|
||||
hass,
|
||||
DOMAIN,
|
||||
SERVICE_SET_AUTO_OFF_NAME,
|
||||
entity_domain=SWITCH_DOMAIN,
|
||||
schema=SERVICE_SET_AUTO_OFF_SCHEMA,
|
||||
func="async_set_auto_off_service",
|
||||
entity_device_classes=(SwitchDeviceClass.SWITCH,),
|
||||
)
|
||||
|
||||
service.async_register_platform_entity_service(
|
||||
hass,
|
||||
DOMAIN,
|
||||
SERVICE_TURN_ON_WITH_TIMER_NAME,
|
||||
entity_domain=SWITCH_DOMAIN,
|
||||
schema=SERVICE_TURN_ON_WITH_TIMER_SCHEMA,
|
||||
func="async_turn_on_with_timer_service",
|
||||
entity_device_classes=(SwitchDeviceClass.SWITCH,),
|
||||
)
|
||||
@@ -10,24 +10,15 @@ from aioswitcher.device import (
|
||||
ShutterChildLock,
|
||||
SwitcherShutter,
|
||||
)
|
||||
import probatio
|
||||
|
||||
from homeassistant.components.switch import SwitchDeviceClass, SwitchEntity
|
||||
from homeassistant.const import EntityCategory
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers import config_validation as cv, entity_platform
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
from homeassistant.helpers.typing import VolDictType
|
||||
|
||||
from . import SwitcherConfigEntry
|
||||
from .const import (
|
||||
CONF_AUTO_OFF,
|
||||
CONF_TIMER_MINUTES,
|
||||
SERVICE_SET_AUTO_OFF_NAME,
|
||||
SERVICE_TURN_ON_WITH_TIMER_NAME,
|
||||
SIGNAL_DEVICE_ADD,
|
||||
)
|
||||
from .const import SIGNAL_DEVICE_ADD
|
||||
from .coordinator import SwitcherDataUpdateCoordinator
|
||||
from .entity import SwitcherEntity
|
||||
|
||||
@@ -37,16 +28,6 @@ API_CONTROL_DEVICE = "control_device"
|
||||
API_SET_AUTO_SHUTDOWN = "set_auto_shutdown"
|
||||
API_SET_CHILD_LOCK = "set_shutter_child_lock"
|
||||
|
||||
SERVICE_SET_AUTO_OFF_SCHEMA: VolDictType = {
|
||||
probatio.Required(CONF_AUTO_OFF): cv.time_period_str,
|
||||
}
|
||||
|
||||
SERVICE_TURN_ON_WITH_TIMER_SCHEMA: VolDictType = {
|
||||
probatio.Required(CONF_TIMER_MINUTES): probatio.All(
|
||||
cv.positive_int, probatio.Range(min=1, max=150)
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
@@ -54,21 +35,6 @@ async def async_setup_entry(
|
||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up Switcher switch from config entry."""
|
||||
platform = entity_platform.async_get_current_platform()
|
||||
|
||||
platform.async_register_entity_service(
|
||||
SERVICE_SET_AUTO_OFF_NAME,
|
||||
SERVICE_SET_AUTO_OFF_SCHEMA,
|
||||
"async_set_auto_off_service",
|
||||
entity_device_classes=(SwitchDeviceClass.SWITCH,),
|
||||
)
|
||||
|
||||
platform.async_register_entity_service(
|
||||
SERVICE_TURN_ON_WITH_TIMER_NAME,
|
||||
SERVICE_TURN_ON_WITH_TIMER_SCHEMA,
|
||||
"async_turn_on_with_timer_service",
|
||||
entity_device_classes=(SwitchDeviceClass.SWITCH,),
|
||||
)
|
||||
|
||||
@callback
|
||||
def async_add_switch(coordinator: SwitcherDataUpdateCoordinator) -> None:
|
||||
|
||||
Reference in New Issue
Block a user