diff --git a/tests/components/tasmota/test_fan.py b/tests/components/tasmota/test_fan.py index a64c5e9c5e4..202a6a5386b 100644 --- a/tests/components/tasmota/test_fan.py +++ b/tests/components/tasmota/test_fan.py @@ -9,6 +9,7 @@ from hatasmota.utils import ( get_topic_tele_will, ) import pytest +from voluptuous import MultipleInvalid from homeassistant.components import fan from homeassistant.components.tasmota.const import DEFAULT_PREFIX @@ -51,46 +52,38 @@ async def test_controlling_state_via_mqtt(hass, mqtt_mock, setup_tasmota): async_fire_mqtt_message(hass, "tasmota_49A3BC/tele/LWT", "Online") state = hass.states.get("fan.tasmota") assert state.state == STATE_OFF - assert state.attributes["speed"] is None assert state.attributes["percentage"] is None - assert state.attributes["speed_list"] == ["off", "low", "medium", "high"] assert state.attributes["supported_features"] == fan.SUPPORT_SET_SPEED assert not state.attributes.get(ATTR_ASSUMED_STATE) async_fire_mqtt_message(hass, "tasmota_49A3BC/tele/STATE", '{"FanSpeed":1}') state = hass.states.get("fan.tasmota") assert state.state == STATE_ON - assert state.attributes["speed"] == "low" assert state.attributes["percentage"] == 33 async_fire_mqtt_message(hass, "tasmota_49A3BC/tele/STATE", '{"FanSpeed":2}') state = hass.states.get("fan.tasmota") assert state.state == STATE_ON - assert state.attributes["speed"] == "medium" assert state.attributes["percentage"] == 66 async_fire_mqtt_message(hass, "tasmota_49A3BC/tele/STATE", '{"FanSpeed":3}') state = hass.states.get("fan.tasmota") assert state.state == STATE_ON - assert state.attributes["speed"] == "high" assert state.attributes["percentage"] == 100 async_fire_mqtt_message(hass, "tasmota_49A3BC/tele/STATE", '{"FanSpeed":0}') state = hass.states.get("fan.tasmota") assert state.state == STATE_OFF - assert state.attributes["speed"] == "off" assert state.attributes["percentage"] == 0 async_fire_mqtt_message(hass, "tasmota_49A3BC/stat/RESULT", '{"FanSpeed":1}') state = hass.states.get("fan.tasmota") assert state.state == STATE_ON - assert state.attributes["speed"] == "low" assert state.attributes["percentage"] == 33 async_fire_mqtt_message(hass, "tasmota_49A3BC/stat/RESULT", '{"FanSpeed":0}') state = hass.states.get("fan.tasmota") assert state.state == STATE_OFF - assert state.attributes["speed"] == "off" assert state.attributes["percentage"] == 0 @@ -132,34 +125,6 @@ async def test_sending_mqtt_commands(hass, mqtt_mock, setup_tasmota): ) mqtt_mock.async_publish.reset_mock() - # Set speed and verify MQTT message is sent - await common.async_set_speed(hass, "fan.tasmota", fan.SPEED_OFF) - mqtt_mock.async_publish.assert_called_once_with( - "tasmota_49A3BC/cmnd/FanSpeed", "0", 0, False - ) - mqtt_mock.async_publish.reset_mock() - - # Set speed and verify MQTT message is sent - await common.async_set_speed(hass, "fan.tasmota", fan.SPEED_LOW) - mqtt_mock.async_publish.assert_called_once_with( - "tasmota_49A3BC/cmnd/FanSpeed", "1", 0, False - ) - mqtt_mock.async_publish.reset_mock() - - # Set speed and verify MQTT message is sent - await common.async_set_speed(hass, "fan.tasmota", fan.SPEED_MEDIUM) - mqtt_mock.async_publish.assert_called_once_with( - "tasmota_49A3BC/cmnd/FanSpeed", "2", 0, False - ) - mqtt_mock.async_publish.reset_mock() - - # Set speed and verify MQTT message is sent - await common.async_set_speed(hass, "fan.tasmota", fan.SPEED_HIGH) - mqtt_mock.async_publish.assert_called_once_with( - "tasmota_49A3BC/cmnd/FanSpeed", "3", 0, False - ) - mqtt_mock.async_publish.reset_mock() - # Set speed percentage and verify MQTT message is sent await common.async_set_percentage(hass, "fan.tasmota", 0) mqtt_mock.async_publish.assert_called_once_with( @@ -188,7 +153,7 @@ async def test_sending_mqtt_commands(hass, mqtt_mock, setup_tasmota): ) -async def test_invalid_fan_speed(hass, mqtt_mock, setup_tasmota): +async def test_invalid_fan_speed_percentage(hass, mqtt_mock, setup_tasmota): """Test the sending MQTT commands.""" config = copy.deepcopy(DEFAULT_CONFIG) config["if"] = 1 @@ -209,9 +174,9 @@ async def test_invalid_fan_speed(hass, mqtt_mock, setup_tasmota): 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 "no_such_speed" in str(excinfo.value) + with pytest.raises(MultipleInvalid) as excinfo: + await common.async_set_percentage(hass, "fan.tasmota", 101) + assert "value must be at most 100" in str(excinfo.value) mqtt_mock.async_publish.assert_not_called()