Improve deCONZ fan platform handling unsupported commands (#41779)
* Improve handling unsupported commands * Raise valueerror on unsupported speed * Fix lintingpull/41784/head
parent
7f9db59209
commit
267d97e80e
|
@ -105,7 +105,11 @@ class DeconzFan(DeconzDevice, FanEntity):
|
|||
|
||||
async def async_set_speed(self, speed: str) -> None:
|
||||
"""Set the speed of the fan."""
|
||||
if speed not in SPEEDS:
|
||||
raise ValueError(f"Unsupported speed {speed}")
|
||||
|
||||
data = {"speed": SPEEDS[speed]}
|
||||
|
||||
await self._device.async_set_state(data)
|
||||
|
||||
async def async_turn_on(self, speed: str = None, **kwargs) -> None:
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
"""deCONZ fan platform tests."""
|
||||
from copy import deepcopy
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.components import deconz
|
||||
from homeassistant.components.deconz.gateway import get_gateway_from_config_entry
|
||||
import homeassistant.components.fan as fan
|
||||
|
@ -165,7 +167,20 @@ async def test_fans(hass):
|
|||
await hass.async_block_till_done()
|
||||
set_callback.assert_called_with("put", "/lights/1/state", json={"speed": 0})
|
||||
|
||||
# Verify that an unsupported speed gets converted to default speed "medium"
|
||||
# Service set fan speed to unsupported value
|
||||
|
||||
with patch.object(
|
||||
ceiling_fan_device, "_request", return_value=True
|
||||
) as set_callback, pytest.raises(ValueError):
|
||||
await hass.services.async_call(
|
||||
fan.DOMAIN,
|
||||
fan.SERVICE_SET_SPEED,
|
||||
{"entity_id": "fan.ceiling_fan", fan.ATTR_SPEED: "bad value"},
|
||||
blocking=True,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
# Events with an unsupported speed gets converted to default speed "medium"
|
||||
|
||||
state_changed_event = {
|
||||
"t": "event",
|
||||
|
|
Loading…
Reference in New Issue