From 867d5088e3385b87e938940f1c2d52f16776569b Mon Sep 17 00:00:00 2001 From: Eugene Prystupa Date: Sat, 29 Aug 2020 18:03:19 -0400 Subject: [PATCH] Fix bond fan.turn_on with OFF speed (#39387) --- homeassistant/components/bond/fan.py | 12 +++++++++++- tests/components/bond/test_fan.py | 12 ++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/bond/fan.py b/homeassistant/components/bond/fan.py index cb247b37309..14a5f84c8b1 100644 --- a/homeassistant/components/bond/fan.py +++ b/homeassistant/components/bond/fan.py @@ -1,4 +1,5 @@ """Support for Bond fans.""" +import logging import math from typing import Any, Callable, List, Optional @@ -23,6 +24,8 @@ from .const import DOMAIN from .entity import BondEntity from .utils import BondDevice, BondHub +_LOGGER = logging.getLogger(__name__) + async def async_setup_entry( hass: HomeAssistant, @@ -97,6 +100,8 @@ class BondFan(BondEntity, FanEntity): async def async_set_speed(self, speed: str) -> None: """Set the desired speed for the fan.""" + _LOGGER.debug("async_set_speed called with speed %s", speed) + max_speed = self._device.props.get("max_speed", 3) if speed == SPEED_LOW: bond_speed = 1 @@ -111,8 +116,13 @@ class BondFan(BondEntity, FanEntity): async def async_turn_on(self, speed: Optional[str] = None, **kwargs) -> None: """Turn on the fan.""" + _LOGGER.debug("async_turn_on called with speed %s", speed) + if speed is not None: - await self.async_set_speed(speed) + if speed == SPEED_OFF: + await self.async_turn_off() + else: + await self.async_set_speed(speed) else: await self._hub.bond.action(self._device.device_id, Action.turn_on()) diff --git a/tests/components/bond/test_fan.py b/tests/components/bond/test_fan.py index 72770817110..0e0e980c39b 100644 --- a/tests/components/bond/test_fan.py +++ b/tests/components/bond/test_fan.py @@ -144,6 +144,18 @@ async def test_turn_on_fan_without_speed(hass: core.HomeAssistant): mock_turn_on.assert_called_with("test-device-id", Action.turn_on()) +async def test_turn_on_fan_with_off_speed(hass: core.HomeAssistant): + """Tests that turn on 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 turn_fan_on(hass, "fan.name_1", fan.SPEED_OFF) + + 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(