From df5f6bdfc1ed4141847dc201e5492bbd81794ba8 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Mon, 22 Aug 2022 20:30:35 +0200 Subject: [PATCH] Use _attr_should_poll in camera entities (#77173) --- homeassistant/components/agent_dvr/camera.py | 6 +----- homeassistant/components/amcrest/camera.py | 9 +-------- homeassistant/components/logi_circle/camera.py | 6 +----- homeassistant/components/nest/camera_sdm.py | 5 ----- homeassistant/components/nest/legacy/camera.py | 6 +----- homeassistant/components/uvc/camera.py | 7 ++----- homeassistant/components/zoneminder/camera.py | 7 ++----- 7 files changed, 8 insertions(+), 38 deletions(-) diff --git a/homeassistant/components/agent_dvr/camera.py b/homeassistant/components/agent_dvr/camera.py index 2e8568b22b7..e485940034f 100644 --- a/homeassistant/components/agent_dvr/camera.py +++ b/homeassistant/components/agent_dvr/camera.py @@ -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.""" diff --git a/homeassistant/components/amcrest/camera.py b/homeassistant/components/amcrest/camera.py index c3d1e0d28d6..da5e046a88a 100644 --- a/homeassistant/components/amcrest/camera.py +++ b/homeassistant/components/amcrest/camera.py @@ -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.""" diff --git a/homeassistant/components/logi_circle/camera.py b/homeassistant/components/logi_circle/camera.py index 097b64ac208..231de83a135 100644 --- a/homeassistant/components/logi_circle/camera.py +++ b/homeassistant/components/logi_circle/camera.py @@ -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: diff --git a/homeassistant/components/nest/camera_sdm.py b/homeassistant/components/nest/camera_sdm.py index c26b216b21f..e148916d7e8 100644 --- a/homeassistant/components/nest/camera_sdm.py +++ b/homeassistant/components/nest/camera_sdm.py @@ -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.""" diff --git a/homeassistant/components/nest/legacy/camera.py b/homeassistant/components/nest/legacy/camera.py index affe912b6fb..d118b9b8c4a 100644 --- a/homeassistant/components/nest/legacy/camera.py +++ b/homeassistant/components/nest/legacy/camera.py @@ -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.""" diff --git a/homeassistant/components/uvc/camera.py b/homeassistant/components/uvc/camera.py index e6365f21dfe..d6c3bd55d63 100644 --- a/homeassistant/components/uvc/camera.py +++ b/homeassistant/components/uvc/camera.py @@ -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.""" diff --git a/homeassistant/components/zoneminder/camera.py b/homeassistant/components/zoneminder/camera.py index a7f0cf1d7fa..a627f64d0bf 100644 --- a/homeassistant/components/zoneminder/camera.py +++ b/homeassistant/components/zoneminder/camera.py @@ -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)