Remove MQTT Fan legacy speeds (#54768)

* Remove MQTT Fan legacy speeds

* deprecated attibutes are not disruptive
This commit is contained in:
Jan Bouwhuis 2021-08-24 11:21:35 +02:00 committed by GitHub
parent 6cace8d8a1
commit 5bb9aa8f3d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 700 deletions

View File

@ -10,7 +10,6 @@ from homeassistant.components.fan import (
ATTR_OSCILLATING,
ATTR_PERCENTAGE,
ATTR_PRESET_MODE,
ATTR_SPEED,
SPEED_HIGH,
SPEED_LOW,
SPEED_MEDIUM,
@ -19,7 +18,6 @@ from homeassistant.components.fan import (
SUPPORT_PRESET_MODE,
SUPPORT_SET_SPEED,
FanEntity,
speed_list_without_preset_modes,
)
from homeassistant.const import (
CONF_NAME,
@ -34,8 +32,6 @@ from homeassistant.helpers.reload import async_setup_reload_service
from homeassistant.helpers.typing import ConfigType
from homeassistant.util.percentage import (
int_states_in_range,
ordered_list_item_to_percentage,
percentage_to_ordered_list_item,
percentage_to_ranged_value,
ranged_value_to_percentage,
)
@ -102,23 +98,12 @@ MQTT_FAN_ATTRIBUTES_BLOCKED = frozenset(
fan.ATTR_PERCENTAGE,
fan.ATTR_PRESET_MODE,
fan.ATTR_PRESET_MODES,
fan.ATTR_SPEED_LIST,
fan.ATTR_SPEED,
}
)
_LOGGER = logging.getLogger(__name__)
def valid_fan_speed_configuration(config):
"""Validate that the fan speed configuration is valid, throws if it isn't."""
if config.get(CONF_SPEED_COMMAND_TOPIC) and not speed_list_without_preset_modes(
config.get(CONF_SPEED_LIST)
):
raise ValueError("No valid speeds configured")
return config
def valid_speed_range_configuration(config):
"""Validate that the fan speed_range configuration is valid, throws if it isn't."""
if config.get(CONF_SPEED_RANGE_MIN) == 0:
@ -138,7 +123,7 @@ def valid_preset_mode_configuration(config):
PLATFORM_SCHEMA = vol.All(
# CONF_SPEED_COMMAND_TOPIC, CONF_SPEED_LIST, CONF_SPEED_STATE_TOPIC, CONF_SPEED_VALUE_TEMPLATE and
# Speeds SPEED_LOW, SPEED_MEDIUM, SPEED_HIGH SPEED_OFF,
# are deprecated, support will be removed after a quarter (2021.7)
# are deprecated, support will be removed with release 2021.9
cv.deprecated(CONF_PAYLOAD_HIGH_SPEED),
cv.deprecated(CONF_PAYLOAD_LOW_SPEED),
cv.deprecated(CONF_PAYLOAD_MEDIUM_SPEED),
@ -203,7 +188,6 @@ PLATFORM_SCHEMA = vol.All(
vol.Optional(CONF_STATE_VALUE_TEMPLATE): cv.template,
}
).extend(MQTT_ENTITY_COMMON_SCHEMA.schema),
valid_fan_speed_configuration,
valid_speed_range_configuration,
valid_preset_mode_configuration,
)
@ -240,8 +224,6 @@ class MqttFan(MqttEntity, FanEntity):
def __init__(self, hass, config, config_entry, discovery_data):
"""Initialize the MQTT fan."""
self._state = False
# self._speed will be removed after a quarter (2021.7)
self._speed = None
self._percentage = None
self._preset_mode = None
self._oscillation = None
@ -255,10 +237,6 @@ class MqttFan(MqttEntity, FanEntity):
self._optimistic_oscillation = None
self._optimistic_percentage = None
self._optimistic_preset_mode = None
self._optimistic_speed = None
self._legacy_speeds_list = []
self._legacy_speeds_list_no_off = []
MqttEntity.__init__(self, hass, config, config_entry, discovery_data)
@ -282,8 +260,6 @@ class MqttFan(MqttEntity, FanEntity):
CONF_PERCENTAGE_COMMAND_TOPIC,
CONF_PRESET_MODE_STATE_TOPIC,
CONF_PRESET_MODE_COMMAND_TOPIC,
CONF_SPEED_STATE_TOPIC,
CONF_SPEED_COMMAND_TOPIC,
CONF_OSCILLATION_STATE_TOPIC,
CONF_OSCILLATION_COMMAND_TOPIC,
)
@ -292,8 +268,6 @@ class MqttFan(MqttEntity, FanEntity):
CONF_STATE: config.get(CONF_STATE_VALUE_TEMPLATE),
ATTR_PERCENTAGE: config.get(CONF_PERCENTAGE_VALUE_TEMPLATE),
ATTR_PRESET_MODE: config.get(CONF_PRESET_MODE_VALUE_TEMPLATE),
# ATTR_SPEED is deprecated in the schema, support will be removed after a quarter (2021.7)
ATTR_SPEED: config.get(CONF_SPEED_VALUE_TEMPLATE),
ATTR_OSCILLATING: config.get(CONF_OSCILLATION_VALUE_TEMPLATE),
}
self._command_templates = {
@ -307,21 +281,9 @@ class MqttFan(MqttEntity, FanEntity):
"STATE_OFF": config[CONF_PAYLOAD_OFF],
"OSCILLATE_ON_PAYLOAD": config[CONF_PAYLOAD_OSCILLATION_ON],
"OSCILLATE_OFF_PAYLOAD": config[CONF_PAYLOAD_OSCILLATION_OFF],
# The use of legacy speeds is deprecated in the schema, support will be removed after a quarter (2021.7)
"SPEED_LOW": config[CONF_PAYLOAD_LOW_SPEED],
"SPEED_MEDIUM": config[CONF_PAYLOAD_MEDIUM_SPEED],
"SPEED_HIGH": config[CONF_PAYLOAD_HIGH_SPEED],
"SPEED_OFF": config[CONF_PAYLOAD_OFF_SPEED],
"PERCENTAGE_RESET": config[CONF_PAYLOAD_RESET_PERCENTAGE],
"PRESET_MODE_RESET": config[CONF_PAYLOAD_RESET_PRESET_MODE],
}
# The use of legacy speeds is deprecated in the schema, support will be removed after a quarter (2021.7)
self._feature_legacy_speeds = not self._topic[CONF_SPEED_COMMAND_TOPIC] is None
if self._feature_legacy_speeds:
self._legacy_speeds_list = config[CONF_SPEED_LIST]
self._legacy_speeds_list_no_off = speed_list_without_preset_modes(
self._legacy_speeds_list
)
self._feature_percentage = CONF_PERCENTAGE_COMMAND_TOPIC in config
self._feature_preset_mode = CONF_PRESET_MODE_COMMAND_TOPIC in config
@ -330,10 +292,11 @@ class MqttFan(MqttEntity, FanEntity):
else:
self._preset_modes = []
if self._feature_percentage:
self._speed_count = min(int_states_in_range(self._speed_range), 100)
else:
self._speed_count = len(self._legacy_speeds_list_no_off) or 100
self._speed_count = (
min(int_states_in_range(self._speed_range), 100)
if self._feature_percentage
else 100
)
optimistic = config[CONF_OPTIMISTIC]
self._optimistic = optimistic or self._topic[CONF_STATE_TOPIC] is None
@ -346,16 +309,13 @@ class MqttFan(MqttEntity, FanEntity):
self._optimistic_preset_mode = (
optimistic or self._topic[CONF_PRESET_MODE_STATE_TOPIC] is None
)
self._optimistic_speed = (
optimistic or self._topic[CONF_SPEED_STATE_TOPIC] is None
)
self._supported_features = 0
self._supported_features |= (
self._topic[CONF_OSCILLATION_COMMAND_TOPIC] is not None
and SUPPORT_OSCILLATE
)
if self._feature_percentage or self._feature_legacy_speeds:
if self._feature_percentage:
self._supported_features |= SUPPORT_SET_SPEED
if self._feature_preset_mode:
self._supported_features |= SUPPORT_PRESET_MODE
@ -368,7 +328,7 @@ class MqttFan(MqttEntity, FanEntity):
tpl.hass = self.hass
tpl_dict[key] = tpl.async_render_with_possible_json_value
async def _subscribe_topics(self): # noqa: C901
async def _subscribe_topics(self):
"""(Re)Subscribe to topics."""
topics = {}
@ -405,7 +365,6 @@ class MqttFan(MqttEntity, FanEntity):
return
if rendered_percentage_payload == self._payload["PERCENTAGE_RESET"]:
self._percentage = None
self._speed = None
self.async_write_ha_state()
return
try:
@ -471,51 +430,6 @@ class MqttFan(MqttEntity, FanEntity):
}
self._preset_mode = None
# The use of legacy speeds is deprecated in the schema, support will be removed after a quarter (2021.7)
@callback
@log_messages(self.hass, self.entity_id)
def speed_received(msg):
"""Handle new received MQTT message for the speed."""
speed_payload = self._value_templates[ATTR_SPEED](msg.payload)
if speed_payload == self._payload["SPEED_LOW"]:
speed = SPEED_LOW
elif speed_payload == self._payload["SPEED_MEDIUM"]:
speed = SPEED_MEDIUM
elif speed_payload == self._payload["SPEED_HIGH"]:
speed = SPEED_HIGH
elif speed_payload == self._payload["SPEED_OFF"]:
speed = SPEED_OFF
else:
speed = None
if speed and speed in self._legacy_speeds_list:
self._speed = speed
else:
_LOGGER.warning(
"'%s' received on topic %s. '%s' is not a valid speed",
msg.payload,
msg.topic,
speed,
)
return
if speed in self._legacy_speeds_list_no_off:
self._percentage = ordered_list_item_to_percentage(
self._legacy_speeds_list_no_off, speed
)
elif speed == SPEED_OFF:
self._percentage = 0
self.async_write_ha_state()
if self._topic[CONF_SPEED_STATE_TOPIC] is not None:
topics[CONF_SPEED_STATE_TOPIC] = {
"topic": self._topic[CONF_SPEED_STATE_TOPIC],
"msg_callback": speed_received,
"qos": self._config[CONF_QOS],
}
self._speed = SPEED_OFF
@callback
@log_messages(self.hass, self.entity_id)
def oscillation_received(msg):
@ -552,12 +466,6 @@ class MqttFan(MqttEntity, FanEntity):
"""Return true if device is on."""
return self._state
# The use of legacy speeds is deprecated in the schema, support will be removed after a quarter (2021.7)
@property
def _implemented_speed(self) -> bool:
"""Return true if speed has been implemented."""
return self._feature_legacy_speeds
@property
def percentage(self):
"""Return the current percentage."""
@ -573,22 +481,11 @@ class MqttFan(MqttEntity, FanEntity):
"""Get the list of available preset modes."""
return self._preset_modes
# The speed_list property is deprecated in the schema, support will be removed after a quarter (2021.7)
@property
def speed_list(self) -> list:
"""Get the list of available speeds."""
return self._legacy_speeds_list_no_off
@property
def supported_features(self) -> int:
"""Flag supported features."""
return self._supported_features
@property
def speed(self):
"""Return the current speed."""
return self._speed
@property
def speed_count(self) -> int:
"""Return the number of speeds the fan supports."""
@ -623,9 +520,6 @@ class MqttFan(MqttEntity, FanEntity):
await self.async_set_percentage(percentage)
if preset_mode:
await self.async_set_preset_mode(preset_mode)
# The speed attribute deprecated in the schema, support will be removed after a quarter (2021.7)
if speed and not percentage and not preset_mode:
await self.async_set_speed(speed)
if self._optimistic:
self._state = True
self.async_write_ha_state()
@ -656,26 +550,13 @@ class MqttFan(MqttEntity, FanEntity):
percentage_to_ranged_value(self._speed_range, percentage)
)
mqtt_payload = self._command_templates[ATTR_PERCENTAGE](percentage_payload)
# Legacy are deprecated in the schema, support will be removed after a quarter (2021.7)
if self._feature_legacy_speeds:
if percentage:
await self.async_set_speed(
percentage_to_ordered_list_item(
self._legacy_speeds_list_no_off,
percentage,
)
)
elif SPEED_OFF in self._legacy_speeds_list:
await self.async_set_speed(SPEED_OFF)
if self._feature_percentage:
mqtt.async_publish(
self.hass,
self._topic[CONF_PERCENTAGE_COMMAND_TOPIC],
mqtt_payload,
self._config[CONF_QOS],
self._config[CONF_RETAIN],
)
mqtt.async_publish(
self.hass,
self._topic[CONF_PERCENTAGE_COMMAND_TOPIC],
mqtt_payload,
self._config[CONF_QOS],
self._config[CONF_RETAIN],
)
if self._optimistic_percentage:
self._percentage = percentage
@ -704,39 +585,6 @@ class MqttFan(MqttEntity, FanEntity):
self._preset_mode = preset_mode
self.async_write_ha_state()
# async_set_speed is deprecated, support will be removed after a quarter (2021.7)
async def async_set_speed(self, speed: str) -> None:
"""Set the speed of the fan.
This method is a coroutine.
"""
speed_payload = None
if speed in self._legacy_speeds_list:
if speed == SPEED_LOW:
speed_payload = self._payload["SPEED_LOW"]
elif speed == SPEED_MEDIUM:
speed_payload = self._payload["SPEED_MEDIUM"]
elif speed == SPEED_HIGH:
speed_payload = self._payload["SPEED_HIGH"]
else:
speed_payload = self._payload["SPEED_OFF"]
else:
_LOGGER.warning("'%s' is not a valid speed", speed)
return
if speed_payload:
mqtt.async_publish(
self.hass,
self._topic[CONF_SPEED_COMMAND_TOPIC],
speed_payload,
self._config[CONF_QOS],
self._config[CONF_RETAIN],
)
if self._optimistic_speed and speed_payload:
self._speed = speed
self.async_write_ha_state()
async def async_oscillate(self, oscillating: bool) -> None:
"""Set oscillation.

View File

@ -77,9 +77,6 @@ async def test_controlling_state_via_topic(hass, mqtt_mock, caplog):
"payload_on": "StAtE_On",
"oscillation_state_topic": "oscillation-state-topic",
"oscillation_command_topic": "oscillation-command-topic",
# use of speeds is deprecated, support will be removed after a quarter (2021.7)
"speed_state_topic": "speed-state-topic",
"speed_command_topic": "speed-command-topic",
"payload_oscillation_off": "OsC_OfF",
"payload_oscillation_on": "OsC_On",
"percentage_state_topic": "percentage-state-topic",
@ -96,12 +93,6 @@ async def test_controlling_state_via_topic(hass, mqtt_mock, caplog):
],
"speed_range_min": 1,
"speed_range_max": 200,
# use of speeds is deprecated, support will be removed after a quarter (2021.7)
"speeds": ["off", "low"],
"payload_off_speed": "speed_OfF",
"payload_low_speed": "speed_lOw",
"payload_medium_speed": "speed_mEdium",
"payload_high_speed": "speed_High",
"payload_reset_percentage": "rEset_percentage",
"payload_reset_preset_mode": "rEset_preset_mode",
}
@ -180,34 +171,11 @@ async def test_controlling_state_via_topic(hass, mqtt_mock, caplog):
assert "not a valid preset mode" in caplog.text
caplog.clear()
# use of speeds is deprecated, support will be removed after a quarter (2021.7)
assert state.attributes.get("speed") == fan.SPEED_OFF
async_fire_mqtt_message(hass, "speed-state-topic", "speed_lOw")
state = hass.states.get("fan.test")
assert state.attributes.get("speed") == fan.SPEED_LOW
async_fire_mqtt_message(hass, "speed-state-topic", "speed_mEdium")
assert "not a valid speed" in caplog.text
caplog.clear()
async_fire_mqtt_message(hass, "speed-state-topic", "speed_High")
assert "not a valid speed" in caplog.text
caplog.clear()
async_fire_mqtt_message(hass, "speed-state-topic", "speed_OfF")
state = hass.states.get("fan.test")
assert state.attributes.get("speed") == fan.SPEED_OFF
async_fire_mqtt_message(hass, "percentage-state-topic", "rEset_percentage")
state = hass.states.get("fan.test")
assert state.attributes.get(fan.ATTR_PERCENTAGE) is None
assert state.attributes.get(fan.ATTR_SPEED) is None
async_fire_mqtt_message(hass, "speed-state-topic", "speed_very_high")
assert "not a valid speed" in caplog.text
caplog.clear()
async def test_controlling_state_via_topic_with_different_speed_range(
hass, mqtt_mock, caplog
@ -284,9 +252,6 @@ async def test_controlling_state_via_topic_no_percentage_topics(
"name": "test",
"state_topic": "state-topic",
"command_topic": "command-topic",
# use of speeds is deprecated, support will be removed after a quarter (2021.7)
"speed_state_topic": "speed-state-topic",
"speed_command_topic": "speed-command-topic",
"preset_mode_state_topic": "preset-mode-state-topic",
"preset_mode_command_topic": "preset-mode-command-topic",
"preset_modes": [
@ -296,8 +261,6 @@ async def test_controlling_state_via_topic_no_percentage_topics(
"eco",
"breeze",
],
# use of speeds is deprecated, support will be removed after a quarter (2021.7)
"speeds": ["off", "low", "medium"],
}
},
)
@ -311,22 +274,16 @@ async def test_controlling_state_via_topic_no_percentage_topics(
state = hass.states.get("fan.test")
assert state.attributes.get("preset_mode") == "smart"
assert state.attributes.get(fan.ATTR_PERCENTAGE) is None
# use of speeds is deprecated, support will be removed after a quarter (2021.7)
assert state.attributes.get("speed") == fan.SPEED_OFF
async_fire_mqtt_message(hass, "preset-mode-state-topic", "auto")
state = hass.states.get("fan.test")
assert state.attributes.get("preset_mode") == "auto"
assert state.attributes.get(fan.ATTR_PERCENTAGE) is None
# use of speeds is deprecated, support will be removed after a quarter (2021.7)
assert state.attributes.get("speed") == fan.SPEED_OFF
async_fire_mqtt_message(hass, "preset-mode-state-topic", "whoosh")
state = hass.states.get("fan.test")
assert state.attributes.get("preset_mode") == "whoosh"
assert state.attributes.get(fan.ATTR_PERCENTAGE) is None
# use of speeds is deprecated, support will be removed after a quarter (2021.7)
assert state.attributes.get("speed") == fan.SPEED_OFF
async_fire_mqtt_message(hass, "preset-mode-state-topic", "medium")
assert "not a valid preset mode" in caplog.text
@ -336,25 +293,6 @@ async def test_controlling_state_via_topic_no_percentage_topics(
assert "not a valid preset mode" in caplog.text
caplog.clear()
# use of speeds is deprecated, support will be removed after a quarter (2021.7)
async_fire_mqtt_message(hass, "speed-state-topic", "medium")
state = hass.states.get("fan.test")
assert state.attributes.get("preset_mode") == "whoosh"
assert state.attributes.get(fan.ATTR_PERCENTAGE) == 100
assert state.attributes.get("speed") == fan.SPEED_MEDIUM
async_fire_mqtt_message(hass, "speed-state-topic", "low")
state = hass.states.get("fan.test")
assert state.attributes.get("preset_mode") == "whoosh"
assert state.attributes.get(fan.ATTR_PERCENTAGE) == 50
assert state.attributes.get("speed") == fan.SPEED_LOW
async_fire_mqtt_message(hass, "speed-state-topic", "off")
state = hass.states.get("fan.test")
assert state.attributes.get("preset_mode") == "whoosh"
assert state.attributes.get(fan.ATTR_PERCENTAGE) == 0
assert state.attributes.get("speed") == fan.SPEED_OFF
async def test_controlling_state_via_topic_and_json_message(hass, mqtt_mock, caplog):
"""Test the controlling state via topic and JSON message (percentage mode)."""
@ -558,22 +496,13 @@ async def test_sending_mqtt_commands_and_optimistic(hass, mqtt_mock, caplog):
"oscillation_command_topic": "oscillation-command-topic",
"payload_oscillation_off": "OsC_OfF",
"payload_oscillation_on": "OsC_On",
# use of speeds is deprecated, support will be removed after a quarter (2021.7)
"speed_command_topic": "speed-command-topic",
"percentage_command_topic": "percentage-command-topic",
"preset_mode_command_topic": "preset-mode-command-topic",
# use of speeds is deprecated, support will be removed after a quarter (2021.7)
"speeds": ["off", "low", "medium"],
"preset_modes": [
"whoosh",
"breeze",
"silent",
],
# use of speeds is deprecated, support will be removed after a quarter (2021.7)
"payload_off_speed": "speed_OfF",
"payload_low_speed": "speed_lOw",
"payload_medium_speed": "speed_mEdium",
"payload_high_speed": "speed_High",
}
},
)
@ -625,10 +554,8 @@ async def test_sending_mqtt_commands_and_optimistic(hass, mqtt_mock, caplog):
await common.async_set_percentage(hass, "fan.test", 101)
await common.async_set_percentage(hass, "fan.test", 100)
assert mqtt_mock.async_publish.call_count == 2
mqtt_mock.async_publish.assert_any_call("percentage-command-topic", "100", 0, False)
mqtt_mock.async_publish.assert_any_call(
"speed-command-topic", "speed_mEdium", 0, False
mqtt_mock.async_publish.assert_called_once_with(
"percentage-command-topic", "100", 0, False
)
mqtt_mock.async_publish.reset_mock()
state = hass.states.get("fan.test")
@ -636,29 +563,18 @@ async def test_sending_mqtt_commands_and_optimistic(hass, mqtt_mock, caplog):
assert state.attributes.get(ATTR_ASSUMED_STATE)
await common.async_set_percentage(hass, "fan.test", 0)
assert mqtt_mock.async_publish.call_count == 2
mqtt_mock.async_publish.assert_any_call("percentage-command-topic", "0", 0, False)
# use of speeds is deprecated, support will be removed after a quarter (2021.7)
mqtt_mock.async_publish.assert_any_call(
"speed-command-topic", "speed_OfF", 0, False
mqtt_mock.async_publish.assert_called_once_with(
"percentage-command-topic", "0", 0, False
)
mqtt_mock.async_publish.reset_mock()
state = hass.states.get("fan.test")
assert state.attributes.get(fan.ATTR_PERCENTAGE) == 0
# use of speeds is deprecated, support will be removed after a quarter (2021.7)
assert state.attributes.get(fan.ATTR_SPEED) == fan.SPEED_OFF
assert state.attributes.get(ATTR_ASSUMED_STATE)
# use of speeds is deprecated, support will be removed after a quarter (2021.7)
await common.async_set_preset_mode(hass, "fan.test", "low")
assert "not a valid preset mode" in caplog.text
caplog.clear()
# use of speeds is deprecated, support will be removed after a quarter (2021.7)
await common.async_set_preset_mode(hass, "fan.test", "medium")
assert "not a valid preset mode" in caplog.text
caplog.clear()
await common.async_set_preset_mode(hass, "fan.test", "whoosh")
mqtt_mock.async_publish.assert_called_once_with(
"preset-mode-command-topic", "whoosh", 0, False
@ -686,41 +602,6 @@ async def test_sending_mqtt_commands_and_optimistic(hass, mqtt_mock, caplog):
assert state.attributes.get(fan.ATTR_PRESET_MODE) == "silent"
assert state.attributes.get(ATTR_ASSUMED_STATE)
# use of speeds is deprecated, support will be removed after a quarter (2021.7)
await common.async_set_speed(hass, "fan.test", fan.SPEED_LOW)
mqtt_mock.async_publish.assert_called_once_with(
"speed-command-topic", "speed_lOw", 0, False
)
mqtt_mock.async_publish.reset_mock()
state = hass.states.get("fan.test")
assert state.state == STATE_OFF
assert state.attributes.get(ATTR_ASSUMED_STATE)
# use of speeds is deprecated, support will be removed after a quarter (2021.7)
await common.async_set_speed(hass, "fan.test", fan.SPEED_MEDIUM)
mqtt_mock.async_publish.assert_called_once_with(
"speed-command-topic", "speed_mEdium", 0, False
)
mqtt_mock.async_publish.reset_mock()
state = hass.states.get("fan.test")
assert state.state == STATE_OFF
assert state.attributes.get(ATTR_ASSUMED_STATE)
# use of speeds is deprecated, support will be removed after a quarter (2021.7)
await common.async_set_speed(hass, "fan.test", fan.SPEED_HIGH)
assert "not a valid speed" in caplog.text
caplog.clear()
# use of speeds is deprecated, support will be removed after a quarter (2021.7)
await common.async_set_speed(hass, "fan.test", fan.SPEED_OFF)
mqtt_mock.async_publish.assert_called_once_with(
"speed-command-topic", "speed_OfF", 0, False
)
mqtt_mock.async_publish.reset_mock()
state = hass.states.get("fan.test")
assert state.state == STATE_OFF
assert state.attributes.get(ATTR_ASSUMED_STATE)
async def test_sending_mqtt_commands_with_alternate_speed_range(hass, mqtt_mock):
"""Test the controlling state via topic using an alternate speed range."""
@ -888,7 +769,6 @@ async def test_sending_mqtt_commands_and_optimistic_no_legacy(hass, mqtt_mock, c
mqtt_mock.async_publish.reset_mock()
state = hass.states.get("fan.test")
assert state.attributes.get(fan.ATTR_PERCENTAGE) == 0
assert state.attributes.get(fan.ATTR_SPEED) is None
assert state.attributes.get(ATTR_ASSUMED_STATE)
await common.async_set_preset_mode(hass, "fan.test", "low")
@ -1028,7 +908,6 @@ async def test_sending_mqtt_command_templates_(hass, mqtt_mock, caplog):
mqtt_mock.async_publish.reset_mock()
state = hass.states.get("fan.test")
assert state.attributes.get(fan.ATTR_PERCENTAGE) == 0
assert state.attributes.get(fan.ATTR_SPEED) is None
assert state.attributes.get(ATTR_ASSUMED_STATE)
await common.async_set_preset_mode(hass, "fan.test", "low")
@ -1111,13 +990,8 @@ async def test_sending_mqtt_commands_and_optimistic_no_percentage_topic(
"platform": "mqtt",
"name": "test",
"command_topic": "command-topic",
# use of speeds is deprecated, support will be removed after a quarter (2021.7)
"speed_state_topic": "speed-state-topic",
"speed_command_topic": "speed-command-topic",
"preset_mode_command_topic": "preset-mode-command-topic",
"preset_mode_state_topic": "preset-mode-state-topic",
# use of speeds is deprecated, support will be removed after a quarter (2021.7)
"speeds": ["off", "low", "medium"],
"preset_modes": [
"whoosh",
"breeze",
@ -1133,32 +1007,6 @@ async def test_sending_mqtt_commands_and_optimistic_no_percentage_topic(
assert state.state == STATE_OFF
assert state.attributes.get(ATTR_ASSUMED_STATE)
with pytest.raises(MultipleInvalid):
await common.async_set_percentage(hass, "fan.test", -1)
with pytest.raises(MultipleInvalid):
await common.async_set_percentage(hass, "fan.test", 101)
await common.async_set_percentage(hass, "fan.test", 100)
mqtt_mock.async_publish.assert_any_call("speed-command-topic", "medium", 0, False)
mqtt_mock.async_publish.reset_mock()
state = hass.states.get("fan.test")
assert state.attributes.get(fan.ATTR_PERCENTAGE) == 100
assert state.attributes.get(ATTR_ASSUMED_STATE)
await common.async_set_percentage(hass, "fan.test", 0)
# use of speeds is deprecated, support will be removed after a quarter (2021.7)
mqtt_mock.async_publish.assert_any_call("speed-command-topic", "off", 0, False)
mqtt_mock.async_publish.reset_mock()
state = hass.states.get("fan.test")
assert state.attributes.get(fan.ATTR_PERCENTAGE) == 0
assert state.attributes.get(ATTR_ASSUMED_STATE)
# use of speeds is deprecated, support will be removed after a quarter (2021.7)
await common.async_set_preset_mode(hass, "fan.test", "low")
assert "not a valid preset mode" in caplog.text
caplog.clear()
await common.async_set_preset_mode(hass, "fan.test", "medium")
assert "not a valid preset mode" in caplog.text
caplog.clear()
@ -1190,185 +1038,6 @@ async def test_sending_mqtt_commands_and_optimistic_no_percentage_topic(
assert state.attributes.get(fan.ATTR_PRESET_MODE) is None
assert state.attributes.get(ATTR_ASSUMED_STATE)
# use of speeds is deprecated, support will be removed after a quarter (2021.7)
await common.async_set_speed(hass, "fan.test", fan.SPEED_LOW)
mqtt_mock.async_publish.assert_called_once_with(
"speed-command-topic", "low", 0, False
)
mqtt_mock.async_publish.reset_mock()
state = hass.states.get("fan.test")
assert state.state == STATE_OFF
assert state.attributes.get(ATTR_ASSUMED_STATE)
await common.async_set_speed(hass, "fan.test", fan.SPEED_MEDIUM)
mqtt_mock.async_publish.assert_called_once_with(
"speed-command-topic", "medium", 0, False
)
mqtt_mock.async_publish.reset_mock()
state = hass.states.get("fan.test")
assert state.state == STATE_OFF
assert state.attributes.get(ATTR_ASSUMED_STATE)
await common.async_set_speed(hass, "fan.test", fan.SPEED_HIGH)
assert "not a valid speed" in caplog.text
caplog.clear()
await common.async_set_speed(hass, "fan.test", fan.SPEED_OFF)
mqtt_mock.async_publish.assert_any_call("speed-command-topic", "off", 0, False)
mqtt_mock.async_publish.reset_mock()
state = hass.states.get("fan.test")
assert state.state == STATE_OFF
assert state.attributes.get(ATTR_ASSUMED_STATE)
await common.async_turn_on(hass, "fan.test", speed="medium")
assert mqtt_mock.async_publish.call_count == 2
mqtt_mock.async_publish.assert_any_call("command-topic", "ON", 0, False)
# use of speeds is deprecated, support will be removed after a quarter (2021.7)
mqtt_mock.async_publish.assert_any_call("speed-command-topic", "medium", 0, False)
mqtt_mock.async_publish.reset_mock()
state = hass.states.get("fan.test")
assert state.state == STATE_ON
assert state.attributes.get(ATTR_ASSUMED_STATE)
await common.async_turn_off(hass, "fan.test")
mqtt_mock.async_publish.assert_called_once_with("command-topic", "OFF", 0, False)
mqtt_mock.async_publish.reset_mock()
state = hass.states.get("fan.test")
assert state.state == STATE_OFF
assert state.attributes.get(ATTR_ASSUMED_STATE)
# use of speeds is deprecated, support will be removed after a quarter (2021.7)
await common.async_turn_on(hass, "fan.test", speed="high")
assert mqtt_mock.async_publish.call_count == 2
mqtt_mock.async_publish.assert_any_call("command-topic", "ON", 0, False)
mqtt_mock.async_publish.assert_any_call(
"preset-mode-command-topic", "high", 0, False
)
mqtt_mock.async_publish.reset_mock()
state = hass.states.get("fan.test")
assert state.state == STATE_ON
assert state.attributes.get(ATTR_ASSUMED_STATE)
await common.async_turn_off(hass, "fan.test")
mqtt_mock.async_publish.assert_called_once_with("command-topic", "OFF", 0, False)
mqtt_mock.async_publish.reset_mock()
state = hass.states.get("fan.test")
assert state.state == STATE_OFF
assert state.attributes.get(ATTR_ASSUMED_STATE)
# use of speeds is deprecated, support will be removed after a quarter (2021.7)
async def test_sending_mqtt_commands_and_optimistic_legacy_speeds_only(
hass, mqtt_mock, caplog
):
"""Test optimistic mode without state topics with legacy speeds."""
assert await async_setup_component(
hass,
fan.DOMAIN,
{
fan.DOMAIN: {
"platform": "mqtt",
"name": "test",
"command_topic": "command-topic",
"speed_state_topic": "speed-state-topic",
"speed_command_topic": "speed-command-topic",
"speeds": ["off", "low", "medium", "high"],
}
},
)
await hass.async_block_till_done()
state = hass.states.get("fan.test")
assert state.state == STATE_OFF
assert state.attributes.get(ATTR_ASSUMED_STATE)
await common.async_set_percentage(hass, "fan.test", 100)
mqtt_mock.async_publish.assert_any_call("speed-command-topic", "high", 0, False)
mqtt_mock.async_publish.reset_mock()
state = hass.states.get("fan.test")
assert state.attributes.get(fan.ATTR_PERCENTAGE) == 100
assert state.attributes.get(fan.ATTR_SPEED) == "off"
assert state.attributes.get(ATTR_ASSUMED_STATE)
await common.async_set_percentage(hass, "fan.test", 0)
mqtt_mock.async_publish.assert_any_call("speed-command-topic", "off", 0, False)
mqtt_mock.async_publish.reset_mock()
state = hass.states.get("fan.test")
assert state.attributes.get(fan.ATTR_PERCENTAGE) == 0
assert state.attributes.get(ATTR_ASSUMED_STATE)
await common.async_set_preset_mode(hass, "fan.test", "low")
assert "not a valid preset mode" in caplog.text
caplog.clear()
await common.async_set_speed(hass, "fan.test", fan.SPEED_LOW)
mqtt_mock.async_publish.assert_called_once_with(
"speed-command-topic", "low", 0, False
)
mqtt_mock.async_publish.reset_mock()
state = hass.states.get("fan.test")
assert state.state == STATE_OFF
assert state.attributes.get(ATTR_ASSUMED_STATE)
await common.async_set_speed(hass, "fan.test", fan.SPEED_MEDIUM)
mqtt_mock.async_publish.assert_called_once_with(
"speed-command-topic", "medium", 0, False
)
mqtt_mock.async_publish.reset_mock()
state = hass.states.get("fan.test")
assert state.state == STATE_OFF
assert state.attributes.get(ATTR_ASSUMED_STATE)
await common.async_set_speed(hass, "fan.test", fan.SPEED_HIGH)
mqtt_mock.async_publish.assert_called_once_with(
"speed-command-topic", "high", 0, False
)
mqtt_mock.async_publish.reset_mock()
state = hass.states.get("fan.test")
assert state.state == STATE_OFF
assert state.attributes.get(ATTR_ASSUMED_STATE)
await common.async_set_speed(hass, "fan.test", fan.SPEED_OFF)
mqtt_mock.async_publish.assert_called_once_with(
"speed-command-topic", "off", 0, False
)
mqtt_mock.async_publish.reset_mock()
state = hass.states.get("fan.test")
assert state.state == STATE_OFF
assert state.attributes.get(ATTR_ASSUMED_STATE)
await common.async_turn_on(hass, "fan.test", speed="medium")
assert mqtt_mock.async_publish.call_count == 2
mqtt_mock.async_publish.assert_any_call("command-topic", "ON", 0, False)
mqtt_mock.async_publish.assert_any_call("speed-command-topic", "medium", 0, False)
mqtt_mock.async_publish.reset_mock()
state = hass.states.get("fan.test")
assert state.state == STATE_ON
assert state.attributes.get(ATTR_ASSUMED_STATE)
await common.async_turn_off(hass, "fan.test")
mqtt_mock.async_publish.assert_called_once_with("command-topic", "OFF", 0, False)
mqtt_mock.async_publish.reset_mock()
state = hass.states.get("fan.test")
assert state.state == STATE_OFF
assert state.attributes.get(ATTR_ASSUMED_STATE)
await common.async_turn_on(hass, "fan.test", speed="off")
assert mqtt_mock.async_publish.call_count == 2
mqtt_mock.async_publish.assert_any_call("command-topic", "ON", 0, False)
mqtt_mock.async_publish.assert_any_call("speed-command-topic", "off", 0, False)
mqtt_mock.async_publish.reset_mock()
state = hass.states.get("fan.test")
assert state.state == STATE_ON
assert state.attributes.get(ATTR_ASSUMED_STATE)
await common.async_turn_off(hass, "fan.test")
mqtt_mock.async_publish.assert_called_once_with("command-topic", "OFF", 0, False)
mqtt_mock.async_publish.reset_mock()
state = hass.states.get("fan.test")
assert state.state == STATE_OFF
assert state.attributes.get(ATTR_ASSUMED_STATE)
async def test_sending_mqtt_commands_and_explicit_optimistic(hass, mqtt_mock, caplog):
"""Test optimistic mode with state topic and turn on attributes."""
@ -1381,17 +1050,12 @@ async def test_sending_mqtt_commands_and_explicit_optimistic(hass, mqtt_mock, ca
"name": "test",
"state_topic": "state-topic",
"command_topic": "command-topic",
# use of speeds is deprecated, support will be removed after a quarter (2021.7)
"speed_state_topic": "speed-state-topic",
"speed_command_topic": "speed-command-topic",
"oscillation_state_topic": "oscillation-state-topic",
"oscillation_command_topic": "oscillation-command-topic",
"percentage_state_topic": "percentage-state-topic",
"percentage_command_topic": "percentage-command-topic",
"preset_mode_command_topic": "preset-mode-command-topic",
"preset_mode_state_topic": "preset-mode-state-topic",
# use of speeds is deprecated, support will be removed after a quarter (2021.7)
"speeds": ["off", "low", "medium"],
"preset_modes": [
"whoosh",
"breeze",
@ -1421,30 +1085,10 @@ async def test_sending_mqtt_commands_and_explicit_optimistic(hass, mqtt_mock, ca
assert state.state == STATE_OFF
assert state.attributes.get(ATTR_ASSUMED_STATE)
await common.async_turn_on(hass, "fan.test", speed=fan.SPEED_MEDIUM)
assert mqtt_mock.async_publish.call_count == 3
mqtt_mock.async_publish.assert_any_call("command-topic", "ON", 0, False)
# use of speeds is deprecated, support will be removed after a quarter (2021.7)
mqtt_mock.async_publish.assert_any_call("speed-command-topic", "medium", 0, False)
mqtt_mock.async_publish.assert_any_call("percentage-command-topic", "100", 0, False)
mqtt_mock.async_publish.reset_mock()
state = hass.states.get("fan.test")
assert state.state == STATE_ON
assert state.attributes.get(ATTR_ASSUMED_STATE)
await common.async_turn_off(hass, "fan.test")
mqtt_mock.async_publish.assert_called_once_with("command-topic", "OFF", 0, False)
mqtt_mock.async_publish.reset_mock()
state = hass.states.get("fan.test")
assert state.state == STATE_OFF
assert state.attributes.get(ATTR_ASSUMED_STATE)
await common.async_turn_on(hass, "fan.test", percentage=25)
assert mqtt_mock.async_publish.call_count == 3
assert mqtt_mock.async_publish.call_count == 2
mqtt_mock.async_publish.assert_any_call("command-topic", "ON", 0, False)
mqtt_mock.async_publish.assert_any_call("percentage-command-topic", "25", 0, False)
# use of speeds is deprecated, support will be removed after a quarter (2021.7)
mqtt_mock.async_publish.assert_any_call("speed-command-topic", "low", 0, False)
mqtt_mock.async_publish.reset_mock()
state = hass.states.get("fan.test")
assert state.state == STATE_ON
@ -1457,7 +1101,6 @@ async def test_sending_mqtt_commands_and_explicit_optimistic(hass, mqtt_mock, ca
assert state.state == STATE_OFF
assert state.attributes.get(ATTR_ASSUMED_STATE)
# use of speeds is deprecated, support will be removed after a quarter (2021.7)
with pytest.raises(NotValidPresetModeError):
await common.async_turn_on(hass, "fan.test", preset_mode="auto")
@ -1525,11 +1168,9 @@ async def test_sending_mqtt_commands_and_explicit_optimistic(hass, mqtt_mock, ca
assert state.attributes.get(ATTR_ASSUMED_STATE)
await common.async_turn_on(hass, "fan.test", percentage=50)
assert mqtt_mock.async_publish.call_count == 3
assert mqtt_mock.async_publish.call_count == 2
mqtt_mock.async_publish.assert_any_call("command-topic", "ON", 0, False)
mqtt_mock.async_publish.assert_any_call("percentage-command-topic", "50", 0, False)
# use of speeds is deprecated, support will be removed after a quarter (2021.7)
mqtt_mock.async_publish.assert_any_call("speed-command-topic", "low", 0, False)
mqtt_mock.async_publish.reset_mock()
state = hass.states.get("fan.test")
assert state.state == STATE_ON
@ -1552,40 +1193,36 @@ async def test_sending_mqtt_commands_and_explicit_optimistic(hass, mqtt_mock, ca
assert state.attributes.get(ATTR_ASSUMED_STATE)
await common.async_set_percentage(hass, "fan.test", 33)
assert mqtt_mock.async_publish.call_count == 2
mqtt_mock.async_publish.assert_any_call("percentage-command-topic", "33", 0, False)
# use of speeds is deprecated, support will be removed after a quarter (2021.7)
mqtt_mock.async_publish.assert_any_call("speed-command-topic", "low", 0, False)
mqtt_mock.async_publish.assert_called_once_with(
"percentage-command-topic", "33", 0, False
)
mqtt_mock.async_publish.reset_mock()
state = hass.states.get("fan.test")
assert state.state == STATE_OFF
assert state.attributes.get(ATTR_ASSUMED_STATE)
await common.async_set_percentage(hass, "fan.test", 50)
assert mqtt_mock.async_publish.call_count == 2
mqtt_mock.async_publish.assert_any_call("percentage-command-topic", "50", 0, False)
# use of speeds is deprecated, support will be removed after a quarter (2021.7)
mqtt_mock.async_publish.assert_any_call("speed-command-topic", "low", 0, False)
mqtt_mock.async_publish.assert_called_once_with(
"percentage-command-topic", "50", 0, False
)
mqtt_mock.async_publish.reset_mock()
state = hass.states.get("fan.test")
assert state.state == STATE_OFF
assert state.attributes.get(ATTR_ASSUMED_STATE)
await common.async_set_percentage(hass, "fan.test", 100)
assert mqtt_mock.async_publish.call_count == 2
mqtt_mock.async_publish.assert_any_call("percentage-command-topic", "100", 0, False)
# use of speeds is deprecated, support will be removed after a quarter (2021.7)
mqtt_mock.async_publish.assert_any_call("speed-command-topic", "medium", 0, False)
mqtt_mock.async_publish.assert_called_once_with(
"percentage-command-topic", "100", 0, False
)
mqtt_mock.async_publish.reset_mock()
state = hass.states.get("fan.test")
assert state.state == STATE_OFF
assert state.attributes.get(ATTR_ASSUMED_STATE)
await common.async_set_percentage(hass, "fan.test", 0)
assert mqtt_mock.async_publish.call_count == 2
mqtt_mock.async_publish.assert_any_call("percentage-command-topic", "0", 0, False)
# use of speeds is deprecated, support will be removed after a quarter (2021.7)
mqtt_mock.async_publish.assert_any_call("speed-command-topic", "off", 0, False)
mqtt_mock.async_publish.assert_called_once_with(
"percentage-command-topic", "0", 0, False
)
mqtt_mock.async_publish.reset_mock()
state = hass.states.get("fan.test")
assert state.state == STATE_OFF
@ -1629,33 +1266,6 @@ async def test_sending_mqtt_commands_and_explicit_optimistic(hass, mqtt_mock, ca
assert state.state == STATE_OFF
assert state.attributes.get(ATTR_ASSUMED_STATE)
# use of speeds is deprecated, support will be removed after a quarter (2021.7)
await common.async_set_speed(hass, "fan.test", fan.SPEED_MEDIUM)
mqtt_mock.async_publish.assert_called_once_with(
"speed-command-topic", "medium", 0, False
)
mqtt_mock.async_publish.reset_mock()
state = hass.states.get("fan.test")
assert state.state == STATE_OFF
assert state.attributes.get(ATTR_ASSUMED_STATE)
await common.async_set_speed(hass, "fan.test", fan.SPEED_HIGH)
assert "not a valid speed" in caplog.text
caplog.clear()
await common.async_set_speed(hass, "fan.test", fan.SPEED_OFF)
mqtt_mock.async_publish.assert_called_once_with(
"speed-command-topic", "off", 0, False
)
mqtt_mock.async_publish.reset_mock()
state = hass.states.get("fan.test")
assert state.state == STATE_OFF
assert state.attributes.get(ATTR_ASSUMED_STATE)
await common.async_set_speed(hass, "fan.test", "cUsToM")
assert "not a valid speed" in caplog.text
caplog.clear()
async def test_attributes(hass, mqtt_mock, caplog):
"""Test attributes."""
@ -1668,8 +1278,6 @@ async def test_attributes(hass, mqtt_mock, caplog):
"name": "test",
"command_topic": "command-topic",
"oscillation_command_topic": "oscillation-command-topic",
# use of speeds is deprecated, support will be removed after a quarter (2021.7)
"speed_command_topic": "speed-command-topic",
"preset_mode_command_topic": "preset-mode-command-topic",
"percentage_command_topic": "percentage-command-topic",
"preset_modes": [
@ -1683,104 +1291,31 @@ async def test_attributes(hass, mqtt_mock, caplog):
state = hass.states.get("fan.test")
assert state.state == STATE_OFF
assert state.attributes.get(fan.ATTR_SPEED_LIST) == [
"low",
"medium",
"high",
]
await common.async_turn_on(hass, "fan.test")
state = hass.states.get("fan.test")
assert state.state == STATE_ON
assert state.attributes.get(ATTR_ASSUMED_STATE)
# use of speeds is deprecated, support will be removed after a quarter (2021.7)
assert state.attributes.get(fan.ATTR_SPEED) is None
assert state.attributes.get(fan.ATTR_OSCILLATING) is None
await common.async_turn_off(hass, "fan.test")
state = hass.states.get("fan.test")
assert state.state == STATE_OFF
assert state.attributes.get(ATTR_ASSUMED_STATE)
# use of speeds is deprecated, support will be removed after a quarter (2021.7)
assert state.attributes.get(fan.ATTR_SPEED) is None
assert state.attributes.get(fan.ATTR_OSCILLATING) is None
await common.async_oscillate(hass, "fan.test", True)
state = hass.states.get("fan.test")
assert state.state == STATE_OFF
assert state.attributes.get(ATTR_ASSUMED_STATE)
# use of speeds is deprecated, support will be removed after a quarter (2021.7)
assert state.attributes.get(fan.ATTR_SPEED) is None
assert state.attributes.get(fan.ATTR_OSCILLATING) is True
await common.async_oscillate(hass, "fan.test", False)
state = hass.states.get("fan.test")
assert state.state == STATE_OFF
assert state.attributes.get(ATTR_ASSUMED_STATE)
# use of speeds is deprecated, support will be removed after a quarter (2021.7)
assert state.attributes.get(fan.ATTR_SPEED) is None
assert state.attributes.get(fan.ATTR_OSCILLATING) is False
# use of speeds is deprecated, support will be removed after a quarter (2021.7)
await common.async_set_speed(hass, "fan.test", fan.SPEED_LOW)
state = hass.states.get("fan.test")
assert state.state == STATE_OFF
assert state.attributes.get(ATTR_ASSUMED_STATE)
assert state.attributes.get(fan.ATTR_SPEED) == "low"
assert state.attributes.get(fan.ATTR_OSCILLATING) is False
# use of speeds is deprecated, support will be removed after a quarter (2021.7)
await common.async_set_speed(hass, "fan.test", fan.SPEED_MEDIUM)
state = hass.states.get("fan.test")
assert state.state == STATE_OFF
assert state.attributes.get(ATTR_ASSUMED_STATE)
assert state.attributes.get(fan.ATTR_SPEED) == "medium"
assert state.attributes.get(fan.ATTR_OSCILLATING) is False
await common.async_set_speed(hass, "fan.test", fan.SPEED_HIGH)
state = hass.states.get("fan.test")
assert state.state == STATE_OFF
assert state.attributes.get(ATTR_ASSUMED_STATE)
assert state.attributes.get(fan.ATTR_SPEED) == "high"
assert state.attributes.get(fan.ATTR_OSCILLATING) is False
await common.async_set_speed(hass, "fan.test", fan.SPEED_OFF)
state = hass.states.get("fan.test")
assert state.state == STATE_OFF
assert state.attributes.get(ATTR_ASSUMED_STATE)
assert state.attributes.get(fan.ATTR_SPEED) == "off"
assert state.attributes.get(fan.ATTR_OSCILLATING) is False
await common.async_set_speed(hass, "fan.test", "cUsToM")
assert "not a valid speed" in caplog.text
caplog.clear()
# use of speeds is deprecated, support will be removed after a quarter (2021.7)
async def test_custom_speed_list(hass, mqtt_mock):
"""Test optimistic mode without state topic."""
assert await async_setup_component(
hass,
fan.DOMAIN,
{
fan.DOMAIN: {
"platform": "mqtt",
"name": "test",
"command_topic": "command-topic",
"oscillation_command_topic": "oscillation-command-topic",
"oscillation_state_topic": "oscillation-state-topic",
"speed_command_topic": "speed-command-topic",
"speed_state_topic": "speed-state-topic",
"speeds": ["off", "high"],
}
},
)
await hass.async_block_till_done()
state = hass.states.get("fan.test")
assert state.state == STATE_OFF
assert state.attributes.get(fan.ATTR_SPEED_LIST) == ["high"]
async def test_supported_features(hass, mqtt_mock):
"""Test optimistic mode without state topic."""
@ -1800,29 +1335,6 @@ async def test_supported_features(hass, mqtt_mock):
"command_topic": "command-topic",
"oscillation_command_topic": "oscillation-command-topic",
},
{
"platform": "mqtt",
"name": "test3a1",
"command_topic": "command-topic",
# use of speeds is deprecated, support will be removed after a quarter (2021.7)
"speed_command_topic": "speed-command-topic",
},
{
"platform": "mqtt",
"name": "test3a2",
"command_topic": "command-topic",
# use of speeds is deprecated, support will be removed after a quarter (2021.7)
"speed_command_topic": "speed-command-topic",
"speeds": ["low"],
},
{
"platform": "mqtt",
"name": "test3a3",
"command_topic": "command-topic",
# use of speeds is deprecated, support will be removed after a quarter (2021.7)
"speed_command_topic": "speed-command-topic",
"speeds": ["off"],
},
{
"platform": "mqtt",
"name": "test3b",
@ -1849,14 +1361,6 @@ async def test_supported_features(hass, mqtt_mock):
"preset_mode_command_topic": "preset-mode-command-topic",
"preset_modes": ["eco", "smart", "auto"],
},
{
"platform": "mqtt",
"name": "test4",
"command_topic": "command-topic",
"oscillation_command_topic": "oscillation-command-topic",
# use of speeds is deprecated, support will be removed after a quarter (2021.7)
"speed_command_topic": "speed-command-topic",
},
{
"platform": "mqtt",
"name": "test4pcta",
@ -1941,19 +1445,6 @@ async def test_supported_features(hass, mqtt_mock):
state = hass.states.get("fan.test2")
assert state.attributes.get(ATTR_SUPPORTED_FEATURES) == fan.SUPPORT_OSCILLATE
state = hass.states.get("fan.test3a1")
assert (
state.attributes.get(ATTR_SUPPORTED_FEATURES)
and fan.SUPPORT_SET_SPEED == fan.SUPPORT_SET_SPEED
)
state = hass.states.get("fan.test3a2")
assert (
state.attributes.get(ATTR_SUPPORTED_FEATURES)
and fan.SUPPORT_SET_SPEED == fan.SUPPORT_SET_SPEED
)
state = hass.states.get("fan.test3a3")
assert state is None
state = hass.states.get("fan.test3b")
assert state.attributes.get(ATTR_SUPPORTED_FEATURES) == fan.SUPPORT_SET_SPEED
@ -1965,12 +1456,6 @@ async def test_supported_features(hass, mqtt_mock):
state = hass.states.get("fan.test3c3")
assert state.attributes.get(ATTR_SUPPORTED_FEATURES) == fan.SUPPORT_PRESET_MODE
state = hass.states.get("fan.test4")
assert (
state.attributes.get(ATTR_SUPPORTED_FEATURES)
== fan.SUPPORT_OSCILLATE | fan.SUPPORT_SET_SPEED
)
state = hass.states.get("fan.test4pcta")
assert state.attributes.get(ATTR_SUPPORTED_FEATURES) == fan.SUPPORT_SET_SPEED
state = hass.states.get("fan.test4pctb")