diff --git a/homeassistant/components/agent_dvr/__init__.py b/homeassistant/components/agent_dvr/__init__.py index d504568869c..6452e1a3bf2 100644 --- a/homeassistant/components/agent_dvr/__init__.py +++ b/homeassistant/components/agent_dvr/__init__.py @@ -7,10 +7,12 @@ from homeassistant.config_entries import ConfigEntry from homeassistant.const import Platform from homeassistant.core import 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.aiohttp_client import async_get_clientsession +from homeassistant.helpers.typing import ConfigType from .const import DOMAIN, SERVER_URL +from .services import async_setup_services ATTRIBUTION = "ispyconnect.com" DEFAULT_BRAND = "Agent DVR by ispyconnect.com" @@ -19,6 +21,14 @@ PLATFORMS = [Platform.ALARM_CONTROL_PANEL, Platform.CAMERA] AgentDVRConfigEntry = ConfigEntry[Agent] +CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN) + + +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: AgentDVRConfigEntry diff --git a/homeassistant/components/agent_dvr/camera.py b/homeassistant/components/agent_dvr/camera.py index c0076024fe4..d39224f28f8 100644 --- a/homeassistant/components/agent_dvr/camera.py +++ b/homeassistant/components/agent_dvr/camera.py @@ -9,10 +9,7 @@ from homeassistant.components.camera import CameraEntityFeature from homeassistant.components.mjpeg import MjpegCamera, filter_urllib3_logging from homeassistant.core import HomeAssistant 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 . import AgentDVRConfigEntry from .const import ATTRIBUTION, CAMERA_SCAN_INTERVAL_SECS, DOMAIN @@ -21,20 +18,6 @@ SCAN_INTERVAL = timedelta(seconds=CAMERA_SCAN_INTERVAL_SECS) _LOGGER = logging.getLogger(__name__) -_DEV_EN_ALT = "enable_alerts" -_DEV_DS_ALT = "disable_alerts" -_DEV_EN_REC = "start_recording" -_DEV_DS_REC = "stop_recording" -_DEV_SNAP = "snapshot" - -CAMERA_SERVICES = { - _DEV_EN_ALT: "async_enable_alerts", - _DEV_DS_ALT: "async_disable_alerts", - _DEV_EN_REC: "async_start_recording", - _DEV_DS_REC: "async_stop_recording", - _DEV_SNAP: "async_snapshot", -} - async def async_setup_entry( hass: HomeAssistant, @@ -57,10 +40,6 @@ async def async_setup_entry( async_add_entities(cameras) - platform = async_get_current_platform() - for service, method in CAMERA_SERVICES.items(): - platform.async_register_entity_service(service, None, method) - class AgentCamera(MjpegCamera): """Representation of an Agent Device Stream.""" diff --git a/homeassistant/components/agent_dvr/services.py b/homeassistant/components/agent_dvr/services.py new file mode 100644 index 00000000000..d80d94427fb --- /dev/null +++ b/homeassistant/components/agent_dvr/services.py @@ -0,0 +1,38 @@ +"""Services for Agent DVR.""" + +from __future__ import annotations + +from homeassistant.components.camera import DOMAIN as CAMERA_DOMAIN +from homeassistant.core import HomeAssistant, callback +from homeassistant.helpers import service + +from .const import DOMAIN + +_DEV_EN_ALT = "enable_alerts" +_DEV_DS_ALT = "disable_alerts" +_DEV_EN_REC = "start_recording" +_DEV_DS_REC = "stop_recording" +_DEV_SNAP = "snapshot" + +CAMERA_SERVICES = { + _DEV_EN_ALT: "async_enable_alerts", + _DEV_DS_ALT: "async_disable_alerts", + _DEV_EN_REC: "async_start_recording", + _DEV_DS_REC: "async_stop_recording", + _DEV_SNAP: "async_snapshot", +} + + +@callback +def async_setup_services(hass: HomeAssistant) -> None: + """Home Assistant services.""" + + for service_name, method in CAMERA_SERVICES.items(): + service.async_register_platform_entity_service( + hass, + DOMAIN, + service_name, + entity_domain=CAMERA_DOMAIN, + schema=None, + func=method, + )