mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 20:27:08 +00:00
Move imports to top for uvc (#29072)
* Move imports to top for uvc * Fixed linting error * Renamed parameter in constructor to avoid redefining import
This commit is contained in:
parent
9a388e2dd2
commit
825ac36ee7
@ -3,12 +3,13 @@ import logging
|
|||||||
import socket
|
import socket
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
from uvcclient import camera as uvc_camera, nvr
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
|
from homeassistant.components.camera import PLATFORM_SCHEMA, Camera
|
||||||
from homeassistant.const import CONF_PORT, CONF_SSL
|
from homeassistant.const import CONF_PORT, CONF_SSL
|
||||||
from homeassistant.components.camera import Camera, PLATFORM_SCHEMA
|
|
||||||
import homeassistant.helpers.config_validation as cv
|
|
||||||
from homeassistant.exceptions import PlatformNotReady
|
from homeassistant.exceptions import PlatformNotReady
|
||||||
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -39,8 +40,6 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||||||
port = config[CONF_PORT]
|
port = config[CONF_PORT]
|
||||||
ssl = config[CONF_SSL]
|
ssl = config[CONF_SSL]
|
||||||
|
|
||||||
from uvcclient import nvr
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Exceptions may be raised in all method calls to the nvr library.
|
# Exceptions may be raised in all method calls to the nvr library.
|
||||||
nvrconn = nvr.UVCRemote(addr, port, key, ssl=ssl)
|
nvrconn = nvr.UVCRemote(addr, port, key, ssl=ssl)
|
||||||
@ -76,10 +75,10 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||||||
class UnifiVideoCamera(Camera):
|
class UnifiVideoCamera(Camera):
|
||||||
"""A Ubiquiti Unifi Video Camera."""
|
"""A Ubiquiti Unifi Video Camera."""
|
||||||
|
|
||||||
def __init__(self, nvr, uuid, name, password):
|
def __init__(self, camera, uuid, name, password):
|
||||||
"""Initialize an Unifi camera."""
|
"""Initialize an Unifi camera."""
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self._nvr = nvr
|
self._nvr = camera
|
||||||
self._uuid = uuid
|
self._uuid = uuid
|
||||||
self._name = name
|
self._name = name
|
||||||
self._password = password
|
self._password = password
|
||||||
@ -118,7 +117,6 @@ class UnifiVideoCamera(Camera):
|
|||||||
|
|
||||||
def _login(self):
|
def _login(self):
|
||||||
"""Login to the camera."""
|
"""Login to the camera."""
|
||||||
from uvcclient import camera as uvc_camera
|
|
||||||
|
|
||||||
caminfo = self._nvr.get_camera(self._uuid)
|
caminfo = self._nvr.get_camera(self._uuid)
|
||||||
if self._connect_addr:
|
if self._connect_addr:
|
||||||
@ -160,7 +158,6 @@ class UnifiVideoCamera(Camera):
|
|||||||
|
|
||||||
def camera_image(self):
|
def camera_image(self):
|
||||||
"""Return the image of this camera."""
|
"""Return the image of this camera."""
|
||||||
from uvcclient import camera as uvc_camera
|
|
||||||
|
|
||||||
if not self._camera:
|
if not self._camera:
|
||||||
if not self._login():
|
if not self._login():
|
||||||
@ -182,7 +179,6 @@ class UnifiVideoCamera(Camera):
|
|||||||
|
|
||||||
def set_motion_detection(self, mode):
|
def set_motion_detection(self, mode):
|
||||||
"""Set motion detection on or off."""
|
"""Set motion detection on or off."""
|
||||||
from uvcclient.nvr import NvrError
|
|
||||||
|
|
||||||
if mode is True:
|
if mode is True:
|
||||||
set_mode = "motion"
|
set_mode = "motion"
|
||||||
@ -192,7 +188,7 @@ class UnifiVideoCamera(Camera):
|
|||||||
try:
|
try:
|
||||||
self._nvr.set_recordmode(self._uuid, set_mode)
|
self._nvr.set_recordmode(self._uuid, set_mode)
|
||||||
self._motion_status = mode
|
self._motion_status = mode
|
||||||
except NvrError as err:
|
except nvr.NvrError as err:
|
||||||
_LOGGER.error("Unable to set recordmode to %s", set_mode)
|
_LOGGER.error("Unable to set recordmode to %s", set_mode)
|
||||||
_LOGGER.debug(err)
|
_LOGGER.debug(err)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user