mirror of
https://github.com/home-assistant/core.git
synced 2025-07-20 03:37:07 +00:00
Filter MQTT fan JSON attributes (#52283)
This commit is contained in:
parent
71a0e474cc
commit
e0f7987544
@ -94,6 +94,18 @@ DEFAULT_SPEED_RANGE_MAX = 100
|
|||||||
OSCILLATE_ON_PAYLOAD = "oscillate_on"
|
OSCILLATE_ON_PAYLOAD = "oscillate_on"
|
||||||
OSCILLATE_OFF_PAYLOAD = "oscillate_off"
|
OSCILLATE_OFF_PAYLOAD = "oscillate_off"
|
||||||
|
|
||||||
|
MQTT_FAN_ATTRIBUTES_BLOCKED = frozenset(
|
||||||
|
{
|
||||||
|
fan.ATTR_DIRECTION,
|
||||||
|
fan.ATTR_OSCILLATING,
|
||||||
|
fan.ATTR_PERCENTAGE_STEP,
|
||||||
|
fan.ATTR_PERCENTAGE,
|
||||||
|
fan.ATTR_PRESET_MODE,
|
||||||
|
fan.ATTR_PRESET_MODES,
|
||||||
|
fan.ATTR_SPEED_LIST,
|
||||||
|
fan.ATTR_SPEED,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -223,6 +235,8 @@ async def _async_setup_entity(
|
|||||||
class MqttFan(MqttEntity, FanEntity):
|
class MqttFan(MqttEntity, FanEntity):
|
||||||
"""A MQTT fan component."""
|
"""A MQTT fan component."""
|
||||||
|
|
||||||
|
_attributes_extra_blocked = MQTT_FAN_ATTRIBUTES_BLOCKED
|
||||||
|
|
||||||
def __init__(self, hass, config, config_entry, discovery_data):
|
def __init__(self, hass, config, config_entry, discovery_data):
|
||||||
"""Initialize the MQTT fan."""
|
"""Initialize the MQTT fan."""
|
||||||
self._state = False
|
self._state = False
|
||||||
|
@ -6,6 +6,7 @@ from voluptuous.error import MultipleInvalid
|
|||||||
|
|
||||||
from homeassistant.components import fan
|
from homeassistant.components import fan
|
||||||
from homeassistant.components.fan import NotValidPresetModeError
|
from homeassistant.components.fan import NotValidPresetModeError
|
||||||
|
from homeassistant.components.mqtt.fan import MQTT_FAN_ATTRIBUTES_BLOCKED
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_ASSUMED_STATE,
|
ATTR_ASSUMED_STATE,
|
||||||
ATTR_SUPPORTED_FEATURES,
|
ATTR_SUPPORTED_FEATURES,
|
||||||
@ -33,6 +34,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,
|
||||||
@ -2037,6 +2039,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, fan.DOMAIN, DEFAULT_CONFIG, MQTT_FAN_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