Move imports in onvif component (#27969)

This commit is contained in:
Diefferson Koderer Môro 2019-10-20 15:46:51 -03:00 committed by Martin Hjelmare
parent 6951d78874
commit 9db07b2a41

View File

@ -8,21 +8,29 @@ import asyncio
import datetime as dt import datetime as dt
import logging import logging
import os import os
import voluptuous as vol
from aiohttp.client_exceptions import ClientConnectionError, ServerDisconnectedError
from haffmpeg.camera import CameraMjpeg
from haffmpeg.tools import IMAGE_JPEG, ImageFrame
import onvif
from onvif import ONVIFCamera, exceptions
import voluptuous as vol
from zeep.exceptions import Fault
from homeassistant.components.camera import PLATFORM_SCHEMA, SUPPORT_STREAM, Camera
from homeassistant.components.camera.const import DOMAIN
from homeassistant.components.ffmpeg import CONF_EXTRA_ARGUMENTS, DATA_FFMPEG
from homeassistant.const import ( from homeassistant.const import (
CONF_NAME, ATTR_ENTITY_ID,
CONF_HOST, CONF_HOST,
CONF_USERNAME, CONF_NAME,
CONF_PASSWORD, CONF_PASSWORD,
CONF_PORT, CONF_PORT,
ATTR_ENTITY_ID, CONF_USERNAME,
) )
from homeassistant.components.camera import Camera, PLATFORM_SCHEMA, SUPPORT_STREAM from homeassistant.exceptions import PlatformNotReady
from homeassistant.components.camera.const import DOMAIN
from homeassistant.components.ffmpeg import DATA_FFMPEG, CONF_EXTRA_ARGUMENTS
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
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.service import async_extract_entity_ids from homeassistant.helpers.service import async_extract_entity_ids
import homeassistant.util.dt as dt_util import homeassistant.util.dt as dt_util
@ -122,9 +130,6 @@ class ONVIFHassCamera(Camera):
_LOGGER.debug("Importing dependencies") _LOGGER.debug("Importing dependencies")
import onvif
from onvif import ONVIFCamera
_LOGGER.debug("Setting up the ONVIF camera component") _LOGGER.debug("Setting up the ONVIF camera component")
self._username = config.get(CONF_USERNAME) self._username = config.get(CONF_USERNAME)
@ -156,10 +161,6 @@ class ONVIFHassCamera(Camera):
Initializes the camera by obtaining the input uri and connecting to Initializes the camera by obtaining the input uri and connecting to
the camera. Also retrieves the ONVIF profiles. the camera. Also retrieves the ONVIF profiles.
""" """
from aiohttp.client_exceptions import ClientConnectionError
from homeassistant.exceptions import PlatformNotReady
from zeep.exceptions import Fault
try: try:
_LOGGER.debug("Updating service addresses") _LOGGER.debug("Updating service addresses")
await self._camera.update_xaddrs() await self._camera.update_xaddrs()
@ -169,7 +170,7 @@ class ONVIFHassCamera(Camera):
self.setup_ptz() self.setup_ptz()
except ClientConnectionError as err: except ClientConnectionError as err:
_LOGGER.warning( _LOGGER.warning(
"Couldn't connect to camera '%s', but will " "retry later. Error: %s", "Couldn't connect to camera '%s', but will retry later. Error: %s",
self._name, self._name,
err, err,
) )
@ -184,8 +185,6 @@ class ONVIFHassCamera(Camera):
async def async_check_date_and_time(self): async def async_check_date_and_time(self):
"""Warns if camera and system date not synced.""" """Warns if camera and system date not synced."""
from aiohttp.client_exceptions import ServerDisconnectedError
_LOGGER.debug("Setting up the ONVIF device management service") _LOGGER.debug("Setting up the ONVIF device management service")
devicemgmt = self._camera.create_devicemgmt_service() devicemgmt = self._camera.create_devicemgmt_service()
@ -228,8 +227,6 @@ class ONVIFHassCamera(Camera):
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."""
from onvif import exceptions
_LOGGER.debug( _LOGGER.debug(
"Connecting with ONVIF Camera: %s on port %s", self._host, self._port "Connecting with ONVIF Camera: %s on port %s", self._host, self._port
) )
@ -289,8 +286,6 @@ class ONVIFHassCamera(Camera):
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."""
from onvif import exceptions
if self._ptz_service is None: if self._ptz_service is None:
_LOGGER.warning("PTZ actions are not supported on camera '%s'", self._name) _LOGGER.warning("PTZ actions are not supported on camera '%s'", self._name)
return return
@ -332,7 +327,6 @@ class ONVIFHassCamera(Camera):
async def async_camera_image(self): async def async_camera_image(self):
"""Return a still image response from the camera.""" """Return a still image response from the camera."""
from haffmpeg.tools import ImageFrame, IMAGE_JPEG
_LOGGER.debug("Retrieving image from camera '%s'", self._name) _LOGGER.debug("Retrieving image from camera '%s'", self._name)
@ -347,8 +341,6 @@ class ONVIFHassCamera(Camera):
async def handle_async_mjpeg_stream(self, request): async def handle_async_mjpeg_stream(self, request):
"""Generate an HTTP MJPEG stream from the camera.""" """Generate an HTTP MJPEG stream from the camera."""
from haffmpeg.camera import CameraMjpeg
_LOGGER.debug("Handling mjpeg stream from camera '%s'", self._name) _LOGGER.debug("Handling mjpeg stream from camera '%s'", self._name)
ffmpeg_manager = self.hass.data[DATA_FFMPEG] ffmpeg_manager = self.hass.data[DATA_FFMPEG]