mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Merge pull request #1257 from kk7ds/handle-uvc-errors-better
Misc UVC improvements
This commit is contained in:
commit
64430f26f3
@ -14,7 +14,7 @@ import requests
|
|||||||
from homeassistant.helpers import validate_config
|
from homeassistant.helpers import validate_config
|
||||||
from homeassistant.components.camera import DOMAIN, Camera
|
from homeassistant.components.camera import DOMAIN, Camera
|
||||||
|
|
||||||
REQUIREMENTS = ['uvcclient==0.5']
|
REQUIREMENTS = ['uvcclient==0.6']
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -58,6 +58,8 @@ class UnifiVideoCamera(Camera):
|
|||||||
self._uuid = uuid
|
self._uuid = uuid
|
||||||
self._name = name
|
self._name = name
|
||||||
self.is_streaming = False
|
self.is_streaming = False
|
||||||
|
self._connect_addr = None
|
||||||
|
self._camera = None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
@ -68,24 +70,64 @@ class UnifiVideoCamera(Camera):
|
|||||||
caminfo = self._nvr.get_camera(self._uuid)
|
caminfo = self._nvr.get_camera(self._uuid)
|
||||||
return caminfo['recordingSettings']['fullTimeRecordEnabled']
|
return caminfo['recordingSettings']['fullTimeRecordEnabled']
|
||||||
|
|
||||||
def camera_image(self):
|
@property
|
||||||
from uvcclient import camera as uvc_camera
|
def brand(self):
|
||||||
|
return 'Ubiquiti'
|
||||||
|
|
||||||
|
@property
|
||||||
|
def model(self):
|
||||||
caminfo = self._nvr.get_camera(self._uuid)
|
caminfo = self._nvr.get_camera(self._uuid)
|
||||||
|
return caminfo['model']
|
||||||
|
|
||||||
|
def _login(self):
|
||||||
|
from uvcclient import camera as uvc_camera
|
||||||
|
caminfo = self._nvr.get_camera(self._uuid)
|
||||||
|
if self._connect_addr:
|
||||||
|
addrs = [self._connect_addr]
|
||||||
|
else:
|
||||||
|
addrs = [caminfo['host'], caminfo['internalHost']]
|
||||||
|
|
||||||
camera = None
|
camera = None
|
||||||
for addr in [caminfo['host'], caminfo['internalHost']]:
|
for addr in addrs:
|
||||||
try:
|
try:
|
||||||
camera = uvc_camera.UVCCameraClient(addr,
|
camera = uvc_camera.UVCCameraClient(addr,
|
||||||
caminfo['username'],
|
caminfo['username'],
|
||||||
'ubnt')
|
'ubnt')
|
||||||
|
camera.login()
|
||||||
_LOGGER.debug('Logged into UVC camera %(name)s via %(addr)s',
|
_LOGGER.debug('Logged into UVC camera %(name)s via %(addr)s',
|
||||||
dict(name=self._name, addr=addr))
|
dict(name=self._name, addr=addr))
|
||||||
|
self._connect_addr = addr
|
||||||
except socket.error:
|
except socket.error:
|
||||||
pass
|
pass
|
||||||
|
except uvc_camera.CameraConnectError:
|
||||||
|
pass
|
||||||
|
except uvc_camera.CameraAuthError:
|
||||||
|
pass
|
||||||
if not camera:
|
if not camera:
|
||||||
_LOGGER.error('Unable to login to camera')
|
_LOGGER.error('Unable to login to camera')
|
||||||
return None
|
return None
|
||||||
|
|
||||||
camera.login()
|
self._camera = camera
|
||||||
return camera.get_snapshot()
|
return True
|
||||||
|
|
||||||
|
def camera_image(self):
|
||||||
|
from uvcclient import camera as uvc_camera
|
||||||
|
if not self._camera:
|
||||||
|
if not self._login():
|
||||||
|
return
|
||||||
|
|
||||||
|
def _get_image(retry=True):
|
||||||
|
try:
|
||||||
|
return self._camera.get_snapshot()
|
||||||
|
except uvc_camera.CameraConnectError:
|
||||||
|
_LOGGER.error('Unable to contact camera')
|
||||||
|
except uvc_camera.CameraAuthError:
|
||||||
|
if retry:
|
||||||
|
self._login()
|
||||||
|
return _get_image(retry=False)
|
||||||
|
else:
|
||||||
|
_LOGGER.error('Unable to log into camera, unable '
|
||||||
|
'to get snapshot')
|
||||||
|
raise
|
||||||
|
|
||||||
|
return _get_image()
|
||||||
|
@ -249,7 +249,7 @@ tellive-py==0.5.2
|
|||||||
transmissionrpc==0.11
|
transmissionrpc==0.11
|
||||||
|
|
||||||
# homeassistant.components.camera.uvc
|
# homeassistant.components.camera.uvc
|
||||||
uvcclient==0.5
|
uvcclient==0.6
|
||||||
|
|
||||||
# homeassistant.components.verisure
|
# homeassistant.components.verisure
|
||||||
vsure==0.5.0
|
vsure==0.5.0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user