Update airvisual to use CoordinatorEntity (#39417)

This commit is contained in:
springstan 2020-08-30 16:01:19 +02:00 committed by GitHub
parent 4294d10789
commit 64513c8c9a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -20,8 +20,11 @@ from homeassistant.const import (
) )
from homeassistant.core import callback from homeassistant.core import callback
from homeassistant.helpers import aiohttp_client, config_validation as cv from homeassistant.helpers import aiohttp_client, config_validation as cv
from homeassistant.helpers.entity import Entity from homeassistant.helpers.update_coordinator import (
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed CoordinatorEntity,
DataUpdateCoordinator,
UpdateFailed,
)
from .const import ( from .const import (
CONF_CITY, CONF_CITY,
@ -351,20 +354,15 @@ async def async_update_options(hass, config_entry):
await coordinator.async_request_refresh() await coordinator.async_request_refresh()
class AirVisualEntity(Entity): class AirVisualEntity(CoordinatorEntity):
"""Define a generic AirVisual entity.""" """Define a generic AirVisual entity."""
def __init__(self, coordinator): def __init__(self, coordinator):
"""Initialize.""" """Initialize."""
super().__init__(coordinator)
self._attrs = {ATTR_ATTRIBUTION: DEFAULT_ATTRIBUTION} self._attrs = {ATTR_ATTRIBUTION: DEFAULT_ATTRIBUTION}
self._icon = None self._icon = None
self._unit = None self._unit = None
self.coordinator = coordinator
@property
def available(self):
"""Return if entity is available."""
return self.coordinator.last_update_success
@property @property
def device_state_attributes(self): def device_state_attributes(self):
@ -376,11 +374,6 @@ class AirVisualEntity(Entity):
"""Return the icon.""" """Return the icon."""
return self._icon return self._icon
@property
def should_poll(self) -> bool:
"""Disable polling."""
return False
@property @property
def unit_of_measurement(self): def unit_of_measurement(self):
"""Return the unit the value is expressed in.""" """Return the unit the value is expressed in."""
@ -399,13 +392,6 @@ class AirVisualEntity(Entity):
self.update_from_latest_data() 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 @callback
def update_from_latest_data(self): def update_from_latest_data(self):
"""Update the entity from the latest data.""" """Update the entity from the latest data."""