Fix UVC doing I/O in event loop (#34610)

This commit is contained in:
Paulus Schoutsen 2020-04-23 15:52:36 -07:00 committed by GitHub
parent 7bfc1d2840
commit afe15a2e6b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 11 deletions

View file

@ -66,7 +66,8 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
[
UnifiVideoCamera(nvrconn, camera[identifier], camera["name"], password)
for camera in cameras
]
],
True,
)
return True
@ -85,17 +86,22 @@ class UnifiVideoCamera(Camera):
self._connect_addr = None
self._camera = None
self._motion_status = False
self._caminfo = None
@property
def name(self):
"""Return the name of this camera."""
return self._name
@property
def should_poll(self):
"""If this entity should be polled."""
return True
@property
def supported_features(self):
"""Return supported features."""
caminfo = self._nvr.get_camera(self._uuid)
channels = caminfo["channels"]
channels = self._caminfo["channels"]
for channel in channels:
if channel["isRtspEnabled"]:
return SUPPORT_STREAM
@ -105,14 +111,12 @@ class UnifiVideoCamera(Camera):
@property
def is_recording(self):
"""Return true if the camera is recording."""
caminfo = self._nvr.get_camera(self._uuid)
return caminfo["recordingSettings"]["fullTimeRecordEnabled"]
return self._caminfo["recordingSettings"]["fullTimeRecordEnabled"]
@property
def motion_detection_enabled(self):
"""Camera Motion Detection Status."""
caminfo = self._nvr.get_camera(self._uuid)
return caminfo["recordingSettings"]["motionRecordEnabled"]
return self._caminfo["recordingSettings"]["motionRecordEnabled"]
@property
def brand(self):
@ -122,13 +126,11 @@ class UnifiVideoCamera(Camera):
@property
def model(self):
"""Return the model of this camera."""
caminfo = self._nvr.get_camera(self._uuid)
return caminfo["model"]
return self._caminfo["model"]
def _login(self):
"""Login to the camera."""
caminfo = self._nvr.get_camera(self._uuid)
caminfo = self._caminfo
if self._connect_addr:
addrs = [self._connect_addr]
else:
@ -164,6 +166,7 @@ class UnifiVideoCamera(Camera):
return None
self._camera = camera
self._caminfo = caminfo
return True
def camera_image(self):
@ -219,3 +222,7 @@ class UnifiVideoCamera(Camera):
return channel["rtspUris"][0]
return None
def update(self):
"""Update the info."""
self._caminfo = self._nvr.get_camera(self._uuid)

View file

@ -213,6 +213,7 @@ class TestUVC(unittest.TestCase):
],
}
self.nvr.server_version = (3, 2, 0)
self.uvc.update()
def test_properties(self):
"""Test the properties."""