Fix bond fan.turn_on with OFF speed (#39387)
This commit is contained in:
parent
7469f57a7b
commit
867d5088e3
2 changed files with 23 additions and 1 deletions
|
@ -1,4 +1,5 @@
|
||||||
"""Support for Bond fans."""
|
"""Support for Bond fans."""
|
||||||
|
import logging
|
||||||
import math
|
import math
|
||||||
from typing import Any, Callable, List, Optional
|
from typing import Any, Callable, List, Optional
|
||||||
|
|
||||||
|
@ -23,6 +24,8 @@ from .const import DOMAIN
|
||||||
from .entity import BondEntity
|
from .entity import BondEntity
|
||||||
from .utils import BondDevice, BondHub
|
from .utils import BondDevice, BondHub
|
||||||
|
|
||||||
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
|
@ -97,6 +100,8 @@ class BondFan(BondEntity, FanEntity):
|
||||||
|
|
||||||
async def async_set_speed(self, speed: str) -> None:
|
async def async_set_speed(self, speed: str) -> None:
|
||||||
"""Set the desired speed for the fan."""
|
"""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)
|
max_speed = self._device.props.get("max_speed", 3)
|
||||||
if speed == SPEED_LOW:
|
if speed == SPEED_LOW:
|
||||||
bond_speed = 1
|
bond_speed = 1
|
||||||
|
@ -111,8 +116,13 @@ class BondFan(BondEntity, FanEntity):
|
||||||
|
|
||||||
async def async_turn_on(self, speed: Optional[str] = None, **kwargs) -> None:
|
async def async_turn_on(self, speed: Optional[str] = None, **kwargs) -> None:
|
||||||
"""Turn on the fan."""
|
"""Turn on the fan."""
|
||||||
|
_LOGGER.debug("async_turn_on called with speed %s", speed)
|
||||||
|
|
||||||
if speed is not None:
|
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:
|
else:
|
||||||
await self._hub.bond.action(self._device.device_id, Action.turn_on())
|
await self._hub.bond.action(self._device.device_id, Action.turn_on())
|
||||||
|
|
||||||
|
|
|
@ -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())
|
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):
|
async def test_turn_off_fan(hass: core.HomeAssistant):
|
||||||
"""Tests that turn off command delegates to API."""
|
"""Tests that turn off command delegates to API."""
|
||||||
await setup_platform(
|
await setup_platform(
|
||||||
|
|
Loading…
Add table
Reference in a new issue