mirror of
https://github.com/home-assistant/core.git
synced 2025-07-13 00:07:10 +00:00
Reuse existing coordinator entity update in Plugwise platforms (#66079)
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
parent
c93d389544
commit
41a4d40b71
@ -99,11 +99,11 @@ class PlugwiseBinarySensorEntity(PlugwiseEntity, BinarySensorEntity):
|
||||
).lstrip()
|
||||
|
||||
@callback
|
||||
def _async_process_data(self) -> None:
|
||||
"""Update the entity."""
|
||||
def _handle_coordinator_update(self) -> None:
|
||||
"""Handle updated data from the coordinator."""
|
||||
if not (data := self.coordinator.data.devices.get(self._dev_id)):
|
||||
LOGGER.error("Received no data for device %s", self._dev_id)
|
||||
self.async_write_ha_state()
|
||||
super()._handle_coordinator_update()
|
||||
return
|
||||
|
||||
self._attr_is_on = data["binary_sensors"].get(self.entity_description.key)
|
||||
@ -113,15 +113,15 @@ class PlugwiseBinarySensorEntity(PlugwiseEntity, BinarySensorEntity):
|
||||
if self.entity_description.key == "slave_boiler_state":
|
||||
self._attr_icon = FLAME_ICON if self._attr_is_on else IDLE_ICON
|
||||
|
||||
self.async_write_ha_state()
|
||||
super()._handle_coordinator_update()
|
||||
|
||||
|
||||
class PlugwiseNotifyBinarySensorEntity(PlugwiseBinarySensorEntity):
|
||||
"""Representation of a Plugwise Notification binary_sensor."""
|
||||
|
||||
@callback
|
||||
def _async_process_data(self) -> None:
|
||||
"""Update the entity."""
|
||||
def _handle_coordinator_update(self) -> None:
|
||||
"""Handle updated data from the coordinator."""
|
||||
notify = self.coordinator.data.gateway["notifications"]
|
||||
|
||||
self._attr_extra_state_attributes = {}
|
||||
@ -144,4 +144,4 @@ class PlugwiseNotifyBinarySensorEntity(PlugwiseBinarySensorEntity):
|
||||
msg
|
||||
)
|
||||
|
||||
self.async_write_ha_state()
|
||||
super()._handle_coordinator_update()
|
||||
|
@ -150,8 +150,8 @@ class PlugwiseClimateEntity(PlugwiseEntity, ClimateEntity):
|
||||
LOGGER.error("Error while communicating to device")
|
||||
|
||||
@callback
|
||||
def _async_process_data(self) -> None:
|
||||
"""Update the data for this climate device."""
|
||||
def _handle_coordinator_update(self) -> None:
|
||||
"""Handle updated data from the coordinator."""
|
||||
data = self.coordinator.data.devices[self._dev_id]
|
||||
heater_central_data = self.coordinator.data.devices[
|
||||
self.coordinator.data.gateway["heater_id"]
|
||||
@ -192,4 +192,4 @@ class PlugwiseClimateEntity(PlugwiseEntity, ClimateEntity):
|
||||
"selected_schema": data.get("selected_schedule"),
|
||||
}
|
||||
|
||||
self.async_write_ha_state()
|
||||
super()._handle_coordinator_update()
|
||||
|
@ -2,7 +2,6 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from homeassistant.const import ATTR_NAME, ATTR_VIA_DEVICE, CONF_HOST
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
|
||||
@ -49,12 +48,5 @@ class PlugwiseEntity(CoordinatorEntity[PlugwiseData]):
|
||||
|
||||
async def async_added_to_hass(self) -> None:
|
||||
"""Subscribe to updates."""
|
||||
self._async_process_data()
|
||||
self.async_on_remove(
|
||||
self.coordinator.async_add_listener(self._async_process_data)
|
||||
)
|
||||
|
||||
@callback
|
||||
def _async_process_data(self) -> None:
|
||||
"""Interpret and process API data."""
|
||||
raise NotImplementedError
|
||||
self._handle_coordinator_update()
|
||||
await super().async_added_to_hass()
|
||||
|
@ -346,15 +346,15 @@ class PlugwiseSensorEnity(PlugwiseEntity, SensorEntity):
|
||||
).lstrip()
|
||||
|
||||
@callback
|
||||
def _async_process_data(self) -> None:
|
||||
"""Update the entity."""
|
||||
def _handle_coordinator_update(self) -> None:
|
||||
"""Handle updated data from the coordinator."""
|
||||
if not (data := self.coordinator.data.devices.get(self._dev_id)):
|
||||
LOGGER.error("Received no data for device %s", self._dev_id)
|
||||
self.async_write_ha_state()
|
||||
super()._handle_coordinator_update()
|
||||
return
|
||||
|
||||
self._attr_native_value = data["sensors"].get(self.entity_description.key)
|
||||
self.async_write_ha_state()
|
||||
super()._handle_coordinator_update()
|
||||
|
||||
|
||||
class PlugwiseAuxSensorEntity(PlugwiseSensorEnity):
|
||||
@ -364,11 +364,11 @@ class PlugwiseAuxSensorEntity(PlugwiseSensorEnity):
|
||||
_heating_state = False
|
||||
|
||||
@callback
|
||||
def _async_process_data(self) -> None:
|
||||
"""Update the entity."""
|
||||
def _handle_coordinator_update(self) -> None:
|
||||
"""Handle updated data from the coordinator."""
|
||||
if not (data := self.coordinator.data.devices.get(self._dev_id)):
|
||||
LOGGER.error("Received no data for device %s", self._dev_id)
|
||||
self.async_write_ha_state()
|
||||
super()._handle_coordinator_update()
|
||||
return
|
||||
|
||||
if data.get("heating_state") is not None:
|
||||
@ -385,4 +385,4 @@ class PlugwiseAuxSensorEntity(PlugwiseSensorEnity):
|
||||
self._attr_native_value = "cooling"
|
||||
self._attr_icon = COOL_ICON
|
||||
|
||||
self.async_write_ha_state()
|
||||
super()._handle_coordinator_update()
|
||||
|
@ -87,12 +87,12 @@ class PlugwiseSwitchEntity(PlugwiseEntity, SwitchEntity):
|
||||
self.async_write_ha_state()
|
||||
|
||||
@callback
|
||||
def _async_process_data(self) -> None:
|
||||
"""Update the data from the Plugs."""
|
||||
def _handle_coordinator_update(self) -> None:
|
||||
"""Handle updated data from the coordinator."""
|
||||
if not (data := self.coordinator.data.devices.get(self._dev_id)):
|
||||
LOGGER.error("Received no data for device %s", self._dev_id)
|
||||
self.async_write_ha_state()
|
||||
super()._handle_coordinator_update()
|
||||
return
|
||||
|
||||
self._attr_is_on = data["switches"].get("relay")
|
||||
self.async_write_ha_state()
|
||||
super()._handle_coordinator_update()
|
||||
|
Loading…
x
Reference in New Issue
Block a user