From 040c88f982a04350332807c809104d55b0e28560 Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Tue, 29 Jun 2021 11:13:58 +0200 Subject: [PATCH] Filter MQTT climate JSON attributes (#52280) --- homeassistant/components/mqtt/climate.py | 27 ++++++++++++++++++++++++ tests/components/mqtt/test_climate.py | 9 ++++++++ 2 files changed, 36 insertions(+) diff --git a/homeassistant/components/mqtt/climate.py b/homeassistant/components/mqtt/climate.py index da0ed485b72..ccaa7c65176 100644 --- a/homeassistant/components/mqtt/climate.py +++ b/homeassistant/components/mqtt/climate.py @@ -119,6 +119,31 @@ CONF_TEMP_MAX = "max_temp" CONF_TEMP_MIN = "min_temp" CONF_TEMP_STEP = "temp_step" +MQTT_CLIMATE_ATTRIBUTES_BLOCKED = frozenset( + { + climate.ATTR_AUX_HEAT, + climate.ATTR_CURRENT_HUMIDITY, + climate.ATTR_CURRENT_TEMPERATURE, + climate.ATTR_FAN_MODE, + climate.ATTR_FAN_MODES, + climate.ATTR_HUMIDITY, + climate.ATTR_HVAC_ACTION, + climate.ATTR_HVAC_MODES, + climate.ATTR_MAX_HUMIDITY, + climate.ATTR_MAX_TEMP, + climate.ATTR_MIN_HUMIDITY, + climate.ATTR_MIN_TEMP, + climate.ATTR_PRESET_MODE, + climate.ATTR_PRESET_MODES, + climate.ATTR_SWING_MODE, + climate.ATTR_SWING_MODES, + climate.ATTR_TARGET_TEMP_HIGH, + climate.ATTR_TARGET_TEMP_LOW, + climate.ATTR_TARGET_TEMP_STEP, + climate.ATTR_TEMPERATURE, + } +) + VALUE_TEMPLATE_KEYS = ( CONF_AUX_STATE_TEMPLATE, CONF_AWAY_MODE_STATE_TEMPLATE, @@ -276,6 +301,8 @@ async def _async_setup_entity( class MqttClimate(MqttEntity, ClimateEntity): """Representation of an MQTT climate device.""" + _attributes_extra_blocked = MQTT_CLIMATE_ATTRIBUTES_BLOCKED + def __init__(self, hass, config, config_entry, discovery_data): """Initialize the climate device.""" self._action = None diff --git a/tests/components/mqtt/test_climate.py b/tests/components/mqtt/test_climate.py index 546c112b153..24c9e4a5b74 100644 --- a/tests/components/mqtt/test_climate.py +++ b/tests/components/mqtt/test_climate.py @@ -23,6 +23,7 @@ from homeassistant.components.climate.const import ( SUPPORT_TARGET_TEMPERATURE, SUPPORT_TARGET_TEMPERATURE_RANGE, ) +from homeassistant.components.mqtt.climate import MQTT_CLIMATE_ATTRIBUTES_BLOCKED from homeassistant.const import STATE_OFF from homeassistant.setup import async_setup_component @@ -45,6 +46,7 @@ from .test_common import ( help_test_entity_id_update_subscriptions, help_test_setting_attribute_via_mqtt_json_message, help_test_setting_attribute_with_template, + help_test_setting_blocked_attribute_via_mqtt_json_message, help_test_unique_id, help_test_update_with_json_attrs_bad_JSON, help_test_update_with_json_attrs_not_dict, @@ -923,6 +925,13 @@ async def test_setting_attribute_via_mqtt_json_message(hass, mqtt_mock): ) +async def test_setting_blocked_attribute_via_mqtt_json_message(hass, mqtt_mock): + """Test the setting of attribute via MQTT with JSON payload.""" + await help_test_setting_blocked_attribute_via_mqtt_json_message( + hass, mqtt_mock, CLIMATE_DOMAIN, DEFAULT_CONFIG, MQTT_CLIMATE_ATTRIBUTES_BLOCKED + ) + + async def test_setting_attribute_with_template(hass, mqtt_mock): """Test the setting of attribute via MQTT with JSON payload.""" await help_test_setting_attribute_with_template(