diff --git a/homeassistant/components/airly/sensor.py b/homeassistant/components/airly/sensor.py index 916405be2a5..8d016c4e60b 100644 --- a/homeassistant/components/airly/sensor.py +++ b/homeassistant/components/airly/sensor.py @@ -11,7 +11,7 @@ from homeassistant.const import ( TEMP_CELSIUS, UNIT_PERCENTAGE, ) -from homeassistant.helpers.entity import Entity +from homeassistant.helpers.update_coordinator import CoordinatorEntity from .const import ( ATTR_API_HUMIDITY, @@ -72,12 +72,12 @@ async def async_setup_entry(hass, config_entry, async_add_entities): async_add_entities(sensors, False) -class AirlySensor(Entity): +class AirlySensor(CoordinatorEntity): """Define an Airly sensor.""" def __init__(self, coordinator, name, kind): """Initialize.""" - self.coordinator = coordinator + super().__init__(coordinator) self._name = name self.kind = kind self._device_class = None @@ -91,11 +91,6 @@ class AirlySensor(Entity): """Return the name.""" return f"{self._name} {SENSOR_TYPES[self.kind][ATTR_LABEL]}" - @property - def should_poll(self): - """Return the polling requirement of the entity.""" - return False - @property def state(self): """Return the state.""" @@ -143,18 +138,3 @@ class AirlySensor(Entity): def unit_of_measurement(self): """Return the unit the value is expressed in.""" return SENSOR_TYPES[self.kind][ATTR_UNIT] - - @property - def available(self): - """Return True if entity is available.""" - return self.coordinator.last_update_success - - 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 Airly entity.""" - await self.coordinator.async_request_refresh()