mirror of
https://github.com/home-assistant/core.git
synced 2025-06-05 05:37:04 +00:00
Update airly to use CoordinatorEntity (#39413)
This commit is contained in:
parent
0f5733ac59
commit
4425c3aea2
@ -11,7 +11,7 @@ from homeassistant.const import (
|
|||||||
TEMP_CELSIUS,
|
TEMP_CELSIUS,
|
||||||
UNIT_PERCENTAGE,
|
UNIT_PERCENTAGE,
|
||||||
)
|
)
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
ATTR_API_HUMIDITY,
|
ATTR_API_HUMIDITY,
|
||||||
@ -72,12 +72,12 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
|||||||
async_add_entities(sensors, False)
|
async_add_entities(sensors, False)
|
||||||
|
|
||||||
|
|
||||||
class AirlySensor(Entity):
|
class AirlySensor(CoordinatorEntity):
|
||||||
"""Define an Airly sensor."""
|
"""Define an Airly sensor."""
|
||||||
|
|
||||||
def __init__(self, coordinator, name, kind):
|
def __init__(self, coordinator, name, kind):
|
||||||
"""Initialize."""
|
"""Initialize."""
|
||||||
self.coordinator = coordinator
|
super().__init__(coordinator)
|
||||||
self._name = name
|
self._name = name
|
||||||
self.kind = kind
|
self.kind = kind
|
||||||
self._device_class = None
|
self._device_class = None
|
||||||
@ -91,11 +91,6 @@ class AirlySensor(Entity):
|
|||||||
"""Return the name."""
|
"""Return the name."""
|
||||||
return f"{self._name} {SENSOR_TYPES[self.kind][ATTR_LABEL]}"
|
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
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
"""Return the state."""
|
"""Return the state."""
|
||||||
@ -143,18 +138,3 @@ class AirlySensor(Entity):
|
|||||||
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."""
|
||||||
return SENSOR_TYPES[self.kind][ATTR_UNIT]
|
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()
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user