mirror of
https://github.com/home-assistant/core.git
synced 2025-07-14 08:47:10 +00:00
Filter MQTT select JSON attributes (#52288)
This commit is contained in:
parent
74e61ab7f7
commit
a7dd7c1a3d
@ -33,6 +33,12 @@ CONF_OPTIONS = "options"
|
|||||||
DEFAULT_NAME = "MQTT Select"
|
DEFAULT_NAME = "MQTT Select"
|
||||||
DEFAULT_OPTIMISTIC = False
|
DEFAULT_OPTIMISTIC = False
|
||||||
|
|
||||||
|
MQTT_SELECT_ATTRIBUTES_BLOCKED = frozenset(
|
||||||
|
{
|
||||||
|
select.ATTR_OPTIONS,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def validate_config(config):
|
def validate_config(config):
|
||||||
"""Validate that the configuration is valid, throws if it isn't."""
|
"""Validate that the configuration is valid, throws if it isn't."""
|
||||||
@ -81,6 +87,8 @@ async def _async_setup_entity(
|
|||||||
class MqttSelect(MqttEntity, SelectEntity, RestoreEntity):
|
class MqttSelect(MqttEntity, SelectEntity, RestoreEntity):
|
||||||
"""representation of an MQTT select."""
|
"""representation of an MQTT select."""
|
||||||
|
|
||||||
|
_attributes_extra_blocked = MQTT_SELECT_ATTRIBUTES_BLOCKED
|
||||||
|
|
||||||
def __init__(self, hass, config, config_entry, discovery_data):
|
def __init__(self, hass, config, config_entry, discovery_data):
|
||||||
"""Initialize the MQTT select."""
|
"""Initialize the MQTT select."""
|
||||||
self._config = config
|
self._config = config
|
||||||
|
@ -5,7 +5,10 @@ from unittest.mock import patch
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components import select
|
from homeassistant.components import select
|
||||||
from homeassistant.components.mqtt.select import CONF_OPTIONS
|
from homeassistant.components.mqtt.select import (
|
||||||
|
CONF_OPTIONS,
|
||||||
|
MQTT_SELECT_ATTRIBUTES_BLOCKED,
|
||||||
|
)
|
||||||
from homeassistant.components.select import (
|
from homeassistant.components.select import (
|
||||||
ATTR_OPTION,
|
ATTR_OPTION,
|
||||||
ATTR_OPTIONS,
|
ATTR_OPTIONS,
|
||||||
@ -35,6 +38,7 @@ from .test_common import (
|
|||||||
help_test_entity_id_update_subscriptions,
|
help_test_entity_id_update_subscriptions,
|
||||||
help_test_setting_attribute_via_mqtt_json_message,
|
help_test_setting_attribute_via_mqtt_json_message,
|
||||||
help_test_setting_attribute_with_template,
|
help_test_setting_attribute_with_template,
|
||||||
|
help_test_setting_blocked_attribute_via_mqtt_json_message,
|
||||||
help_test_unique_id,
|
help_test_unique_id,
|
||||||
help_test_update_with_json_attrs_bad_JSON,
|
help_test_update_with_json_attrs_bad_JSON,
|
||||||
help_test_update_with_json_attrs_not_dict,
|
help_test_update_with_json_attrs_not_dict,
|
||||||
@ -230,6 +234,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, select.DOMAIN, DEFAULT_CONFIG, MQTT_SELECT_ATTRIBUTES_BLOCKED
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
async def test_setting_attribute_with_template(hass, mqtt_mock):
|
async def test_setting_attribute_with_template(hass, mqtt_mock):
|
||||||
"""Test the setting of attribute via MQTT with JSON payload."""
|
"""Test the setting of attribute via MQTT with JSON payload."""
|
||||||
await help_test_setting_attribute_with_template(
|
await help_test_setting_attribute_with_template(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user