Update gios to use CoordinatorEntity (#39421)

pull/39431/head
springstan 2020-08-30 16:37:03 +02:00 committed by GitHub
parent 186c13f1ab
commit baf5750425
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 22 deletions

View File

@ -9,6 +9,7 @@ from homeassistant.components.air_quality import (
AirQualityEntity,
)
from homeassistant.const import CONF_NAME
from homeassistant.helpers.update_coordinator import CoordinatorEntity
from .const import ATTR_STATION, DEFAULT_NAME, DOMAIN, ICONS_MAP, MANUFACTURER
@ -45,12 +46,12 @@ def round_state(func):
return _decorator
class GiosAirQuality(AirQualityEntity):
class GiosAirQuality(CoordinatorEntity, AirQualityEntity):
"""Define an GIOS sensor."""
def __init__(self, coordinator, name):
"""Initialize."""
self.coordinator = coordinator
super().__init__(coordinator)
self._name = name
self._attrs = {}
@ -127,16 +128,6 @@ class GiosAirQuality(AirQualityEntity):
"entry_type": "service",
}
@property
def should_poll(self):
"""Return the polling requirement of the entity."""
return False
@property
def available(self):
"""Return True if entity is available."""
return self.coordinator.last_update_success
@property
def device_state_attributes(self):
"""Return the state attributes."""
@ -150,16 +141,6 @@ class GiosAirQuality(AirQualityEntity):
self._attrs[ATTR_STATION] = self.coordinator.gios.station_name
return self._attrs
async def async_added_to_hass(self):
"""Connect to dispatcher listening for entity data notifications."""
self.async_on_remove(
self.coordinator.async_add_listener(self.async_write_ha_state)
)
async def async_update(self):
"""Update GIOS entity."""
await self.coordinator.async_request_refresh()
def _get_sensor_value(self, sensor):
"""Return value of specified sensor."""
if sensor in self.coordinator.data: