Update airly to use CoordinatorEntity (#39413)

This commit is contained in:
springstan 2020-08-30 14:41:39 +02:00 committed by GitHub
parent 0f5733ac59
commit 4425c3aea2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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()