From 152b6c2d1a396daff78e1e3d66635260d45d7552 Mon Sep 17 00:00:00 2001 From: springstan <46536646+springstan@users.noreply.github.com> Date: Sun, 30 Aug 2020 16:06:38 +0200 Subject: [PATCH] Update accuweather to use CoordinatorEntity (#39408) --- .../components/accuweather/sensor.py | 26 +++---------------- 1 file changed, 3 insertions(+), 23 deletions(-) diff --git a/homeassistant/components/accuweather/sensor.py b/homeassistant/components/accuweather/sensor.py index 9ab44a318a9..4f61322b2c6 100644 --- a/homeassistant/components/accuweather/sensor.py +++ b/homeassistant/components/accuweather/sensor.py @@ -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()