mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Update accuweather to use CoordinatorEntity (#39408)
This commit is contained in:
parent
29c1f873eb
commit
152b6c2d1a
@ -5,7 +5,7 @@ from homeassistant.const import (
|
|||||||
CONF_NAME,
|
CONF_NAME,
|
||||||
DEVICE_CLASS_TEMPERATURE,
|
DEVICE_CLASS_TEMPERATURE,
|
||||||
)
|
)
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
ATTR_FORECAST,
|
ATTR_FORECAST,
|
||||||
@ -48,14 +48,14 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
|||||||
async_add_entities(sensors, False)
|
async_add_entities(sensors, False)
|
||||||
|
|
||||||
|
|
||||||
class AccuWeatherSensor(Entity):
|
class AccuWeatherSensor(CoordinatorEntity):
|
||||||
"""Define an AccuWeather entity."""
|
"""Define an AccuWeather entity."""
|
||||||
|
|
||||||
def __init__(self, name, kind, coordinator, forecast_day=None):
|
def __init__(self, name, kind, coordinator, forecast_day=None):
|
||||||
"""Initialize."""
|
"""Initialize."""
|
||||||
|
super().__init__(coordinator)
|
||||||
self._name = name
|
self._name = name
|
||||||
self.kind = kind
|
self.kind = kind
|
||||||
self.coordinator = coordinator
|
|
||||||
self._device_class = None
|
self._device_class = None
|
||||||
self._attrs = {ATTR_ATTRIBUTION: ATTRIBUTION}
|
self._attrs = {ATTR_ATTRIBUTION: ATTRIBUTION}
|
||||||
self._unit_system = "Metric" if self.coordinator.is_metric else "Imperial"
|
self._unit_system = "Metric" if self.coordinator.is_metric else "Imperial"
|
||||||
@ -85,16 +85,6 @@ class AccuWeatherSensor(Entity):
|
|||||||
"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 state(self):
|
def state(self):
|
||||||
"""Return the state."""
|
"""Return the state."""
|
||||||
@ -173,13 +163,3 @@ class AccuWeatherSensor(Entity):
|
|||||||
def entity_registry_enabled_default(self):
|
def entity_registry_enabled_default(self):
|
||||||
"""Return if the entity should be enabled when first added to the entity registry."""
|
"""Return if the entity should be enabled when first added to the entity registry."""
|
||||||
return bool(self.kind not in OPTIONAL_SENSORS)
|
return bool(self.kind not in OPTIONAL_SENSORS)
|
||||||
|
|
||||||
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 AccuWeather entity."""
|
|
||||||
await self.coordinator.async_request_refresh()
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user