Call async added to hass super in Risco (#100444)

This commit is contained in:
Joost Lekkerkerker 2023-09-26 20:02:00 +02:00 committed by GitHub
parent ae7ede1253
commit bdfdeb2bc0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 13 deletions

View file

@ -31,17 +31,10 @@ class RiscoCloudEntity(CoordinatorEntity[RiscoDataUpdateCoordinator]):
def _get_data_from_coordinator(self) -> None:
raise NotImplementedError
def _refresh_from_coordinator(self) -> None:
def _handle_coordinator_update(self) -> None:
self._get_data_from_coordinator()
self.async_write_ha_state()
# pylint: disable-next=hass-missing-super-call
async def async_added_to_hass(self) -> None:
"""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."""

View file

@ -86,15 +86,12 @@ class RiscoSensor(CoordinatorEntity[RiscoEventsDataUpdateCoordinator], SensorEnt
self._attr_name = f"Risco {self.coordinator.risco.site_name} {name} Events"
self._attr_device_class = SensorDeviceClass.TIMESTAMP
# pylint: disable-next=hass-missing-super-call
async def async_added_to_hass(self) -> None:
"""When entity is added to hass."""
await super().async_added_to_hass()
self._entity_registry = er.async_get(self.hass)
self.async_on_remove(
self.coordinator.async_add_listener(self._refresh_from_coordinator)
)
def _refresh_from_coordinator(self):
def _handle_coordinator_update(self):
events = self.coordinator.data
for event in reversed(events):
if event.category_id in self._excludes: