Remove the ability for mqtt to set speeds that are not in the speed_list (#45445)

This commit is contained in:
J. Nick Koston 2021-01-22 23:24:06 -06:00 committed by GitHub
parent 011d5208fd
commit 954ad854fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 15 deletions

View File

@ -365,7 +365,7 @@ class MqttFan(MqttEntity, FanEntity):
elif speed == SPEED_OFF: elif speed == SPEED_OFF:
mqtt_payload = self._payload["SPEED_OFF"] mqtt_payload = self._payload["SPEED_OFF"]
else: else:
mqtt_payload = speed raise ValueError(f"{speed} is not a valid fan speed")
mqtt.async_publish( mqtt.async_publish(
self.hass, self.hass,

View File

@ -435,14 +435,8 @@ async def test_sending_mqtt_commands_and_explicit_optimistic(hass, mqtt_mock):
assert state.state is STATE_OFF assert state.state is STATE_OFF
assert state.attributes.get(ATTR_ASSUMED_STATE) assert state.attributes.get(ATTR_ASSUMED_STATE)
await common.async_set_speed(hass, "fan.test", "cUsToM") with pytest.raises(ValueError):
mqtt_mock.async_publish.assert_called_once_with( await common.async_set_speed(hass, "fan.test", "cUsToM")
"speed-command-topic", "cUsToM", 0, False
)
mqtt_mock.async_publish.reset_mock()
state = hass.states.get("fan.test")
assert state.state is STATE_OFF
assert state.attributes.get(ATTR_ASSUMED_STATE)
async def test_attributes(hass, mqtt_mock): async def test_attributes(hass, mqtt_mock):
@ -522,12 +516,8 @@ async def test_attributes(hass, mqtt_mock):
assert state.attributes.get(fan.ATTR_SPEED) == "off" assert state.attributes.get(fan.ATTR_SPEED) == "off"
assert state.attributes.get(fan.ATTR_OSCILLATING) is False assert state.attributes.get(fan.ATTR_OSCILLATING) is False
await common.async_set_speed(hass, "fan.test", "cUsToM") with pytest.raises(ValueError):
state = hass.states.get("fan.test") await common.async_set_speed(hass, "fan.test", "cUsToM")
assert state.state is STATE_OFF
assert state.attributes.get(ATTR_ASSUMED_STATE)
assert state.attributes.get(fan.ATTR_SPEED) == "cUsToM"
assert state.attributes.get(fan.ATTR_OSCILLATING) is False
async def test_custom_speed_list(hass, mqtt_mock): async def test_custom_speed_list(hass, mqtt_mock):