Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter MQTT climate JSON attributes #52280

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 27 additions & 0 deletions homeassistant/components/mqtt/climate.py
Expand Up @@ -119,6 +119,31 @@
CONF_TEMP_MIN = "min_temp"
CONF_TEMP_STEP = "temp_step"

MQTT_CLIMATE_ATTRIBUTES_BLOCKED = frozenset(
{
climate.ATTR_AUX_HEAT,
frenck marked this conversation as resolved.
Show resolved Hide resolved
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,
Expand Down Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions tests/components/mqtt/test_climate.py
Expand Up @@ -23,6 +23,7 @@
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

Expand All @@ -45,6 +46,7 @@
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,
Expand Down Expand Up @@ -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(
Expand Down