diff --git a/homeassistant/components/bond/fan.py b/homeassistant/components/bond/fan.py index 14a5f84c8b1e..19e345b7e230 100644 --- a/homeassistant/components/bond/fan.py +++ b/homeassistant/components/bond/fan.py @@ -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 diff --git a/tests/components/bond/test_fan.py b/tests/components/bond/test_fan.py index 0e0e980c39b4..1adea282a306 100644 --- a/tests/components/bond/test_fan.py +++ b/tests/components/bond/test_fan.py @@ -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(