Use _attr_should_poll in camera entities (#77173)

This commit is contained in:
epenet 2022-08-22 20:30:35 +02:00 committed by GitHub
parent 03ed552ca9
commit df5f6bdfc1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 8 additions and 38 deletions

View File

@ -70,6 +70,7 @@ class AgentCamera(MjpegCamera):
"""Representation of an Agent Device Stream."""
_attr_attribution = ATTRIBUTION
_attr_should_poll = True # Cameras default to False
_attr_supported_features = CameraEntityFeature.ON_OFF
def __init__(self, device):
@ -117,11 +118,6 @@ 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."""

View File

@ -164,6 +164,7 @@ class AmcrestCommandFailed(Exception):
class AmcrestCam(Camera):
"""An implementation of an Amcrest IP camera."""
_attr_should_poll = True # Cameras default to False
_attr_supported_features = CameraEntityFeature.ON_OFF | CameraEntityFeature.STREAM
def __init__(self, name: str, device: AmcrestDevice, ffmpeg: FFmpegManager) -> None:
@ -281,14 +282,6 @@ class AmcrestCam(Camera):
# Entity property overrides
@property
def should_poll(self) -> bool:
"""Return True if entity has to be polled for state.
False if entity pushes its state to HA.
"""
return True
@property
def name(self) -> str:
"""Return the name of this camera."""

View File

@ -62,6 +62,7 @@ async def async_setup_entry(
class LogiCam(Camera):
"""An implementation of a Logi Circle camera."""
_attr_should_poll = True # Cameras default to False
_attr_supported_features = CameraEntityFeature.ON_OFF
def __init__(self, camera, device_info, ffmpeg):
@ -168,11 +169,6 @@ class LogiCam(Camera):
"""Enable streaming mode for this camera."""
await self._camera.set_config("streaming", True)
@property
def should_poll(self):
"""Update the image periodically."""
return True
async def set_config(self, mode, value):
"""Set an configuration property for the target camera."""
if mode == LED_MODE_KEY:

View File

@ -74,11 +74,6 @@ class NestCamera(Camera):
self._attr_is_streaming = CameraLiveStreamTrait.NAME in self._device.traits
self.stream_options[CONF_EXTRA_PART_WAIT_TIME] = 3
@property
def should_poll(self) -> bool:
"""Disable polling since entities have state pushed via pubsub."""
return False
@property
def unique_id(self) -> str:
"""Return a unique ID."""

View File

@ -38,6 +38,7 @@ async def async_setup_legacy_entry(hass, entry, async_add_entities) -> None:
class NestCamera(Camera):
"""Representation of a Nest Camera."""
_attr_should_poll = True # Cameras default to False
_attr_supported_features = CameraEntityFeature.ON_OFF
def __init__(self, structure, device):
@ -75,11 +76,6 @@ class NestCamera(Camera):
name=self.device.name_long,
)
@property
def should_poll(self):
"""Nest camera should poll periodically."""
return True
@property
def is_recording(self):
"""Return true if the device is recording."""

View File

@ -86,6 +86,8 @@ def setup_platform(
class UnifiVideoCamera(Camera):
"""A Ubiquiti Unifi Video Camera."""
_attr_should_poll = True # Cameras default to False
def __init__(self, camera, uuid, name, password):
"""Initialize an Unifi camera."""
super().__init__()
@ -104,11 +106,6 @@ class UnifiVideoCamera(Camera):
"""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."""

View File

@ -36,6 +36,8 @@ def setup_platform(
class ZoneMinderCamera(MjpegCamera):
"""Representation of a ZoneMinder Monitor Stream."""
_attr_should_poll = True # Cameras default to False
def __init__(self, monitor, verify_ssl):
"""Initialize as a subclass of MjpegCamera."""
super().__init__(
@ -48,11 +50,6 @@ class ZoneMinderCamera(MjpegCamera):
self._is_available = None
self._monitor = monitor
@property
def should_poll(self):
"""Update the recording state periodically."""
return True
def update(self):
"""Update our recording state from the ZM API."""
_LOGGER.debug("Updating camera state for monitor %i", self._monitor.id)