From 64513c8c9a0b814c7a975cfa3b1440d8b719ea19 Mon Sep 17 00:00:00 2001 From: springstan <46536646+springstan@users.noreply.github.com> Date: Sun, 30 Aug 2020 16:01:19 +0200 Subject: [PATCH] Update airvisual to use CoordinatorEntity (#39417) --- .../components/airvisual/__init__.py | 28 +++++-------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/homeassistant/components/airvisual/__init__.py b/homeassistant/components/airvisual/__init__.py index 4e748766425..563e24bf8fd 100644 --- a/homeassistant/components/airvisual/__init__.py +++ b/homeassistant/components/airvisual/__init__.py @@ -20,8 +20,11 @@ from homeassistant.const import ( ) from homeassistant.core import callback from homeassistant.helpers import aiohttp_client, config_validation as cv -from homeassistant.helpers.entity import Entity -from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed +from homeassistant.helpers.update_coordinator import ( + CoordinatorEntity, + DataUpdateCoordinator, + UpdateFailed, +) from .const import ( CONF_CITY, @@ -351,20 +354,15 @@ async def async_update_options(hass, config_entry): await coordinator.async_request_refresh() -class AirVisualEntity(Entity): +class AirVisualEntity(CoordinatorEntity): """Define a generic AirVisual entity.""" def __init__(self, coordinator): """Initialize.""" + super().__init__(coordinator) self._attrs = {ATTR_ATTRIBUTION: DEFAULT_ATTRIBUTION} self._icon = None self._unit = None - self.coordinator = coordinator - - @property - def available(self): - """Return if entity is available.""" - return self.coordinator.last_update_success @property def device_state_attributes(self): @@ -376,11 +374,6 @@ class AirVisualEntity(Entity): """Return the icon.""" return self._icon - @property - def should_poll(self) -> bool: - """Disable polling.""" - return False - @property def unit_of_measurement(self): """Return the unit the value is expressed in.""" @@ -399,13 +392,6 @@ class AirVisualEntity(Entity): self.update_from_latest_data() - async def async_update(self): - """Update the entity. - - Only used by the generic entity update service. - """ - await self.coordinator.async_request_refresh() - @callback def update_from_latest_data(self): """Update the entity from the latest data."""