mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +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 requests
|
||||
from uvcclient import camera as uvc_camera, nvr
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.camera import PLATFORM_SCHEMA, Camera
|
||||
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
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
@ -39,8 +40,6 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
port = config[CONF_PORT]
|
||||
ssl = config[CONF_SSL]
|
||||
|
||||
from uvcclient import nvr
|
||||
|
||||
try:
|
||||
# Exceptions may be raised in all method calls to the nvr library.
|
||||
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):
|
||||
"""A Ubiquiti Unifi Video Camera."""
|
||||
|
||||
def __init__(self, nvr, uuid, name, password):
|
||||
def __init__(self, camera, uuid, name, password):
|
||||
"""Initialize an Unifi camera."""
|
||||
super().__init__()
|
||||
self._nvr = nvr
|
||||
self._nvr = camera
|
||||
self._uuid = uuid
|
||||
self._name = name
|
||||
self._password = password
|
||||
@ -118,7 +117,6 @@ class UnifiVideoCamera(Camera):
|
||||
|
||||
def _login(self):
|
||||
"""Login to the camera."""
|
||||
from uvcclient import camera as uvc_camera
|
||||
|
||||
caminfo = self._nvr.get_camera(self._uuid)
|
||||
if self._connect_addr:
|
||||
@ -160,7 +158,6 @@ class UnifiVideoCamera(Camera):
|
||||
|
||||
def camera_image(self):
|
||||
"""Return the image of this camera."""
|
||||
from uvcclient import camera as uvc_camera
|
||||
|
||||
if not self._camera:
|
||||
if not self._login():
|
||||
@ -182,7 +179,6 @@ class UnifiVideoCamera(Camera):
|
||||
|
||||
def set_motion_detection(self, mode):
|
||||
"""Set motion detection on or off."""
|
||||
from uvcclient.nvr import NvrError
|
||||
|
||||
if mode is True:
|
||||
set_mode = "motion"
|
||||
@ -192,7 +188,7 @@ class UnifiVideoCamera(Camera):
|
||||
try:
|
||||
self._nvr.set_recordmode(self._uuid, set_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.debug(err)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user