mirror of
https://github.com/home-assistant/core.git
synced 2026-12-05 05:14:01 -04:00
Move verisure service registration to services module (#184630)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
142a9b0f6c
commit
0d91e3a25e
@@ -9,11 +9,17 @@ from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_EMAIL, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import 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.storage import STORAGE_DIR
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
|
||||
from .const import CONF_GIID, CONF_LOCK_DEFAULT_CODE, DOMAIN, LOGGER
|
||||
from .coordinator import VerisureConfigEntry, VerisureDataUpdateCoordinator
|
||||
from .services import async_setup_services
|
||||
|
||||
PLATFORMS = [
|
||||
Platform.ALARM_CONTROL_PANEL,
|
||||
@@ -25,6 +31,15 @@ PLATFORMS = [
|
||||
]
|
||||
|
||||
|
||||
CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN)
|
||||
|
||||
|
||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
"""Set up the Verisure integration."""
|
||||
async_setup_services(hass)
|
||||
return True
|
||||
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: VerisureConfigEntry) -> bool:
|
||||
"""Set up Verisure from a config entry."""
|
||||
await hass.async_add_executor_job(migrate_cookie_files, hass, entry)
|
||||
|
||||
@@ -11,13 +11,10 @@ from homeassistant.const import EVENT_HOMEASSISTANT_STOP
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import device_registry as dr
|
||||
from homeassistant.helpers.device_registry import DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import (
|
||||
AddConfigEntryEntitiesCallback,
|
||||
async_get_current_platform,
|
||||
)
|
||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
|
||||
from .const import CONF_GIID, DOMAIN, LOGGER, SERVICE_CAPTURE_SMARTCAM
|
||||
from .const import CONF_GIID, DOMAIN, LOGGER
|
||||
from .coordinator import VerisureConfigEntry, VerisureDataUpdateCoordinator
|
||||
|
||||
|
||||
@@ -29,13 +26,6 @@ async def async_setup_entry(
|
||||
"""Set up Verisure sensors based on a config entry."""
|
||||
coordinator = entry.runtime_data
|
||||
|
||||
platform = async_get_current_platform()
|
||||
platform.async_register_entity_service(
|
||||
SERVICE_CAPTURE_SMARTCAM,
|
||||
None,
|
||||
VerisureSmartcam.capture_smartcam.__name__,
|
||||
)
|
||||
|
||||
async_add_entities(
|
||||
VerisureSmartcam(coordinator, serial_number, hass.config.config_dir)
|
||||
for serial_number in coordinator.data["cameras"]
|
||||
|
||||
@@ -10,10 +10,7 @@ from homeassistant.const import ATTR_CODE
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers import device_registry as dr
|
||||
from homeassistant.helpers.device_registry import DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import (
|
||||
AddConfigEntryEntitiesCallback,
|
||||
async_get_current_platform,
|
||||
)
|
||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
|
||||
from .const import (
|
||||
@@ -22,8 +19,6 @@ from .const import (
|
||||
DEFAULT_LOCK_CODE_DIGITS,
|
||||
DOMAIN,
|
||||
LOGGER,
|
||||
SERVICE_DISABLE_AUTOLOCK,
|
||||
SERVICE_ENABLE_AUTOLOCK,
|
||||
)
|
||||
from .coordinator import VerisureConfigEntry, VerisureDataUpdateCoordinator
|
||||
|
||||
@@ -36,18 +31,6 @@ async def async_setup_entry(
|
||||
"""Set up Verisure alarm control panel from a config entry."""
|
||||
coordinator = entry.runtime_data
|
||||
|
||||
platform = async_get_current_platform()
|
||||
platform.async_register_entity_service(
|
||||
SERVICE_DISABLE_AUTOLOCK,
|
||||
None,
|
||||
VerisureDoorlock.disable_autolock.__name__,
|
||||
)
|
||||
platform.async_register_entity_service(
|
||||
SERVICE_ENABLE_AUTOLOCK,
|
||||
None,
|
||||
VerisureDoorlock.enable_autolock.__name__,
|
||||
)
|
||||
|
||||
async_add_entities(
|
||||
VerisureDoorlock(coordinator, serial_number)
|
||||
for serial_number in coordinator.data["locks"]
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
"""Services for the Verisure integration."""
|
||||
|
||||
from homeassistant.components.camera import DOMAIN as CAMERA_DOMAIN
|
||||
from homeassistant.components.lock import DOMAIN as LOCK_DOMAIN
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers import service
|
||||
|
||||
from .const import (
|
||||
DOMAIN,
|
||||
SERVICE_CAPTURE_SMARTCAM,
|
||||
SERVICE_DISABLE_AUTOLOCK,
|
||||
SERVICE_ENABLE_AUTOLOCK,
|
||||
)
|
||||
|
||||
|
||||
@callback
|
||||
def async_setup_services(hass: HomeAssistant) -> None:
|
||||
"""Set up the services for the Verisure integration."""
|
||||
|
||||
service.async_register_platform_entity_service(
|
||||
hass,
|
||||
DOMAIN,
|
||||
SERVICE_CAPTURE_SMARTCAM,
|
||||
entity_domain=CAMERA_DOMAIN,
|
||||
schema=None,
|
||||
func="capture_smartcam",
|
||||
)
|
||||
|
||||
service.async_register_platform_entity_service(
|
||||
hass,
|
||||
DOMAIN,
|
||||
SERVICE_DISABLE_AUTOLOCK,
|
||||
entity_domain=LOCK_DOMAIN,
|
||||
schema=None,
|
||||
func="disable_autolock",
|
||||
)
|
||||
|
||||
service.async_register_platform_entity_service(
|
||||
hass,
|
||||
DOMAIN,
|
||||
SERVICE_ENABLE_AUTOLOCK,
|
||||
entity_domain=LOCK_DOMAIN,
|
||||
schema=None,
|
||||
func="enable_autolock",
|
||||
)
|
||||
Reference in New Issue
Block a user