Update nexia to use CoordinatorEntity (#39391)

Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
This commit is contained in:
J. Nick Koston 2020-08-30 07:57:02 -05:00 committed by GitHub
parent b3ec3d0baf
commit 854e33025b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 4 additions and 28 deletions

View File

@ -458,10 +458,3 @@ class NexiaZone(NexiaThermostatZoneEntity, ClimateEntity):
Update a single zone. Update a single zone.
""" """
dispatcher_send(self.hass, f"{SIGNAL_ZONE_UPDATE}-{self._zone.zone_id}") 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()

View File

@ -2,7 +2,7 @@
from homeassistant.const import ATTR_ATTRIBUTION from homeassistant.const import ATTR_ATTRIBUTION
from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity import Entity from homeassistant.helpers.update_coordinator import CoordinatorEntity
from .const import ( from .const import (
ATTRIBUTION, ATTRIBUTION,
@ -13,20 +13,14 @@ from .const import (
) )
class NexiaEntity(Entity): class NexiaEntity(CoordinatorEntity):
"""Base class for nexia entities.""" """Base class for nexia entities."""
def __init__(self, coordinator, name, unique_id): def __init__(self, coordinator, name, unique_id):
"""Initialize the entity.""" """Initialize the entity."""
super().__init__() super().__init__(coordinator)
self._unique_id = unique_id self._unique_id = unique_id
self._name = name self._name = name
self._coordinator = coordinator
@property
def available(self):
"""Return True if entity is available."""
return self._coordinator.last_update_success
@property @property
def unique_id(self): def unique_id(self):
@ -45,17 +39,6 @@ class NexiaEntity(Entity):
ATTR_ATTRIBUTION: ATTRIBUTION, 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): class NexiaThermostatEntity(NexiaEntity):
"""Base class for nexia devices attached to a thermostat.""" """Base class for nexia devices attached to a thermostat."""

View File

@ -57,6 +57,6 @@ class NexiaAutomationScene(NexiaEntity, Scene):
await self.hass.async_add_executor_job(self._automation.activate) await self.hass.async_add_executor_job(self._automation.activate)
async def refresh_callback(_): async def refresh_callback(_):
await self._coordinator.async_refresh() await self.coordinator.async_refresh()
async_call_later(self.hass, SCENE_ACTIVATION_TIME, refresh_callback) async_call_later(self.hass, SCENE_ACTIVATION_TIME, refresh_callback)