From 4142530368b67feb96cfabc7b573683726ae6b79 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Fri, 26 Aug 2022 21:40:28 +0200 Subject: [PATCH] Adjust inheritance in ring (#77366) * Adjust inheritance in ring * Fix extra_state_attributes --- homeassistant/components/ring/camera.py | 4 +--- homeassistant/components/ring/entity.py | 25 +++++++++---------------- homeassistant/components/ring/sensor.py | 1 - 3 files changed, 10 insertions(+), 20 deletions(-) diff --git a/homeassistant/components/ring/camera.py b/homeassistant/components/ring/camera.py index 72d8a51f01e..5bf440cfcd9 100644 --- a/homeassistant/components/ring/camera.py +++ b/homeassistant/components/ring/camera.py @@ -16,7 +16,7 @@ from homeassistant.helpers.aiohttp_client import async_aiohttp_proxy_stream from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.util import dt as dt_util -from . import ATTRIBUTION, DOMAIN +from . import DOMAIN from .entity import RingEntityMixin FORCE_REFRESH_INTERVAL = timedelta(minutes=3) @@ -48,8 +48,6 @@ async def async_setup_entry( class RingCam(RingEntityMixin, Camera): """An implementation of a Ring Door Bell camera.""" - _attr_attribution = ATTRIBUTION - def __init__(self, config_entry_id, ffmpeg_manager, device): """Initialize a Ring Door Bell camera.""" super().__init__(config_entry_id, device) diff --git a/homeassistant/components/ring/entity.py b/homeassistant/components/ring/entity.py index 84f4816115f..16aa86511be 100644 --- a/homeassistant/components/ring/entity.py +++ b/homeassistant/components/ring/entity.py @@ -1,30 +1,33 @@ """Base class for Ring entity.""" -from homeassistant.const import ATTR_ATTRIBUTION from homeassistant.core import callback -from homeassistant.helpers.entity import DeviceInfo +from homeassistant.helpers.entity import DeviceInfo, Entity from . import ATTRIBUTION, DOMAIN -class RingEntityMixin: +class RingEntityMixin(Entity): """Base implementation for Ring device.""" + _attr_attribution = ATTRIBUTION + _attr_should_poll = False + def __init__(self, config_entry_id, device): """Initialize a sensor for Ring device.""" super().__init__() self._config_entry_id = config_entry_id self._device = device + self._attr_extra_state_attributes = {} - async def async_added_to_hass(self): + async def async_added_to_hass(self) -> None: """Register callbacks.""" self.ring_objects["device_data"].async_add_listener(self._update_callback) - async def async_will_remove_from_hass(self): + async def async_will_remove_from_hass(self) -> None: """Disconnect callbacks.""" self.ring_objects["device_data"].async_remove_listener(self._update_callback) @callback - def _update_callback(self): + def _update_callback(self) -> None: """Call update method.""" self.async_write_ha_state() @@ -33,16 +36,6 @@ class RingEntityMixin: """Return the Ring API objects.""" return self.hass.data[DOMAIN][self._config_entry_id] - @property - def should_poll(self): - """Return False, updates are controlled via the hub.""" - return False - - @property - def extra_state_attributes(self): - """Return the state attributes.""" - return {ATTR_ATTRIBUTION: ATTRIBUTION} - @property def device_info(self) -> DeviceInfo: """Return device info.""" diff --git a/homeassistant/components/ring/sensor.py b/homeassistant/components/ring/sensor.py index 4036c9adb4d..26068c149ce 100644 --- a/homeassistant/components/ring/sensor.py +++ b/homeassistant/components/ring/sensor.py @@ -42,7 +42,6 @@ class RingSensor(RingEntityMixin, SensorEntity): """A sensor implementation for Ring device.""" entity_description: RingSensorEntityDescription - _attr_should_poll = False # updates are controlled via the hub def __init__( self,