Filter MQTT cover JSON attributes (#52282)

This commit is contained in:
Erik Montnemery 2021-06-29 11:59:23 +02:00 committed by GitHub
parent 30a9198d97
commit 39a064683a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 0 deletions

View File

@ -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

View File

@ -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(