Add binary sensors to Risco integration (#39137)
* Add binary sensors to Risco integration * Minor cleanups * RiscoEntity base class * Platinum score * Remove alarm parameter in _setup_risco * Avoid zones and partitions sharing unique ids
This commit is contained in:
1 parent
73328dab5e
commit
3198233b8f
7 files changed
+278
-38
No files matched your search
@@ -0,0 +1,45 @@
|
||||
"""A risco entity base class."""
|
||||
from homeassistant.helpers.entity import Entity
|
||||
|
||||
|
||||
class RiscoEntity(Entity):
|
||||
"""Risco entity base class."""
|
||||
|
||||
def __init__(self, coordinator):
|
||||
"""Init the instance."""
|
||||
self._coordinator = coordinator
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
"""No need to poll. Coordinator notifies entity of updates."""
|
||||
return False
|
||||
|
||||
@property
|
||||
def available(self):
|
||||
"""Return if entity is available."""
|
||||
return self._coordinator.last_update_success
|
||||
|
||||
def _get_data_from_coordinator(self):
|
||||
raise NotImplementedError
|
||||
|
||||
def _refresh_from_coordinator(self):
|
||||
self._get_data_from_coordinator()
|
||||
self.async_write_ha_state()
|
||||
|
||||
async def async_added_to_hass(self):
|
||||
"""When entity is added to hass."""
|
||||
self.async_on_remove(
|
||||
self._coordinator.async_add_listener(self._refresh_from_coordinator)
|
||||
)
|
||||
|
||||
@property
|
||||
def _risco(self):
|
||||
"""Return the Risco API object."""
|
||||
return self._coordinator.risco
|
||||
|
||||
async def async_update(self):
|
||||
"""Update the entity.
|
||||
|
||||
Only used by the generic entity update service.
|
||||
"""
|
||||
await self._coordinator.async_request_refresh()
|
||||
Reference in new issue
Block a user