Remove deprecated `send_if_off` option for MQTT climate (#76293)
* Remove `send_if_off` option for mqtt climate * Use cv.remove()pull/76299/head
parent
9aa8838479
commit
741efb89d5
|
@ -99,7 +99,7 @@ CONF_PRESET_MODE_COMMAND_TOPIC = "preset_mode_command_topic"
|
|||
CONF_PRESET_MODE_VALUE_TEMPLATE = "preset_mode_value_template"
|
||||
CONF_PRESET_MODE_COMMAND_TEMPLATE = "preset_mode_command_template"
|
||||
CONF_PRESET_MODES_LIST = "preset_modes"
|
||||
# CONF_SEND_IF_OFF is deprecated, support will be removed with release 2022.9
|
||||
# Support CONF_SEND_IF_OFF is removed with release 2022.9
|
||||
CONF_SEND_IF_OFF = "send_if_off"
|
||||
CONF_SWING_MODE_COMMAND_TEMPLATE = "swing_mode_command_template"
|
||||
CONF_SWING_MODE_COMMAND_TOPIC = "swing_mode_command_topic"
|
||||
|
@ -284,8 +284,6 @@ _PLATFORM_SCHEMA_BASE = MQTT_BASE_SCHEMA.extend(
|
|||
[PRECISION_TENTHS, PRECISION_HALVES, PRECISION_WHOLE]
|
||||
),
|
||||
vol.Optional(CONF_RETAIN, default=DEFAULT_RETAIN): cv.boolean,
|
||||
# CONF_SEND_IF_OFF is deprecated, support will be removed with release 2022.9
|
||||
vol.Optional(CONF_SEND_IF_OFF): cv.boolean,
|
||||
vol.Optional(CONF_ACTION_TEMPLATE): cv.template,
|
||||
vol.Optional(CONF_ACTION_TOPIC): valid_subscribe_topic,
|
||||
# CONF_PRESET_MODE_COMMAND_TOPIC and CONF_PRESET_MODES_LIST must be used together
|
||||
|
@ -334,8 +332,8 @@ PLATFORM_SCHEMA_MODERN = vol.All(
|
|||
# Configuring MQTT Climate under the climate platform key is deprecated in HA Core 2022.6
|
||||
PLATFORM_SCHEMA = vol.All(
|
||||
cv.PLATFORM_SCHEMA.extend(_PLATFORM_SCHEMA_BASE.schema),
|
||||
# CONF_SEND_IF_OFF is deprecated, support will be removed with release 2022.9
|
||||
cv.deprecated(CONF_SEND_IF_OFF),
|
||||
# Support CONF_SEND_IF_OFF is removed with release 2022.9
|
||||
cv.removed(CONF_SEND_IF_OFF),
|
||||
# AWAY and HOLD mode topics and templates are deprecated, support will be removed with release 2022.9
|
||||
cv.deprecated(CONF_AWAY_MODE_COMMAND_TOPIC),
|
||||
cv.deprecated(CONF_AWAY_MODE_STATE_TEMPLATE),
|
||||
|
@ -353,8 +351,8 @@ _DISCOVERY_SCHEMA_BASE = _PLATFORM_SCHEMA_BASE.extend({}, extra=vol.REMOVE_EXTRA
|
|||
|
||||
DISCOVERY_SCHEMA = vol.All(
|
||||
_DISCOVERY_SCHEMA_BASE,
|
||||
# CONF_SEND_IF_OFF is deprecated, support will be removed with release 2022.9
|
||||
cv.deprecated(CONF_SEND_IF_OFF),
|
||||
# Support CONF_SEND_IF_OFF is removed with release 2022.9
|
||||
cv.removed(CONF_SEND_IF_OFF),
|
||||
# AWAY and HOLD mode topics and templates are deprecated, support will be removed with release 2022.9
|
||||
cv.deprecated(CONF_AWAY_MODE_COMMAND_TOPIC),
|
||||
cv.deprecated(CONF_AWAY_MODE_STATE_TEMPLATE),
|
||||
|
@ -437,8 +435,6 @@ class MqttClimate(MqttEntity, ClimateEntity):
|
|||
self._feature_preset_mode = False
|
||||
self._optimistic_preset_mode = None
|
||||
|
||||
# CONF_SEND_IF_OFF is deprecated, support will be removed with release 2022.9
|
||||
self._send_if_off = True
|
||||
# AWAY and HOLD mode topics and templates are deprecated,
|
||||
# support will be removed with release 2022.9
|
||||
self._hold_list = []
|
||||
|
@ -511,10 +507,6 @@ class MqttClimate(MqttEntity, ClimateEntity):
|
|||
|
||||
self._command_templates = command_templates
|
||||
|
||||
# CONF_SEND_IF_OFF is deprecated, support will be removed with release 2022.9
|
||||
if CONF_SEND_IF_OFF in config:
|
||||
self._send_if_off = config[CONF_SEND_IF_OFF]
|
||||
|
||||
# AWAY and HOLD mode topics and templates are deprecated,
|
||||
# support will be removed with release 2022.9
|
||||
if CONF_HOLD_LIST in config:
|
||||
|
@ -871,10 +863,8 @@ class MqttClimate(MqttEntity, ClimateEntity):
|
|||
# optimistic mode
|
||||
setattr(self, attr, temp)
|
||||
|
||||
# CONF_SEND_IF_OFF is deprecated, support will be removed with release 2022.9
|
||||
if self._send_if_off or self._current_operation != HVACMode.OFF:
|
||||
payload = self._command_templates[cmnd_template](temp)
|
||||
await self._publish(cmnd_topic, payload)
|
||||
payload = self._command_templates[cmnd_template](temp)
|
||||
await self._publish(cmnd_topic, payload)
|
||||
|
||||
async def async_set_temperature(self, **kwargs: Any) -> None:
|
||||
"""Set new target temperatures."""
|
||||
|
@ -910,12 +900,8 @@ class MqttClimate(MqttEntity, ClimateEntity):
|
|||
|
||||
async def async_set_swing_mode(self, swing_mode: str) -> None:
|
||||
"""Set new swing mode."""
|
||||
# CONF_SEND_IF_OFF is deprecated, support will be removed with release 2022.9
|
||||
if self._send_if_off or self._current_operation != HVACMode.OFF:
|
||||
payload = self._command_templates[CONF_SWING_MODE_COMMAND_TEMPLATE](
|
||||
swing_mode
|
||||
)
|
||||
await self._publish(CONF_SWING_MODE_COMMAND_TOPIC, payload)
|
||||
payload = self._command_templates[CONF_SWING_MODE_COMMAND_TEMPLATE](swing_mode)
|
||||
await self._publish(CONF_SWING_MODE_COMMAND_TOPIC, payload)
|
||||
|
||||
if self._topic[CONF_SWING_MODE_STATE_TOPIC] is None:
|
||||
self._current_swing_mode = swing_mode
|
||||
|
@ -923,10 +909,8 @@ class MqttClimate(MqttEntity, ClimateEntity):
|
|||
|
||||
async def async_set_fan_mode(self, fan_mode: str) -> None:
|
||||
"""Set new target temperature."""
|
||||
# CONF_SEND_IF_OFF is deprecated, support will be removed with release 2022.9
|
||||
if self._send_if_off or self._current_operation != HVACMode.OFF:
|
||||
payload = self._command_templates[CONF_FAN_MODE_COMMAND_TEMPLATE](fan_mode)
|
||||
await self._publish(CONF_FAN_MODE_COMMAND_TOPIC, payload)
|
||||
payload = self._command_templates[CONF_FAN_MODE_COMMAND_TEMPLATE](fan_mode)
|
||||
await self._publish(CONF_FAN_MODE_COMMAND_TOPIC, payload)
|
||||
|
||||
if self._topic[CONF_FAN_MODE_STATE_TOPIC] is None:
|
||||
self._current_fan_mode = fan_mode
|
||||
|
|
|
@ -349,44 +349,6 @@ async def test_set_fan_mode(hass, mqtt_mock_entry_with_yaml_config):
|
|||
assert state.attributes.get("fan_mode") == "high"
|
||||
|
||||
|
||||
# CONF_SEND_IF_OFF is deprecated, support will be removed with release 2022.9
|
||||
@pytest.mark.parametrize(
|
||||
"send_if_off,assert_async_publish",
|
||||
[
|
||||
({}, [call("fan-mode-topic", "low", 0, False)]),
|
||||
({"send_if_off": True}, [call("fan-mode-topic", "low", 0, False)]),
|
||||
({"send_if_off": False}, []),
|
||||
],
|
||||
)
|
||||
async def test_set_fan_mode_send_if_off(
|
||||
hass, mqtt_mock_entry_with_yaml_config, send_if_off, assert_async_publish
|
||||
):
|
||||
"""Test setting of fan mode if the hvac is off."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config[CLIMATE_DOMAIN].update(send_if_off)
|
||||
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
|
||||
await hass.async_block_till_done()
|
||||
mqtt_mock = await mqtt_mock_entry_with_yaml_config()
|
||||
assert hass.states.get(ENTITY_CLIMATE) is not None
|
||||
|
||||
# Turn on HVAC
|
||||
await common.async_set_hvac_mode(hass, "cool", ENTITY_CLIMATE)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
# Updates for fan_mode should be sent when the device is turned on
|
||||
await common.async_set_fan_mode(hass, "high", ENTITY_CLIMATE)
|
||||
mqtt_mock.async_publish.assert_called_once_with("fan-mode-topic", "high", 0, False)
|
||||
|
||||
# Turn off HVAC
|
||||
await common.async_set_hvac_mode(hass, "off", ENTITY_CLIMATE)
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert state.state == "off"
|
||||
|
||||
# Updates for fan_mode should be sent if SEND_IF_OFF is not set or is True
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
await common.async_set_fan_mode(hass, "low", ENTITY_CLIMATE)
|
||||
mqtt_mock.async_publish.assert_has_calls(assert_async_publish)
|
||||
|
||||
|
||||
async def test_set_swing_mode_bad_attr(hass, mqtt_mock_entry_with_yaml_config, caplog):
|
||||
"""Test setting swing mode without required attribute."""
|
||||
assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG)
|
||||
|
@ -442,44 +404,6 @@ async def test_set_swing(hass, mqtt_mock_entry_with_yaml_config):
|
|||
assert state.attributes.get("swing_mode") == "on"
|
||||
|
||||
|
||||
# CONF_SEND_IF_OFF is deprecated, support will be removed with release 2022.9
|
||||
@pytest.mark.parametrize(
|
||||
"send_if_off,assert_async_publish",
|
||||
[
|
||||
({}, [call("swing-mode-topic", "on", 0, False)]),
|
||||
({"send_if_off": True}, [call("swing-mode-topic", "on", 0, False)]),
|
||||
({"send_if_off": False}, []),
|
||||
],
|
||||
)
|
||||
async def test_set_swing_mode_send_if_off(
|
||||
hass, mqtt_mock_entry_with_yaml_config, send_if_off, assert_async_publish
|
||||
):
|
||||
"""Test setting of swing mode if the hvac is off."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config[CLIMATE_DOMAIN].update(send_if_off)
|
||||
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
|
||||
await hass.async_block_till_done()
|
||||
mqtt_mock = await mqtt_mock_entry_with_yaml_config()
|
||||
assert hass.states.get(ENTITY_CLIMATE) is not None
|
||||
|
||||
# Turn on HVAC
|
||||
await common.async_set_hvac_mode(hass, "cool", ENTITY_CLIMATE)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
# Updates for swing_mode should be sent when the device is turned on
|
||||
await common.async_set_swing_mode(hass, "off", ENTITY_CLIMATE)
|
||||
mqtt_mock.async_publish.assert_called_once_with("swing-mode-topic", "off", 0, False)
|
||||
|
||||
# Turn off HVAC
|
||||
await common.async_set_hvac_mode(hass, "off", ENTITY_CLIMATE)
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert state.state == "off"
|
||||
|
||||
# Updates for swing_mode should be sent if SEND_IF_OFF is not set or is True
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
await common.async_set_swing_mode(hass, "on", ENTITY_CLIMATE)
|
||||
mqtt_mock.async_publish.assert_has_calls(assert_async_publish)
|
||||
|
||||
|
||||
async def test_set_target_temperature(hass, mqtt_mock_entry_with_yaml_config):
|
||||
"""Test setting the target temperature."""
|
||||
assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG)
|
||||
|
@ -517,46 +441,6 @@ async def test_set_target_temperature(hass, mqtt_mock_entry_with_yaml_config):
|
|||
mqtt_mock.async_publish.reset_mock()
|
||||
|
||||
|
||||
# CONF_SEND_IF_OFF is deprecated, support will be removed with release 2022.9
|
||||
@pytest.mark.parametrize(
|
||||
"send_if_off,assert_async_publish",
|
||||
[
|
||||
({}, [call("temperature-topic", "21.0", 0, False)]),
|
||||
({"send_if_off": True}, [call("temperature-topic", "21.0", 0, False)]),
|
||||
({"send_if_off": False}, []),
|
||||
],
|
||||
)
|
||||
async def test_set_target_temperature_send_if_off(
|
||||
hass, mqtt_mock_entry_with_yaml_config, send_if_off, assert_async_publish
|
||||
):
|
||||
"""Test setting of target temperature if the hvac is off."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config[CLIMATE_DOMAIN].update(send_if_off)
|
||||
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
|
||||
await hass.async_block_till_done()
|
||||
mqtt_mock = await mqtt_mock_entry_with_yaml_config()
|
||||
assert hass.states.get(ENTITY_CLIMATE) is not None
|
||||
|
||||
# Turn on HVAC
|
||||
await common.async_set_hvac_mode(hass, "cool", ENTITY_CLIMATE)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
# Updates for target temperature should be sent when the device is turned on
|
||||
await common.async_set_temperature(hass, 16.0, ENTITY_CLIMATE)
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
"temperature-topic", "16.0", 0, False
|
||||
)
|
||||
|
||||
# Turn off HVAC
|
||||
await common.async_set_hvac_mode(hass, "off", ENTITY_CLIMATE)
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert state.state == "off"
|
||||
|
||||
# Updates for target temperature sent should be if SEND_IF_OFF is not set or is True
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
await common.async_set_temperature(hass, 21.0, ENTITY_CLIMATE)
|
||||
mqtt_mock.async_publish.assert_has_calls(assert_async_publish)
|
||||
|
||||
|
||||
async def test_set_target_temperature_pessimistic(
|
||||
hass, mqtt_mock_entry_with_yaml_config
|
||||
):
|
||||
|
|
Loading…
Reference in New Issue