Map bond fan speeds to standard HA speeds (#37808)
This commit is contained in:
1 parent
9e8e5c37f4
commit
95e72b4c4b
4 files changed
+88
-20
No files matched your search
@@ -1,4 +1,5 @@
|
||||
"""Support for Bond fans."""
|
||||
import math
|
||||
from typing import Any, Callable, List, Optional
|
||||
|
||||
from bond import DeviceTypes, Directions
|
||||
@@ -67,12 +68,15 @@ class BondFan(BondEntity, FanEntity):
|
||||
@property
|
||||
def speed(self) -> Optional[str]:
|
||||
"""Return the current speed."""
|
||||
if self._power is None:
|
||||
return None
|
||||
if self._power == 0:
|
||||
return SPEED_OFF
|
||||
if not self._power or not self._speed:
|
||||
return None
|
||||
|
||||
return self.speed_list[self._speed] if self._speed is not None else None
|
||||
# map 1..max_speed Bond speed to 1..3 HA speed
|
||||
max_speed = self._device.props.get("max_speed", 3)
|
||||
ha_speed = math.ceil(self._speed * (len(self.speed_list) - 1) / max_speed)
|
||||
return self.speed_list[ha_speed]
|
||||
|
||||
@property
|
||||
def speed_list(self) -> list:
|
||||
@@ -99,8 +103,14 @@ class BondFan(BondEntity, FanEntity):
|
||||
|
||||
def set_speed(self, speed: str) -> None:
|
||||
"""Set the desired speed for the fan."""
|
||||
speed_index = self.speed_list.index(speed)
|
||||
self._hub.bond.setSpeed(self._device.device_id, speed=speed_index)
|
||||
max_speed = self._device.props.get("max_speed", 3)
|
||||
if speed == SPEED_LOW:
|
||||
bond_speed = 1
|
||||
elif speed == SPEED_HIGH:
|
||||
bond_speed = max_speed
|
||||
else:
|
||||
bond_speed = math.ceil(max_speed / 2)
|
||||
self._hub.bond.setSpeed(self._device.device_id, speed=bond_speed)
|
||||
|
||||
def turn_on(self, speed: Optional[str] = None, **kwargs) -> None:
|
||||
"""Turn on the fan."""
|
||||
|
||||
@@ -8,9 +8,10 @@ from bond import Actions, Bond
|
||||
class BondDevice:
|
||||
"""Helper device class to hold ID and attributes together."""
|
||||
|
||||
def __init__(self, device_id: str, attrs: dict):
|
||||
def __init__(self, device_id: str, attrs: dict, props: dict):
|
||||
"""Create a helper device from ID and attributes returned by API."""
|
||||
self.device_id = device_id
|
||||
self.props = props
|
||||
self._attrs = attrs
|
||||
|
||||
@property
|
||||
@@ -67,7 +68,11 @@ class BondHub:
|
||||
"""Fetch all available devices using Bond API."""
|
||||
device_ids = self.bond.getDeviceIds()
|
||||
devices = [
|
||||
BondDevice(device_id, self.bond.getDevice(device_id))
|
||||
BondDevice(
|
||||
device_id,
|
||||
self.bond.getDevice(device_id),
|
||||
self.bond.getProperties(device_id),
|
||||
)
|
||||
for device_id in device_ids
|
||||
]
|
||||
return devices
|
||||
|
||||
Reference in new issue
Block a user