From 854e33025b2dcdb3dc0e8054ba5dd8862cbf5040 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 30 Aug 2020 07:57:02 -0500 Subject: [PATCH] Update nexia to use CoordinatorEntity (#39391) Co-authored-by: Paulus Schoutsen --- homeassistant/components/nexia/climate.py | 7 ------- homeassistant/components/nexia/entity.py | 23 +++-------------------- homeassistant/components/nexia/scene.py | 2 +- 3 files changed, 4 insertions(+), 28 deletions(-) diff --git a/homeassistant/components/nexia/climate.py b/homeassistant/components/nexia/climate.py index b22b185a44c..5085242e6d7 100644 --- a/homeassistant/components/nexia/climate.py +++ b/homeassistant/components/nexia/climate.py @@ -458,10 +458,3 @@ class NexiaZone(NexiaThermostatZoneEntity, ClimateEntity): Update a single zone. """ dispatcher_send(self.hass, f"{SIGNAL_ZONE_UPDATE}-{self._zone.zone_id}") - - async def async_update(self): - """Update the entity. - - Only used by the generic entity update service. - """ - await self._coordinator.async_request_refresh() diff --git a/homeassistant/components/nexia/entity.py b/homeassistant/components/nexia/entity.py index 33962bb11c0..7820ebb6216 100644 --- a/homeassistant/components/nexia/entity.py +++ b/homeassistant/components/nexia/entity.py @@ -2,7 +2,7 @@ from homeassistant.const import ATTR_ATTRIBUTION from homeassistant.helpers.dispatcher import async_dispatcher_connect -from homeassistant.helpers.entity import Entity +from homeassistant.helpers.update_coordinator import CoordinatorEntity from .const import ( ATTRIBUTION, @@ -13,20 +13,14 @@ from .const import ( ) -class NexiaEntity(Entity): +class NexiaEntity(CoordinatorEntity): """Base class for nexia entities.""" def __init__(self, coordinator, name, unique_id): """Initialize the entity.""" - super().__init__() + super().__init__(coordinator) self._unique_id = unique_id self._name = name - self._coordinator = coordinator - - @property - def available(self): - """Return True if entity is available.""" - return self._coordinator.last_update_success @property def unique_id(self): @@ -45,17 +39,6 @@ class NexiaEntity(Entity): ATTR_ATTRIBUTION: ATTRIBUTION, } - @property - def should_poll(self): - """Return False, updates are controlled via coordinator.""" - return False - - async def async_added_to_hass(self): - """Subscribe to updates.""" - self.async_on_remove( - self._coordinator.async_add_listener(self.async_write_ha_state) - ) - class NexiaThermostatEntity(NexiaEntity): """Base class for nexia devices attached to a thermostat.""" diff --git a/homeassistant/components/nexia/scene.py b/homeassistant/components/nexia/scene.py index 1700de3f059..d3a6691d59e 100644 --- a/homeassistant/components/nexia/scene.py +++ b/homeassistant/components/nexia/scene.py @@ -57,6 +57,6 @@ class NexiaAutomationScene(NexiaEntity, Scene): await self.hass.async_add_executor_job(self._automation.activate) async def refresh_callback(_): - await self._coordinator.async_refresh() + await self.coordinator.async_refresh() async_call_later(self.hass, SCENE_ACTIVATION_TIME, refresh_callback)