Update risco to use CoordinatorEntity (#39456)

This commit is contained in:
J. Nick Koston 2020-08-30 13:04:30 -05:00 committed by GitHub
parent e5b360cd08
commit 2b78d5235d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 28 deletions

View File

@ -65,7 +65,7 @@ class RiscoAlarm(AlarmControlPanelEntity, RiscoEntity):
"""Init the partition."""
super().__init__(coordinator)
self._partition_id = partition_id
self._partition = self._coordinator.data.partitions[self._partition_id]
self._partition = self.coordinator.data.partitions[self._partition_id]
self._code = code
self._code_arm_required = options[CONF_CODE_ARM_REQUIRED]
self._code_disarm_required = options[CONF_CODE_DISARM_REQUIRED]
@ -76,7 +76,7 @@ class RiscoAlarm(AlarmControlPanelEntity, RiscoEntity):
self._supported_states |= STATES_TO_SUPPORTED_FEATURES[state]
def _get_data_from_coordinator(self):
self._partition = self._coordinator.data.partitions[self._partition_id]
self._partition = self.coordinator.data.partitions[self._partition_id]
@property
def device_info(self):

View File

@ -39,7 +39,7 @@ class RiscoBinarySensor(BinarySensorEntity, RiscoEntity):
self._zone = zone
def _get_data_from_coordinator(self):
self._zone = self._coordinator.data.zones[self._zone_id]
self._zone = self.coordinator.data.zones[self._zone_id]
@property
def device_info(self):

View File

@ -1,24 +1,10 @@
"""A risco entity base class."""
from homeassistant.helpers.entity import Entity
from homeassistant.helpers.update_coordinator import CoordinatorEntity
class RiscoEntity(Entity):
class RiscoEntity(CoordinatorEntity):
"""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
@ -29,17 +15,10 @@ class RiscoEntity(Entity):
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)
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()
return self.coordinator.risco