Filter MQTT number JSON attributes (#52286)
This commit is contained in:
parent
3b89fcfe83
commit
71a0e474cc
2 changed files with 23 additions and 1 deletions
|
@ -40,6 +40,14 @@ CONF_STEP = "step"
|
|||
DEFAULT_NAME = "MQTT Number"
|
||||
DEFAULT_OPTIMISTIC = False
|
||||
|
||||
MQTT_NUMBER_ATTRIBUTES_BLOCKED = frozenset(
|
||||
{
|
||||
number.ATTR_MAX,
|
||||
number.ATTR_MIN,
|
||||
number.ATTR_STEP,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
def validate_config(config):
|
||||
"""Validate that the configuration is valid, throws if it isn't."""
|
||||
|
@ -92,6 +100,8 @@ async def _async_setup_entity(
|
|||
class MqttNumber(MqttEntity, NumberEntity, RestoreEntity):
|
||||
"""representation of an MQTT number."""
|
||||
|
||||
_attributes_extra_blocked = MQTT_NUMBER_ATTRIBUTES_BLOCKED
|
||||
|
||||
def __init__(self, hass, config, config_entry, discovery_data):
|
||||
"""Initialize the MQTT Number."""
|
||||
self._config = config
|
||||
|
|
|
@ -5,7 +5,11 @@ from unittest.mock import patch
|
|||
import pytest
|
||||
|
||||
from homeassistant.components import number
|
||||
from homeassistant.components.mqtt.number import CONF_MAX, CONF_MIN
|
||||
from homeassistant.components.mqtt.number import (
|
||||
CONF_MAX,
|
||||
CONF_MIN,
|
||||
MQTT_NUMBER_ATTRIBUTES_BLOCKED,
|
||||
)
|
||||
from homeassistant.components.number import (
|
||||
ATTR_MAX,
|
||||
ATTR_MIN,
|
||||
|
@ -37,6 +41,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,
|
||||
|
@ -250,6 +255,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, number.DOMAIN, DEFAULT_CONFIG, MQTT_NUMBER_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(
|
||||
|
|
Loading…
Add table
Reference in a new issue