Filter MQTT lock JSON attributes (#52285)
This commit is contained in:
parent
7de3e7d1dd
commit
3b89fcfe83
2 changed files with 18 additions and 0 deletions
|
@ -37,6 +37,13 @@ DEFAULT_PAYLOAD_UNLOCK = "UNLOCK"
|
|||
DEFAULT_STATE_LOCKED = "LOCKED"
|
||||
DEFAULT_STATE_UNLOCKED = "UNLOCKED"
|
||||
|
||||
MQTT_LOCK_ATTRIBUTES_BLOCKED = frozenset(
|
||||
{
|
||||
lock.ATTR_CHANGED_BY,
|
||||
lock.ATTR_CODE_FORMAT,
|
||||
}
|
||||
)
|
||||
|
||||
PLATFORM_SCHEMA = mqtt.MQTT_RW_PLATFORM_SCHEMA.extend(
|
||||
{
|
||||
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
|
||||
|
@ -76,6 +83,8 @@ async def _async_setup_entity(
|
|||
class MqttLock(MqttEntity, LockEntity):
|
||||
"""Representation of a lock that can be toggled using MQTT."""
|
||||
|
||||
_attributes_extra_blocked = MQTT_LOCK_ATTRIBUTES_BLOCKED
|
||||
|
||||
def __init__(self, hass, config, config_entry, discovery_data):
|
||||
"""Initialize the lock."""
|
||||
self._state = False
|
||||
|
|
|
@ -10,6 +10,7 @@ from homeassistant.components.lock import (
|
|||
STATE_LOCKED,
|
||||
STATE_UNLOCKED,
|
||||
)
|
||||
from homeassistant.components.mqtt.lock import MQTT_LOCK_ATTRIBUTES_BLOCKED
|
||||
from homeassistant.const import ATTR_ASSUMED_STATE, ATTR_ENTITY_ID
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
|
@ -32,6 +33,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,
|
||||
|
@ -311,6 +313,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, LOCK_DOMAIN, DEFAULT_CONFIG, MQTT_LOCK_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