diff --git a/homeassistant/components/mqtt/cover.py b/homeassistant/components/mqtt/cover.py index 0a78a102a13..fd3e36c04e1 100644 --- a/homeassistant/components/mqtt/cover.py +++ b/homeassistant/components/mqtt/cover.py @@ -101,6 +101,13 @@ TILT_FEATURES = ( | SUPPORT_SET_TILT_POSITION ) +MQTT_COVER_ATTRIBUTES_BLOCKED = frozenset( + { + cover.ATTR_CURRENT_POSITION, + cover.ATTR_CURRENT_TILT_POSITION, + } +) + def validate_options(value): """Validate options. @@ -219,6 +226,8 @@ async def _async_setup_entity( class MqttCover(MqttEntity, CoverEntity): """Representation of a cover that can be controlled using MQTT.""" + _attributes_extra_blocked = MQTT_COVER_ATTRIBUTES_BLOCKED + def __init__(self, hass, config, config_entry, discovery_data): """Initialize the cover.""" self._position = None diff --git a/tests/components/mqtt/test_cover.py b/tests/components/mqtt/test_cover.py index c5a8552dc20..7d763895428 100644 --- a/tests/components/mqtt/test_cover.py +++ b/tests/components/mqtt/test_cover.py @@ -20,6 +20,7 @@ from homeassistant.components.mqtt.cover import ( CONF_TILT_COMMAND_TOPIC, CONF_TILT_STATUS_TEMPLATE, CONF_TILT_STATUS_TOPIC, + MQTT_COVER_ATTRIBUTES_BLOCKED, MqttCover, ) from homeassistant.const import ( @@ -62,6 +63,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, @@ -2307,6 +2309,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, cover.DOMAIN, DEFAULT_CONFIG, MQTT_COVER_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(