Fix a problem with set_speed(off) when direct HA API for set speed is called (#39488)
This commit is contained in:
parent
e1c7c3fdb2
commit
b71cbd2033
2 changed files with 25 additions and 0 deletions
|
@ -102,6 +102,10 @@ class BondFan(BondEntity, FanEntity):
|
|||
"""Set the desired speed for the fan."""
|
||||
_LOGGER.debug("async_set_speed called with speed %s", speed)
|
||||
|
||||
if speed == SPEED_OFF:
|
||||
await self.async_turn_off()
|
||||
return
|
||||
|
||||
max_speed = self._device.props.get("max_speed", 3)
|
||||
if speed == SPEED_LOW:
|
||||
bond_speed = 1
|
||||
|
|
|
@ -8,11 +8,14 @@ from homeassistant import core
|
|||
from homeassistant.components import fan
|
||||
from homeassistant.components.fan import (
|
||||
ATTR_DIRECTION,
|
||||
ATTR_SPEED,
|
||||
ATTR_SPEED_LIST,
|
||||
DIRECTION_FORWARD,
|
||||
DIRECTION_REVERSE,
|
||||
DOMAIN as FAN_DOMAIN,
|
||||
SERVICE_SET_DIRECTION,
|
||||
SERVICE_SET_SPEED,
|
||||
SPEED_OFF,
|
||||
)
|
||||
from homeassistant.const import ATTR_ENTITY_ID, SERVICE_TURN_OFF, SERVICE_TURN_ON
|
||||
from homeassistant.helpers.entity_registry import EntityRegistry
|
||||
|
@ -156,6 +159,24 @@ async def test_turn_on_fan_with_off_speed(hass: core.HomeAssistant):
|
|||
mock_turn_off.assert_called_with("test-device-id", Action.turn_off())
|
||||
|
||||
|
||||
async def test_set_speed_off(hass: core.HomeAssistant):
|
||||
"""Tests that set_speed(off) command delegates to turn off API."""
|
||||
await setup_platform(
|
||||
hass, FAN_DOMAIN, ceiling_fan("name-1"), bond_device_id="test-device-id"
|
||||
)
|
||||
|
||||
with patch_bond_action() as mock_turn_off, patch_bond_device_state():
|
||||
await hass.services.async_call(
|
||||
FAN_DOMAIN,
|
||||
SERVICE_SET_SPEED,
|
||||
service_data={ATTR_ENTITY_ID: "fan.name_1", ATTR_SPEED: SPEED_OFF},
|
||||
blocking=True,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
mock_turn_off.assert_called_with("test-device-id", Action.turn_off())
|
||||
|
||||
|
||||
async def test_turn_off_fan(hass: core.HomeAssistant):
|
||||
"""Tests that turn off command delegates to API."""
|
||||
await setup_platform(
|
||||
|
|
Loading…
Add table
Reference in a new issue