mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 06:07:17 +00:00
Allow processing data in CoordinatorEntity before writing state (#40926)
This commit is contained in:
parent
187fec9a0c
commit
22b4ad6308
@ -14,6 +14,7 @@ from homeassistant.components.climate.const import (
|
|||||||
SUPPORT_TARGET_TEMPERATURE,
|
SUPPORT_TARGET_TEMPERATURE,
|
||||||
)
|
)
|
||||||
from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS, TEMP_FAHRENHEIT
|
from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS, TEMP_FAHRENHEIT
|
||||||
|
from homeassistant.core import callback
|
||||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||||
|
|
||||||
from .const import CONF_SUPPORTED_MODES, DATA_COORDINATOR, DATA_INFO, DOMAIN
|
from .const import CONF_SUPPORTED_MODES, DATA_COORDINATOR, DATA_INFO, DOMAIN
|
||||||
@ -66,15 +67,10 @@ class CoolmasterClimate(CoordinatorEntity, ClimateEntity):
|
|||||||
self._hvac_modes = supported_modes
|
self._hvac_modes = supported_modes
|
||||||
self._info = info
|
self._info = info
|
||||||
|
|
||||||
def _refresh_from_coordinator(self):
|
@callback
|
||||||
|
def _handle_coordinator_update(self):
|
||||||
self._unit = self.coordinator.data[self._unit_id]
|
self._unit = self.coordinator.data[self._unit_id]
|
||||||
self.async_write_ha_state()
|
super()._handle_coordinator_update()
|
||||||
|
|
||||||
async def async_added_to_hass(self):
|
|
||||||
"""When entity is added to hass."""
|
|
||||||
self.async_on_remove(
|
|
||||||
self.coordinator.async_add_listener(self._refresh_from_coordinator)
|
|
||||||
)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_info(self):
|
def device_info(self):
|
||||||
|
@ -213,9 +213,14 @@ class CoordinatorEntity(entity.Entity):
|
|||||||
"""When entity is added to hass."""
|
"""When entity is added to hass."""
|
||||||
await super().async_added_to_hass()
|
await super().async_added_to_hass()
|
||||||
self.async_on_remove(
|
self.async_on_remove(
|
||||||
self.coordinator.async_add_listener(self.async_write_ha_state)
|
self.coordinator.async_add_listener(self._handle_coordinator_update)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@callback
|
||||||
|
def _handle_coordinator_update(self) -> None:
|
||||||
|
"""Handle updated data from the coordinator."""
|
||||||
|
self.async_write_ha_state()
|
||||||
|
|
||||||
async def async_update(self) -> None:
|
async def async_update(self) -> None:
|
||||||
"""Update the entity.
|
"""Update the entity.
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user