mirror of
https://github.com/home-assistant/core.git
synced 2026-12-06 05:38:06 -04:00
Move onvif service registration to services module (#184468)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
994193e8be
commit
13668d4395
@@ -19,20 +19,32 @@ from homeassistant.const import (
|
||||
)
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
from homeassistant.helpers import config_validation as cv, entity_registry as er
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
|
||||
from .const import (
|
||||
CONF_ENABLE_WEBHOOKS,
|
||||
CONF_SNAPSHOT_AUTH,
|
||||
DEFAULT_ARGUMENTS,
|
||||
DEFAULT_ENABLE_WEBHOOKS,
|
||||
DOMAIN,
|
||||
SNAPSHOT_TIMEOUT,
|
||||
)
|
||||
from .device import ONVIFConfigEntry, ONVIFDevice
|
||||
from .services import async_setup_services
|
||||
|
||||
LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN)
|
||||
|
||||
|
||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
"""Set up the ONVIF integration."""
|
||||
async_setup_services(hass)
|
||||
return True
|
||||
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ONVIFConfigEntry) -> bool:
|
||||
"""Set up ONVIF from a config entry."""
|
||||
if not entry.options:
|
||||
|
||||
@@ -5,7 +5,6 @@ from typing import override
|
||||
|
||||
from haffmpeg.camera import CameraMjpeg
|
||||
from onvif.exceptions import ONVIFError
|
||||
import probatio
|
||||
from yarl import URL
|
||||
|
||||
from homeassistant.components import ffmpeg
|
||||
@@ -18,34 +17,10 @@ from homeassistant.components.stream import (
|
||||
)
|
||||
from homeassistant.const import HTTP_BASIC_AUTHENTICATION
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import config_validation as cv, entity_platform
|
||||
from homeassistant.helpers.aiohttp_client import async_aiohttp_proxy_stream
|
||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
|
||||
from .const import (
|
||||
ABSOLUTE_MOVE,
|
||||
ATTR_CONTINUOUS_DURATION,
|
||||
ATTR_DISTANCE,
|
||||
ATTR_MOVE_MODE,
|
||||
ATTR_PAN,
|
||||
ATTR_PRESET,
|
||||
ATTR_SPEED,
|
||||
ATTR_TILT,
|
||||
ATTR_ZOOM,
|
||||
CONF_SNAPSHOT_AUTH,
|
||||
CONTINUOUS_MOVE,
|
||||
DIR_DOWN,
|
||||
DIR_LEFT,
|
||||
DIR_RIGHT,
|
||||
DIR_UP,
|
||||
GOTOPRESET_MOVE,
|
||||
LOGGER,
|
||||
RELATIVE_MOVE,
|
||||
SERVICE_PTZ,
|
||||
STOP_MOVE,
|
||||
ZOOM_IN,
|
||||
ZOOM_OUT,
|
||||
)
|
||||
from .const import CONF_SNAPSHOT_AUTH, LOGGER
|
||||
from .device import ONVIFConfigEntry, ONVIFDevice
|
||||
from .entity import ONVIFBaseEntity
|
||||
from .models import Profile
|
||||
@@ -57,32 +32,6 @@ async def async_setup_entry(
|
||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the ONVIF camera video stream."""
|
||||
platform = entity_platform.async_get_current_platform()
|
||||
|
||||
# Create PTZ service
|
||||
platform.async_register_entity_service(
|
||||
SERVICE_PTZ,
|
||||
{
|
||||
probatio.Optional(ATTR_PAN): probatio.In([DIR_LEFT, DIR_RIGHT]),
|
||||
probatio.Optional(ATTR_TILT): probatio.In([DIR_UP, DIR_DOWN]),
|
||||
probatio.Optional(ATTR_ZOOM): probatio.In([ZOOM_OUT, ZOOM_IN]),
|
||||
probatio.Optional(ATTR_DISTANCE, default=0.1): cv.small_float,
|
||||
probatio.Optional(ATTR_SPEED): cv.small_float,
|
||||
probatio.Optional(ATTR_MOVE_MODE, default=RELATIVE_MOVE): probatio.In(
|
||||
[
|
||||
CONTINUOUS_MOVE,
|
||||
RELATIVE_MOVE,
|
||||
ABSOLUTE_MOVE,
|
||||
GOTOPRESET_MOVE,
|
||||
STOP_MOVE,
|
||||
]
|
||||
),
|
||||
probatio.Optional(ATTR_CONTINUOUS_DURATION, default=0.5): cv.small_float,
|
||||
probatio.Optional(ATTR_PRESET, default="0"): cv.string,
|
||||
},
|
||||
"async_perform_ptz",
|
||||
)
|
||||
|
||||
device = config_entry.runtime_data
|
||||
async_add_entities(
|
||||
[ONVIFCameraEntity(device, profile) for profile in device.profiles]
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
"""Services for the ONVIF integration."""
|
||||
|
||||
import probatio
|
||||
|
||||
from homeassistant.components.camera import DOMAIN as CAMERA_DOMAIN
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers import config_validation as cv, service
|
||||
|
||||
from .const import (
|
||||
ABSOLUTE_MOVE,
|
||||
ATTR_CONTINUOUS_DURATION,
|
||||
ATTR_DISTANCE,
|
||||
ATTR_MOVE_MODE,
|
||||
ATTR_PAN,
|
||||
ATTR_PRESET,
|
||||
ATTR_SPEED,
|
||||
ATTR_TILT,
|
||||
ATTR_ZOOM,
|
||||
CONTINUOUS_MOVE,
|
||||
DIR_DOWN,
|
||||
DIR_LEFT,
|
||||
DIR_RIGHT,
|
||||
DIR_UP,
|
||||
DOMAIN,
|
||||
GOTOPRESET_MOVE,
|
||||
RELATIVE_MOVE,
|
||||
SERVICE_PTZ,
|
||||
STOP_MOVE,
|
||||
ZOOM_IN,
|
||||
ZOOM_OUT,
|
||||
)
|
||||
|
||||
|
||||
@callback
|
||||
def async_setup_services(hass: HomeAssistant) -> None:
|
||||
"""Set up the services for the ONVIF integration."""
|
||||
|
||||
service.async_register_platform_entity_service(
|
||||
hass,
|
||||
DOMAIN,
|
||||
SERVICE_PTZ,
|
||||
entity_domain=CAMERA_DOMAIN,
|
||||
schema={
|
||||
probatio.Optional(ATTR_PAN): probatio.In([DIR_LEFT, DIR_RIGHT]),
|
||||
probatio.Optional(ATTR_TILT): probatio.In([DIR_UP, DIR_DOWN]),
|
||||
probatio.Optional(ATTR_ZOOM): probatio.In([ZOOM_OUT, ZOOM_IN]),
|
||||
probatio.Optional(ATTR_DISTANCE, default=0.1): cv.small_float,
|
||||
probatio.Optional(ATTR_SPEED): cv.small_float,
|
||||
probatio.Optional(ATTR_MOVE_MODE, default=RELATIVE_MOVE): probatio.In(
|
||||
[
|
||||
CONTINUOUS_MOVE,
|
||||
RELATIVE_MOVE,
|
||||
ABSOLUTE_MOVE,
|
||||
GOTOPRESET_MOVE,
|
||||
STOP_MOVE,
|
||||
]
|
||||
),
|
||||
probatio.Optional(ATTR_CONTINUOUS_DURATION, default=0.5): cv.small_float,
|
||||
probatio.Optional(ATTR_PRESET, default="0"): cv.string,
|
||||
},
|
||||
func="async_perform_ptz",
|
||||
)
|
||||
Reference in New Issue
Block a user