Update accuweather to use CoordinatorEntity (#39408)

This commit is contained in:
springstan 2020-08-30 16:06:38 +02:00 committed by GitHub
parent 29c1f873eb
commit 152b6c2d1a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -5,7 +5,7 @@ from homeassistant.const import (
CONF_NAME,
DEVICE_CLASS_TEMPERATURE,
)
from homeassistant.helpers.entity import Entity
from homeassistant.helpers.update_coordinator import CoordinatorEntity
from .const import (
ATTR_FORECAST,
@ -48,14 +48,14 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
async_add_entities(sensors, False)
class AccuWeatherSensor(Entity):
class AccuWeatherSensor(CoordinatorEntity):
"""Define an AccuWeather entity."""
def __init__(self, name, kind, coordinator, forecast_day=None):
"""Initialize."""
super().__init__(coordinator)
self._name = name
self.kind = kind
self.coordinator = coordinator
self._device_class = None
self._attrs = {ATTR_ATTRIBUTION: ATTRIBUTION}
self._unit_system = "Metric" if self.coordinator.is_metric else "Imperial"
@ -85,16 +85,6 @@ class AccuWeatherSensor(Entity):
"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
def state(self):
"""Return the state."""
@ -173,13 +163,3 @@ class AccuWeatherSensor(Entity):
def entity_registry_enabled_default(self):
"""Return if the entity should be enabled when first added to the entity registry."""
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()