Update hunterdouglas_powerview to use CoordinatorEntity (#39463)
This commit is contained in:
parent
b57f33c41a
commit
9ec870c750
3 changed files with 7 additions and 19 deletions
|
@ -110,7 +110,6 @@ class PowerViewShade(ShadeEntity, CoverEntity):
|
|||
self._scheduled_transition_update = None
|
||||
self._room_name = room_data.get(room_id, {}).get(ROOM_NAME_UNICODE, "")
|
||||
self._current_cover_position = MIN_POSITION
|
||||
self._coordinator = coordinator
|
||||
|
||||
@property
|
||||
def device_state_attributes(self):
|
||||
|
@ -272,7 +271,7 @@ class PowerViewShade(ShadeEntity, CoverEntity):
|
|||
"""When entity is added to hass."""
|
||||
self._async_update_current_cover_position()
|
||||
self.async_on_remove(
|
||||
self._coordinator.async_add_listener(self._async_update_shade_from_group)
|
||||
self.coordinator.async_add_listener(self._async_update_shade_from_group)
|
||||
)
|
||||
|
||||
@callback
|
||||
|
@ -282,5 +281,5 @@ class PowerViewShade(ShadeEntity, CoverEntity):
|
|||
# If a transition in in progress
|
||||
# the data will be wrong
|
||||
return
|
||||
self._async_process_new_shade_data(self._coordinator.data[self._shade.id])
|
||||
self._async_process_new_shade_data(self.coordinator.data[self._shade.id])
|
||||
self.async_write_ha_state()
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
from aiopvapi.resources.shade import ATTR_TYPE
|
||||
|
||||
import homeassistant.helpers.device_registry as dr
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
|
||||
from .const import (
|
||||
DEVICE_FIRMWARE,
|
||||
|
@ -20,31 +20,20 @@ from .const import (
|
|||
)
|
||||
|
||||
|
||||
class HDEntity(Entity):
|
||||
class HDEntity(CoordinatorEntity):
|
||||
"""Base class for hunter douglas entities."""
|
||||
|
||||
def __init__(self, coordinator, device_info, unique_id):
|
||||
"""Initialize the entity."""
|
||||
super().__init__()
|
||||
self._coordinator = coordinator
|
||||
super().__init__(coordinator)
|
||||
self._unique_id = unique_id
|
||||
self._device_info = device_info
|
||||
|
||||
@property
|
||||
def available(self):
|
||||
"""Return True if entity is available."""
|
||||
return self._coordinator.last_update_success
|
||||
|
||||
@property
|
||||
def unique_id(self):
|
||||
"""Return the unique id."""
|
||||
return self._unique_id
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
"""Return False, updates are controlled via coordinator."""
|
||||
return False
|
||||
|
||||
@property
|
||||
def device_info(self):
|
||||
"""Return the device_info of the device."""
|
||||
|
|
|
@ -76,11 +76,11 @@ class PowerViewShadeBatterySensor(ShadeEntity):
|
|||
async def async_added_to_hass(self):
|
||||
"""When entity is added to hass."""
|
||||
self.async_on_remove(
|
||||
self._coordinator.async_add_listener(self._async_update_shade_from_group)
|
||||
self.coordinator.async_add_listener(self._async_update_shade_from_group)
|
||||
)
|
||||
|
||||
@callback
|
||||
def _async_update_shade_from_group(self):
|
||||
"""Update with new data from the coordinator."""
|
||||
self._shade.raw_data = self._coordinator.data[self._shade.id]
|
||||
self._shade.raw_data = self.coordinator.data[self._shade.id]
|
||||
self.async_write_ha_state()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue