mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 07:07:28 +00:00
Fix UVC doing I/O in event loop (#34610)
This commit is contained in:
parent
7bfc1d2840
commit
afe15a2e6b
@ -66,7 +66,8 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||||||
[
|
[
|
||||||
UnifiVideoCamera(nvrconn, camera[identifier], camera["name"], password)
|
UnifiVideoCamera(nvrconn, camera[identifier], camera["name"], password)
|
||||||
for camera in cameras
|
for camera in cameras
|
||||||
]
|
],
|
||||||
|
True,
|
||||||
)
|
)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@ -85,17 +86,22 @@ class UnifiVideoCamera(Camera):
|
|||||||
self._connect_addr = None
|
self._connect_addr = None
|
||||||
self._camera = None
|
self._camera = None
|
||||||
self._motion_status = False
|
self._motion_status = False
|
||||||
|
self._caminfo = None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""Return the name of this camera."""
|
"""Return the name of this camera."""
|
||||||
return self._name
|
return self._name
|
||||||
|
|
||||||
|
@property
|
||||||
|
def should_poll(self):
|
||||||
|
"""If this entity should be polled."""
|
||||||
|
return True
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def supported_features(self):
|
def supported_features(self):
|
||||||
"""Return supported features."""
|
"""Return supported features."""
|
||||||
caminfo = self._nvr.get_camera(self._uuid)
|
channels = self._caminfo["channels"]
|
||||||
channels = caminfo["channels"]
|
|
||||||
for channel in channels:
|
for channel in channels:
|
||||||
if channel["isRtspEnabled"]:
|
if channel["isRtspEnabled"]:
|
||||||
return SUPPORT_STREAM
|
return SUPPORT_STREAM
|
||||||
@ -105,14 +111,12 @@ class UnifiVideoCamera(Camera):
|
|||||||
@property
|
@property
|
||||||
def is_recording(self):
|
def is_recording(self):
|
||||||
"""Return true if the camera is recording."""
|
"""Return true if the camera is recording."""
|
||||||
caminfo = self._nvr.get_camera(self._uuid)
|
return self._caminfo["recordingSettings"]["fullTimeRecordEnabled"]
|
||||||
return caminfo["recordingSettings"]["fullTimeRecordEnabled"]
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def motion_detection_enabled(self):
|
def motion_detection_enabled(self):
|
||||||
"""Camera Motion Detection Status."""
|
"""Camera Motion Detection Status."""
|
||||||
caminfo = self._nvr.get_camera(self._uuid)
|
return self._caminfo["recordingSettings"]["motionRecordEnabled"]
|
||||||
return caminfo["recordingSettings"]["motionRecordEnabled"]
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def brand(self):
|
def brand(self):
|
||||||
@ -122,13 +126,11 @@ class UnifiVideoCamera(Camera):
|
|||||||
@property
|
@property
|
||||||
def model(self):
|
def model(self):
|
||||||
"""Return the model of this camera."""
|
"""Return the model of this camera."""
|
||||||
caminfo = self._nvr.get_camera(self._uuid)
|
return self._caminfo["model"]
|
||||||
return caminfo["model"]
|
|
||||||
|
|
||||||
def _login(self):
|
def _login(self):
|
||||||
"""Login to the camera."""
|
"""Login to the camera."""
|
||||||
|
caminfo = self._caminfo
|
||||||
caminfo = self._nvr.get_camera(self._uuid)
|
|
||||||
if self._connect_addr:
|
if self._connect_addr:
|
||||||
addrs = [self._connect_addr]
|
addrs = [self._connect_addr]
|
||||||
else:
|
else:
|
||||||
@ -164,6 +166,7 @@ class UnifiVideoCamera(Camera):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
self._camera = camera
|
self._camera = camera
|
||||||
|
self._caminfo = caminfo
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def camera_image(self):
|
def camera_image(self):
|
||||||
@ -219,3 +222,7 @@ class UnifiVideoCamera(Camera):
|
|||||||
return channel["rtspUris"][0]
|
return channel["rtspUris"][0]
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def update(self):
|
||||||
|
"""Update the info."""
|
||||||
|
self._caminfo = self._nvr.get_camera(self._uuid)
|
||||||
|
@ -213,6 +213,7 @@ class TestUVC(unittest.TestCase):
|
|||||||
],
|
],
|
||||||
}
|
}
|
||||||
self.nvr.server_version = (3, 2, 0)
|
self.nvr.server_version = (3, 2, 0)
|
||||||
|
self.uvc.update()
|
||||||
|
|
||||||
def test_properties(self):
|
def test_properties(self):
|
||||||
"""Test the properties."""
|
"""Test the properties."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user