mirror of
https://github.com/home-assistant/core.git
synced 2025-04-25 01:38:02 +00:00
Fix feedback from UVC (#45630)
* Fixing feedback from UVC * Couple of fixes
This commit is contained in:
parent
87d40ff815
commit
8a112721fa
@ -2,6 +2,7 @@
|
||||
from datetime import datetime
|
||||
import logging
|
||||
import re
|
||||
from typing import Optional
|
||||
|
||||
import requests
|
||||
from uvcclient import camera as uvc_camera, nvr
|
||||
@ -111,9 +112,9 @@ class UnifiVideoCamera(Camera):
|
||||
return 0
|
||||
|
||||
@property
|
||||
def state_attributes(self):
|
||||
def device_state_attributes(self):
|
||||
"""Return the camera state attributes."""
|
||||
attr = super().state_attributes
|
||||
attr = {}
|
||||
if self.motion_detection_enabled:
|
||||
attr["last_recording_start_time"] = timestamp_ms_to_date(
|
||||
self._caminfo["lastRecordingStartTime"]
|
||||
@ -124,7 +125,7 @@ class UnifiVideoCamera(Camera):
|
||||
def is_recording(self):
|
||||
"""Return true if the camera is recording."""
|
||||
recording_state = "DISABLED"
|
||||
if "recordingIndicator" in self._caminfo.keys():
|
||||
if "recordingIndicator" in self._caminfo:
|
||||
recording_state = self._caminfo["recordingIndicator"]
|
||||
|
||||
return (
|
||||
@ -256,7 +257,8 @@ class UnifiVideoCamera(Camera):
|
||||
self._caminfo = self._nvr.get_camera(self._uuid)
|
||||
|
||||
|
||||
def timestamp_ms_to_date(epoch_ms) -> datetime or None:
|
||||
def timestamp_ms_to_date(epoch_ms: int) -> Optional[datetime]:
|
||||
"""Convert millisecond timestamp to datetime."""
|
||||
if epoch_ms:
|
||||
return datetime.fromtimestamp(epoch_ms / 1000)
|
||||
return None
|
||||
|
@ -257,7 +257,7 @@ class TestUVC(unittest.TestCase):
|
||||
assert not self.uvc.is_recording
|
||||
assert (
|
||||
datetime(2021, 1, 8, 1, 56, 32, 367000)
|
||||
== self.uvc.state_attributes["last_recording_start_time"]
|
||||
== self.uvc.device_state_attributes["last_recording_start_time"]
|
||||
)
|
||||
|
||||
self.nvr.get_camera.return_value["recordingIndicator"] = "DISABLED"
|
||||
|
Loading…
x
Reference in New Issue
Block a user