feat: add shade capabilities, velocity control, and cleanup
Add ShadeCapability lookup to replace hardcoded model string checks for tilt/tilt-only selection. Add velocity number entity (0–100) and pass velocity through all movement paths including open/close. Remove redundant device_info property overrides and deduplicate hex parsing.
This commit is contained in:
69
custom_components/hunterdouglas_powerview_ble/number.py
Normal file
69
custom_components/hunterdouglas_powerview_ble/number.py
Normal file
@@ -0,0 +1,69 @@
|
||||
"""Hunter Douglas PowerView velocity control."""
|
||||
|
||||
from homeassistant.components.bluetooth.passive_update_coordinator import (
|
||||
PassiveBluetoothCoordinatorEntity,
|
||||
)
|
||||
from homeassistant.components.number import NumberMode, RestoreNumber
|
||||
from homeassistant.const import EntityCategory
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.device_registry import format_mac
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from . import ConfigEntryType
|
||||
from .const import DOMAIN, LOGGER
|
||||
from .coordinator import PVCoordinator
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
_hass: HomeAssistant,
|
||||
config_entry: ConfigEntryType,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the velocity number entity."""
|
||||
|
||||
coordinator: PVCoordinator = config_entry.runtime_data
|
||||
async_add_entities([PowerViewVelocity(coordinator)])
|
||||
|
||||
|
||||
class PowerViewVelocity(
|
||||
PassiveBluetoothCoordinatorEntity[PVCoordinator], RestoreNumber
|
||||
): # type: ignore[reportIncompatibleVariableOverride]
|
||||
"""Number entity to control shade movement velocity."""
|
||||
|
||||
_attr_has_entity_name = True
|
||||
_attr_name = "Velocity"
|
||||
_attr_icon = "mdi:speedometer"
|
||||
_attr_mode = NumberMode.SLIDER
|
||||
_attr_native_min_value = 0
|
||||
_attr_native_max_value = 100
|
||||
_attr_native_step = 1
|
||||
_attr_entity_category = EntityCategory.CONFIG
|
||||
|
||||
def __init__(self, coordinator: PVCoordinator) -> None:
|
||||
"""Initialize the velocity entity."""
|
||||
self._coord = coordinator
|
||||
self._attr_device_info = self._coord.device_info
|
||||
self._attr_unique_id = (
|
||||
f"{DOMAIN}_{format_mac(self._coord.address)}_velocity"
|
||||
)
|
||||
super().__init__(coordinator)
|
||||
|
||||
@property
|
||||
def native_value(self) -> int:
|
||||
"""Return the current velocity value."""
|
||||
return self._coord.velocity
|
||||
|
||||
async def async_added_to_hass(self) -> None:
|
||||
"""Restore last known velocity on startup."""
|
||||
await super().async_added_to_hass()
|
||||
last_data = await self.async_get_last_number_data()
|
||||
if last_data and last_data.native_value is not None:
|
||||
self._coord.velocity = int(last_data.native_value)
|
||||
LOGGER.debug(
|
||||
"%s: restored velocity to %s", self._coord.name, self._coord.velocity
|
||||
)
|
||||
|
||||
async def async_set_native_value(self, value: float) -> None:
|
||||
"""Set the velocity value."""
|
||||
self._coord.velocity = int(value)
|
||||
self.async_write_ha_state()
|
||||
Reference in New Issue
Block a user