mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 14:17:45 +00:00
Update nexia to use CoordinatorEntity (#39391)
Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
This commit is contained in:
parent
b3ec3d0baf
commit
854e33025b
@ -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()
|
|
||||||
|
@ -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."""
|
||||||
|
@ -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)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user