mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 09:17:10 +00:00
Update gios to use CoordinatorEntity (#39421)
This commit is contained in:
parent
186c13f1ab
commit
baf5750425
@ -9,6 +9,7 @@ from homeassistant.components.air_quality import (
|
|||||||
AirQualityEntity,
|
AirQualityEntity,
|
||||||
)
|
)
|
||||||
from homeassistant.const import CONF_NAME
|
from homeassistant.const import CONF_NAME
|
||||||
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||||
|
|
||||||
from .const import ATTR_STATION, DEFAULT_NAME, DOMAIN, ICONS_MAP, MANUFACTURER
|
from .const import ATTR_STATION, DEFAULT_NAME, DOMAIN, ICONS_MAP, MANUFACTURER
|
||||||
|
|
||||||
@ -45,12 +46,12 @@ def round_state(func):
|
|||||||
return _decorator
|
return _decorator
|
||||||
|
|
||||||
|
|
||||||
class GiosAirQuality(AirQualityEntity):
|
class GiosAirQuality(CoordinatorEntity, AirQualityEntity):
|
||||||
"""Define an GIOS sensor."""
|
"""Define an GIOS sensor."""
|
||||||
|
|
||||||
def __init__(self, coordinator, name):
|
def __init__(self, coordinator, name):
|
||||||
"""Initialize."""
|
"""Initialize."""
|
||||||
self.coordinator = coordinator
|
super().__init__(coordinator)
|
||||||
self._name = name
|
self._name = name
|
||||||
self._attrs = {}
|
self._attrs = {}
|
||||||
|
|
||||||
@ -127,16 +128,6 @@ class GiosAirQuality(AirQualityEntity):
|
|||||||
"entry_type": "service",
|
"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
|
@property
|
||||||
def device_state_attributes(self):
|
def device_state_attributes(self):
|
||||||
"""Return the state attributes."""
|
"""Return the state attributes."""
|
||||||
@ -150,16 +141,6 @@ class GiosAirQuality(AirQualityEntity):
|
|||||||
self._attrs[ATTR_STATION] = self.coordinator.gios.station_name
|
self._attrs[ATTR_STATION] = self.coordinator.gios.station_name
|
||||||
return self._attrs
|
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):
|
def _get_sensor_value(self, sensor):
|
||||||
"""Return value of specified sensor."""
|
"""Return value of specified sensor."""
|
||||||
if sensor in self.coordinator.data:
|
if sensor in self.coordinator.data:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user