Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions homeassistant/components/onvif/config_flow.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Config flow for ONVIF."""
import asyncio
from pprint import pformat
from typing import List
from urllib.parse import urlparse
Expand Down Expand Up @@ -191,13 +192,12 @@ async def async_step_profiles(self, user_input=None):
self.onvif_config[CONF_USERNAME],
self.onvif_config[CONF_PASSWORD],
)

await device.update_xaddrs()

try:
# Get the MAC address to use as the unique ID for the config flow
if not self.device_id:
devicemgmt = device.create_devicemgmt_service()
await asyncio.sleep(0.1)
network_interfaces = await devicemgmt.GetNetworkInterfaces()
for interface in network_interfaces:
if interface.Enabled:
Expand All @@ -217,6 +217,7 @@ async def async_step_profiles(self, user_input=None):

# Verify there is an H264 profile
media_service = device.create_media_service()
await asyncio.sleep(0.1)
profiles = await media_service.GetProfiles()
h264 = any(
profile.VideoEncoderConfiguration.Encoding == "H264"
Expand Down
24 changes: 19 additions & 5 deletions homeassistant/components/onvif/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
import os
from typing import List

from aiohttp.client_exceptions import ClientConnectionError, ServerDisconnectedError
from aiohttp.client_exceptions import (
ClientConnectionError,
ClientPayloadError,
ServerDisconnectedError,
)
import onvif
from onvif import ONVIFCamera
from onvif.exceptions import ONVIFError
Expand Down Expand Up @@ -134,6 +138,7 @@ async def async_check_date_and_time(self) -> None:
LOGGER.debug("Setting up the ONVIF device management service")
devicemgmt = self.device.create_devicemgmt_service()

await asyncio.sleep(0.1)
LOGGER.debug("Retrieving current device date/time")
try:
system_date = dt_util.utcnow()
Expand Down Expand Up @@ -197,6 +202,7 @@ async def async_check_date_and_time(self) -> None:
async def async_get_device_info(self) -> DeviceInfo:
"""Obtain information about this device."""
devicemgmt = self.device.create_devicemgmt_service()
await asyncio.sleep(0.1)
device_info = await devicemgmt.GetDeviceInformation()
return DeviceInfo(
device_info.Manufacturer,
Expand All @@ -210,6 +216,7 @@ async def async_get_capabilities(self):
snapshot = False
try:
media_service = self.device.create_media_service()
await asyncio.sleep(0.1)
media_capabilities = await media_service.GetServiceCapabilities()
snapshot = media_capabilities.SnapshotUri
except (ONVIFError, Fault):
Expand All @@ -218,6 +225,7 @@ async def async_get_capabilities(self):
pullpoint = False
try:
event_service = self.device.create_events_service()
await asyncio.sleep(0.1)
event_capabilities = await event_service.GetServiceCapabilities()
pullpoint = event_capabilities.WSPullPointSupport
except (ONVIFError, Fault):
Expand All @@ -235,6 +243,7 @@ async def async_get_capabilities(self):
async def async_get_profiles(self) -> List[Profile]:
"""Obtain media profiles for this device."""
media_service = self.device.create_media_service()
await asyncio.sleep(0.1)
result = await media_service.GetProfiles()
profiles = []
for key, onvif_profile in enumerate(result):
Expand Down Expand Up @@ -266,10 +275,15 @@ async def async_get_profiles(self) -> List[Profile]:
is not None,
)

ptz_service = self.device.get_service("ptz")
presets = await ptz_service.GetPresets(profile.token)
profile.ptz.presets = [preset.token for preset in presets]

try:
ptz_service = self.device.get_service("ptz")
await asyncio.sleep(0.1)
presets = await ptz_service.GetPresets(profile.token)
profile.ptz.presets = [preset.token for preset in presets]
except ClientPayloadError as err:
LOGGER.warning(
"Couldn't get PTZ presets for: %s Error: %s", self.name, err,
)
profiles.append(profile)

return profiles
Expand Down