mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Address old review comments of Tasmota fan (#44112)
* Address review comments of Tasmota fan * Address review comment
This commit is contained in:
parent
9cc406fef9
commit
7084d6c650
@ -63,7 +63,7 @@ class TasmotaFan(
|
|||||||
@property
|
@property
|
||||||
def speed_list(self):
|
def speed_list(self):
|
||||||
"""Get the list of available speeds."""
|
"""Get the list of available speeds."""
|
||||||
return list(HA_TO_TASMOTA_SPEED_MAP.keys())
|
return list(HA_TO_TASMOTA_SPEED_MAP)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def supported_features(self):
|
def supported_features(self):
|
||||||
@ -72,6 +72,8 @@ class TasmotaFan(
|
|||||||
|
|
||||||
async def async_set_speed(self, speed):
|
async def async_set_speed(self, speed):
|
||||||
"""Set the speed of the fan."""
|
"""Set the speed of the fan."""
|
||||||
|
if speed not in HA_TO_TASMOTA_SPEED_MAP:
|
||||||
|
raise ValueError(f"Unsupported speed {speed}")
|
||||||
if speed == fan.SPEED_OFF:
|
if speed == fan.SPEED_OFF:
|
||||||
await self.async_turn_off()
|
await self.async_turn_off()
|
||||||
else:
|
else:
|
||||||
|
@ -7,6 +7,7 @@ from hatasmota.utils import (
|
|||||||
get_topic_tele_state,
|
get_topic_tele_state,
|
||||||
get_topic_tele_will,
|
get_topic_tele_will,
|
||||||
)
|
)
|
||||||
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components import fan
|
from homeassistant.components import fan
|
||||||
from homeassistant.components.tasmota.const import DEFAULT_PREFIX
|
from homeassistant.components.tasmota.const import DEFAULT_PREFIX
|
||||||
@ -152,6 +153,33 @@ async def test_sending_mqtt_commands(hass, mqtt_mock, setup_tasmota):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
async def test_invalid_fan_speed(hass, mqtt_mock, setup_tasmota):
|
||||||
|
"""Test the sending MQTT commands."""
|
||||||
|
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||||
|
config["if"] = 1
|
||||||
|
mac = config["mac"]
|
||||||
|
|
||||||
|
async_fire_mqtt_message(
|
||||||
|
hass,
|
||||||
|
f"{DEFAULT_PREFIX}/{mac}/config",
|
||||||
|
json.dumps(config),
|
||||||
|
)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
async_fire_mqtt_message(hass, "tasmota_49A3BC/tele/LWT", "Online")
|
||||||
|
state = hass.states.get("fan.tasmota")
|
||||||
|
assert state.state == STATE_OFF
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
mqtt_mock.async_publish.reset_mock()
|
||||||
|
|
||||||
|
# Set an unsupported speed and verify MQTT message is not sent
|
||||||
|
with pytest.raises(ValueError) as excinfo:
|
||||||
|
await common.async_set_speed(hass, "fan.tasmota", "no_such_speed")
|
||||||
|
assert "Unsupported speed no_such_speed" in str(excinfo.value)
|
||||||
|
mqtt_mock.async_publish.assert_not_called()
|
||||||
|
|
||||||
|
|
||||||
async def test_availability_when_connection_lost(
|
async def test_availability_when_connection_lost(
|
||||||
hass, mqtt_client_mock, mqtt_mock, setup_tasmota
|
hass, mqtt_client_mock, mqtt_mock, setup_tasmota
|
||||||
):
|
):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user