Fix camera state and attributes for agent_dvr (#54049)

* Fix camera state and attributes for agent_dvr

* tweak

* tweak
pull/54278/head
Robert Hillis 2021-08-08 09:43:08 -04:00 committed by GitHub
parent 89bb95b0be
commit 7590cb2861
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 4 deletions

View File

@ -67,8 +67,6 @@ async def async_setup_entry(
class AgentCamera(MjpegCamera):
"""Representation of an Agent Device Stream."""
_attr_supported_features = SUPPORT_ON_OFF
def __init__(self, device):
"""Initialize as a subclass of MjpegCamera."""
device_info = {
@ -80,7 +78,6 @@ class AgentCamera(MjpegCamera):
self._removed = False
self._attr_name = f"{device.client.name} {device.name}"
self._attr_unique_id = f"{device._client.unique}_{device.typeID}_{device.id}"
self._attr_should_poll = True
super().__init__(device_info)
self._attr_device_info = {
"identifiers": {(AGENT_DOMAIN, self.unique_id)},
@ -102,10 +99,10 @@ class AgentCamera(MjpegCamera):
if self.device.client.is_available and not self._removed:
_LOGGER.error("%s lost", self.name)
self._removed = True
self._attr_available = self.device.client.is_available
self._attr_icon = "mdi:camcorder-off"
if self.is_on:
self._attr_icon = "mdi:camcorder"
self._attr_available = self.device.client.is_available
self._attr_extra_state_attributes = {
ATTR_ATTRIBUTION: ATTRIBUTION,
"editable": False,
@ -117,6 +114,11 @@ class AgentCamera(MjpegCamera):
"alerts_enabled": self.device.alerts_active,
}
@property
def should_poll(self) -> bool:
"""Update the state periodically."""
return True
@property
def is_recording(self) -> bool:
"""Return whether the monitor is recording."""
@ -137,6 +139,11 @@ class AgentCamera(MjpegCamera):
"""Return True if entity is connected."""
return self.device.connected
@property
def supported_features(self) -> int:
"""Return supported features."""
return SUPPORT_ON_OFF
@property
def is_on(self) -> bool:
"""Return true if on."""