ONVIF Event Implementation (#35406)
Initial implementation of ONVIF event sensors
This commit is contained in:
1 parent
9eb1505aa1
commit
132bb4e890
12 files changed
+762
-20
No files matched your search
@@ -11,6 +11,7 @@ from onvif.exceptions import ONVIFError
|
||||
from zeep.asyncio import AsyncTransport
|
||||
from zeep.exceptions import Fault
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
CONF_HOST,
|
||||
CONF_NAME,
|
||||
@@ -18,6 +19,7 @@ from homeassistant.const import (
|
||||
CONF_PORT,
|
||||
CONF_USERNAME,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
import homeassistant.util.dt as dt_util
|
||||
|
||||
@@ -31,24 +33,26 @@ from .const import (
|
||||
TILT_FACTOR,
|
||||
ZOOM_FACTOR,
|
||||
)
|
||||
from .event import EventManager
|
||||
from .models import PTZ, Capabilities, DeviceInfo, Profile, Resolution, Video
|
||||
|
||||
|
||||
class ONVIFDevice:
|
||||
"""Manages an ONVIF device."""
|
||||
|
||||
def __init__(self, hass, config_entry=None):
|
||||
def __init__(self, hass: HomeAssistant, config_entry: ConfigEntry = None):
|
||||
"""Initialize the device."""
|
||||
self.hass = hass
|
||||
self.config_entry = config_entry
|
||||
self.available = True
|
||||
self.hass: HomeAssistant = hass
|
||||
self.config_entry: ConfigEntry = config_entry
|
||||
self.available: bool = True
|
||||
|
||||
self.device = None
|
||||
self.device: ONVIFCamera = None
|
||||
self.events: EventManager = None
|
||||
|
||||
self.info = DeviceInfo()
|
||||
self.capabilities = Capabilities()
|
||||
self.profiles = []
|
||||
self.max_resolution = 0
|
||||
self.info: DeviceInfo = DeviceInfo()
|
||||
self.capabilities: Capabilities = Capabilities()
|
||||
self.profiles: List[Profile] = []
|
||||
self.max_resolution: int = 0
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
@@ -96,6 +100,11 @@ class ONVIFDevice:
|
||||
if self.capabilities.ptz:
|
||||
self.device.create_ptz_service()
|
||||
|
||||
if self.capabilities.events:
|
||||
self.events = EventManager(
|
||||
self.hass, self.device, self.config_entry.unique_id
|
||||
)
|
||||
|
||||
# Determine max resolution from profiles
|
||||
self.max_resolution = max(
|
||||
profile.video.resolution.width
|
||||
@@ -199,14 +208,18 @@ class ONVIFDevice:
|
||||
async def async_get_capabilities(self):
|
||||
"""Obtain information about the available services on the device."""
|
||||
media_service = self.device.create_media_service()
|
||||
capabilities = await media_service.GetServiceCapabilities()
|
||||
media_capabilities = await media_service.GetServiceCapabilities()
|
||||
event_service = self.device.create_events_service()
|
||||
event_capabilities = await event_service.GetServiceCapabilities()
|
||||
ptz = False
|
||||
try:
|
||||
self.device.get_definition("ptz")
|
||||
ptz = True
|
||||
except ONVIFError:
|
||||
pass
|
||||
return Capabilities(capabilities.SnapshotUri, ptz)
|
||||
return Capabilities(
|
||||
media_capabilities.SnapshotUri, event_capabilities.WSPullPointSupport, ptz
|
||||
)
|
||||
|
||||
async def async_get_profiles(self) -> List[Profile]:
|
||||
"""Obtain media profiles for this device."""
|
||||
|
||||
Reference in new issue
Block a user