mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Fix bond fans without defined max_speed (#38382)
This commit is contained in:
parent
00a4bcff3d
commit
a00aa6740e
@ -75,7 +75,7 @@ class BondFan(BondEntity, FanEntity):
|
||||
return None
|
||||
|
||||
# map 1..max_speed Bond speed to 1..3 HA speed
|
||||
max_speed = self._device.props.get("max_speed", 3)
|
||||
max_speed = max(self._device.props.get("max_speed", 3), self._speed)
|
||||
ha_speed = math.ceil(self._speed * (len(self.speed_list) - 1) / max_speed)
|
||||
return self.speed_list[ha_speed]
|
||||
|
||||
|
@ -49,9 +49,11 @@ async def setup_platform(
|
||||
hass: core.HomeAssistant,
|
||||
platform: str,
|
||||
discovered_device: Dict[str, Any],
|
||||
*,
|
||||
bond_device_id: str = "bond-device-id",
|
||||
props: Dict[str, Any] = None,
|
||||
bond_version: Dict[str, Any] = None,
|
||||
props: Dict[str, Any] = None,
|
||||
state: Dict[str, Any] = None,
|
||||
):
|
||||
"""Set up the specified Bond platform."""
|
||||
mock_entry = MockConfigEntry(
|
||||
@ -65,9 +67,11 @@ async def setup_platform(
|
||||
return_value=[bond_device_id]
|
||||
), patch_bond_device(
|
||||
return_value=discovered_device
|
||||
), patch_bond_device_state(), patch_bond_device_properties(
|
||||
), patch_bond_device_properties(
|
||||
return_value=props
|
||||
), patch_bond_device_state():
|
||||
), patch_bond_device_state(
|
||||
return_value=state
|
||||
):
|
||||
assert await async_setup_component(hass, BOND_DOMAIN, {})
|
||||
await hass.async_block_till_done()
|
||||
|
||||
|
@ -96,6 +96,20 @@ async def test_non_standard_speed_list(hass: core.HomeAssistant):
|
||||
)
|
||||
|
||||
|
||||
async def test_fan_speed_with_no_max_seed(hass: core.HomeAssistant):
|
||||
"""Tests that fans without max speed (increase/decrease controls) map speed to HA standard."""
|
||||
await setup_platform(
|
||||
hass,
|
||||
FAN_DOMAIN,
|
||||
ceiling_fan("name-1"),
|
||||
bond_device_id="test-device-id",
|
||||
props={"no": "max_speed"},
|
||||
state={"power": 1, "speed": 14},
|
||||
)
|
||||
|
||||
assert hass.states.get("fan.name_1").attributes["speed"] == fan.SPEED_HIGH
|
||||
|
||||
|
||||
async def test_turn_on_fan_with_speed(hass: core.HomeAssistant):
|
||||
"""Tests that turn on command delegates to set speed API."""
|
||||
await setup_platform(
|
||||
|
Loading…
x
Reference in New Issue
Block a user