mirror of
https://github.com/home-assistant/core.git
synced 2025-07-26 22:57:17 +00:00
Update hunterdouglas_powerview to use CoordinatorEntity (#39463)
This commit is contained in:
parent
b57f33c41a
commit
9ec870c750
@ -110,7 +110,6 @@ class PowerViewShade(ShadeEntity, CoverEntity):
|
|||||||
self._scheduled_transition_update = None
|
self._scheduled_transition_update = None
|
||||||
self._room_name = room_data.get(room_id, {}).get(ROOM_NAME_UNICODE, "")
|
self._room_name = room_data.get(room_id, {}).get(ROOM_NAME_UNICODE, "")
|
||||||
self._current_cover_position = MIN_POSITION
|
self._current_cover_position = MIN_POSITION
|
||||||
self._coordinator = coordinator
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_state_attributes(self):
|
def device_state_attributes(self):
|
||||||
@ -272,7 +271,7 @@ class PowerViewShade(ShadeEntity, CoverEntity):
|
|||||||
"""When entity is added to hass."""
|
"""When entity is added to hass."""
|
||||||
self._async_update_current_cover_position()
|
self._async_update_current_cover_position()
|
||||||
self.async_on_remove(
|
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
|
@callback
|
||||||
@ -282,5 +281,5 @@ class PowerViewShade(ShadeEntity, CoverEntity):
|
|||||||
# If a transition in in progress
|
# If a transition in in progress
|
||||||
# the data will be wrong
|
# the data will be wrong
|
||||||
return
|
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()
|
self.async_write_ha_state()
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
from aiopvapi.resources.shade import ATTR_TYPE
|
from aiopvapi.resources.shade import ATTR_TYPE
|
||||||
|
|
||||||
import homeassistant.helpers.device_registry as dr
|
import homeassistant.helpers.device_registry as dr
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
DEVICE_FIRMWARE,
|
DEVICE_FIRMWARE,
|
||||||
@ -20,31 +20,20 @@ from .const import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class HDEntity(Entity):
|
class HDEntity(CoordinatorEntity):
|
||||||
"""Base class for hunter douglas entities."""
|
"""Base class for hunter douglas entities."""
|
||||||
|
|
||||||
def __init__(self, coordinator, device_info, unique_id):
|
def __init__(self, coordinator, device_info, unique_id):
|
||||||
"""Initialize the entity."""
|
"""Initialize the entity."""
|
||||||
super().__init__()
|
super().__init__(coordinator)
|
||||||
self._coordinator = coordinator
|
|
||||||
self._unique_id = unique_id
|
self._unique_id = unique_id
|
||||||
self._device_info = device_info
|
self._device_info = device_info
|
||||||
|
|
||||||
@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):
|
||||||
"""Return the unique id."""
|
"""Return the unique id."""
|
||||||
return self._unique_id
|
return self._unique_id
|
||||||
|
|
||||||
@property
|
|
||||||
def should_poll(self):
|
|
||||||
"""Return False, updates are controlled via coordinator."""
|
|
||||||
return False
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_info(self):
|
def device_info(self):
|
||||||
"""Return the device_info of the device."""
|
"""Return the device_info of the device."""
|
||||||
|
@ -76,11 +76,11 @@ class PowerViewShadeBatterySensor(ShadeEntity):
|
|||||||
async def async_added_to_hass(self):
|
async def async_added_to_hass(self):
|
||||||
"""When entity is added to hass."""
|
"""When entity is added to hass."""
|
||||||
self.async_on_remove(
|
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
|
@callback
|
||||||
def _async_update_shade_from_group(self):
|
def _async_update_shade_from_group(self):
|
||||||
"""Update with new data from the coordinator."""
|
"""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()
|
self.async_write_ha_state()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user