mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 04:07:08 +00:00
Fix onvif camera setup error (#24585)
* fix: onvif setup error * refactor: onvif camera init process * onvif/camera: review fixes * onvif/camera: review fixes * onvif/camera: fix pydoc * onvif: remove unrelated async-await * Onvif review fix * onvif/camera: remove log
This commit is contained in:
parent
d9ef92f6d2
commit
baa30aec9d
@ -24,6 +24,7 @@ from homeassistant.components.ffmpeg import DATA_FFMPEG, CONF_EXTRA_ARGUMENTS
|
|||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers.aiohttp_client import async_aiohttp_proxy_stream
|
from homeassistant.helpers.aiohttp_client import async_aiohttp_proxy_stream
|
||||||
from homeassistant.helpers.service import extract_entity_ids
|
from homeassistant.helpers.service import extract_entity_ids
|
||||||
|
import homeassistant.util.dt as dt_util
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -158,19 +159,38 @@ class ONVIFHassCamera(Camera):
|
|||||||
from aiohttp.client_exceptions import ClientConnectorError
|
from aiohttp.client_exceptions import ClientConnectorError
|
||||||
from homeassistant.exceptions import PlatformNotReady
|
from homeassistant.exceptions import PlatformNotReady
|
||||||
from zeep.exceptions import Fault
|
from zeep.exceptions import Fault
|
||||||
import homeassistant.util.dt as dt_util
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
_LOGGER.debug("Updating service addresses")
|
_LOGGER.debug("Updating service addresses")
|
||||||
|
|
||||||
await self._camera.update_xaddrs()
|
await self._camera.update_xaddrs()
|
||||||
|
|
||||||
_LOGGER.debug("Setting up the ONVIF device management service")
|
await self.async_check_date_and_time()
|
||||||
|
await self.async_obtain_input_uri()
|
||||||
|
self.setup_ptz()
|
||||||
|
except ClientConnectorError as err:
|
||||||
|
_LOGGER.warning(
|
||||||
|
"Couldn't connect to camera '%s', but will " "retry later. Error: %s",
|
||||||
|
self._name,
|
||||||
|
err,
|
||||||
|
)
|
||||||
|
raise PlatformNotReady
|
||||||
|
except Fault as err:
|
||||||
|
_LOGGER.error(
|
||||||
|
"Couldn't connect to camera '%s', please verify "
|
||||||
|
"that the credentials are correct. Error: %s",
|
||||||
|
self._name,
|
||||||
|
err,
|
||||||
|
)
|
||||||
|
|
||||||
|
async def async_check_date_and_time(self):
|
||||||
|
"""Warns if camera and system date not synced."""
|
||||||
|
from aiohttp.client_exceptions import ServerDisconnectedError
|
||||||
|
|
||||||
|
_LOGGER.debug("Setting up the ONVIF device management service")
|
||||||
devicemgmt = self._camera.create_devicemgmt_service()
|
devicemgmt = self._camera.create_devicemgmt_service()
|
||||||
|
|
||||||
_LOGGER.debug("Retrieving current camera date/time")
|
_LOGGER.debug("Retrieving current camera date/time")
|
||||||
|
try:
|
||||||
system_date = dt_util.utcnow()
|
system_date = dt_util.utcnow()
|
||||||
device_time = await devicemgmt.GetSystemDateAndTime()
|
device_time = await devicemgmt.GetSystemDateAndTime()
|
||||||
if device_time:
|
if device_time:
|
||||||
@ -201,33 +221,10 @@ class ONVIFHassCamera(Camera):
|
|||||||
cam_date,
|
cam_date,
|
||||||
system_date,
|
system_date,
|
||||||
)
|
)
|
||||||
|
except ServerDisconnectedError as err:
|
||||||
_LOGGER.debug("Obtaining input uri")
|
|
||||||
|
|
||||||
await self.async_obtain_input_uri()
|
|
||||||
|
|
||||||
_LOGGER.debug("Setting up the ONVIF PTZ service")
|
|
||||||
|
|
||||||
if self._camera.get_service("ptz", create=False) is None:
|
|
||||||
_LOGGER.warning("PTZ is not available on this camera")
|
|
||||||
else:
|
|
||||||
self._ptz_service = self._camera.create_ptz_service()
|
|
||||||
_LOGGER.debug("Completed set up of the ONVIF camera component")
|
|
||||||
except ClientConnectorError as err:
|
|
||||||
_LOGGER.warning(
|
_LOGGER.warning(
|
||||||
"Couldn't connect to camera '%s', but will " "retry later. Error: %s",
|
"Couldn't get camera '%s' date/time. Error: %s", self._name, err
|
||||||
self._name,
|
|
||||||
err,
|
|
||||||
)
|
)
|
||||||
raise PlatformNotReady
|
|
||||||
except Fault as err:
|
|
||||||
_LOGGER.error(
|
|
||||||
"Couldn't connect to camera '%s', please verify "
|
|
||||||
"that the credentials are correct. Error: %s",
|
|
||||||
self._name,
|
|
||||||
err,
|
|
||||||
)
|
|
||||||
return
|
|
||||||
|
|
||||||
async def async_obtain_input_uri(self):
|
async def async_obtain_input_uri(self):
|
||||||
"""Set the input uri for the camera."""
|
"""Set the input uri for the camera."""
|
||||||
@ -280,7 +277,15 @@ class ONVIFHassCamera(Camera):
|
|||||||
)
|
)
|
||||||
except exceptions.ONVIFError as err:
|
except exceptions.ONVIFError as err:
|
||||||
_LOGGER.error("Couldn't setup camera '%s'. Error: %s", self._name, err)
|
_LOGGER.error("Couldn't setup camera '%s'. Error: %s", self._name, err)
|
||||||
return
|
|
||||||
|
def setup_ptz(self):
|
||||||
|
"""Set up PTZ if available."""
|
||||||
|
_LOGGER.debug("Setting up the ONVIF PTZ service")
|
||||||
|
if self._camera.get_service("ptz", create=False) is None:
|
||||||
|
_LOGGER.warning("PTZ is not available on this camera")
|
||||||
|
else:
|
||||||
|
self._ptz_service = self._camera.create_ptz_service()
|
||||||
|
_LOGGER.debug("Completed set up of the ONVIF camera component")
|
||||||
|
|
||||||
async def async_perform_ptz(self, pan, tilt, zoom):
|
async def async_perform_ptz(self, pan, tilt, zoom):
|
||||||
"""Perform a PTZ action on the camera."""
|
"""Perform a PTZ action on the camera."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user