Adjust inheritance in ring (#77366)
* Adjust inheritance in ring * Fix extra_state_attributes
This commit is contained in:
parent
d8b2563b3d
commit
4142530368
3 changed files with 10 additions and 20 deletions
|
@ -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)
|
||||
|
|
|
@ -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."""
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Add table
Reference in a new issue