mirror of
https://github.com/home-assistant/core.git
synced 2025-07-10 14:57:09 +00:00
Filter MQTT sensor JSON attributes (#52289)
This commit is contained in:
parent
e0f7987544
commit
61f7f5c96a
@ -44,6 +44,13 @@ CONF_LAST_RESET_TOPIC = "last_reset_topic"
|
|||||||
CONF_LAST_RESET_VALUE_TEMPLATE = "last_reset_value_template"
|
CONF_LAST_RESET_VALUE_TEMPLATE = "last_reset_value_template"
|
||||||
CONF_STATE_CLASS = "state_class"
|
CONF_STATE_CLASS = "state_class"
|
||||||
|
|
||||||
|
MQTT_SENSOR_ATTRIBUTES_BLOCKED = frozenset(
|
||||||
|
{
|
||||||
|
sensor.ATTR_LAST_RESET,
|
||||||
|
sensor.ATTR_STATE_CLASS,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
DEFAULT_NAME = "MQTT Sensor"
|
DEFAULT_NAME = "MQTT Sensor"
|
||||||
DEFAULT_FORCE_UPDATE = False
|
DEFAULT_FORCE_UPDATE = False
|
||||||
PLATFORM_SCHEMA = mqtt.MQTT_RO_PLATFORM_SCHEMA.extend(
|
PLATFORM_SCHEMA = mqtt.MQTT_RO_PLATFORM_SCHEMA.extend(
|
||||||
@ -87,6 +94,7 @@ class MqttSensor(MqttEntity, SensorEntity):
|
|||||||
"""Representation of a sensor that can be updated using MQTT."""
|
"""Representation of a sensor that can be updated using MQTT."""
|
||||||
|
|
||||||
_attr_last_reset = None
|
_attr_last_reset = None
|
||||||
|
_attributes_extra_blocked = MQTT_SENSOR_ATTRIBUTES_BLOCKED
|
||||||
|
|
||||||
def __init__(self, hass, config, config_entry, discovery_data):
|
def __init__(self, hass, config, config_entry, discovery_data):
|
||||||
"""Initialize the sensor."""
|
"""Initialize the sensor."""
|
||||||
|
@ -6,6 +6,7 @@ from unittest.mock import patch
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
from homeassistant.components.mqtt.sensor import MQTT_SENSOR_ATTRIBUTES_BLOCKED
|
||||||
import homeassistant.components.sensor as sensor
|
import homeassistant.components.sensor as sensor
|
||||||
from homeassistant.const import EVENT_STATE_CHANGED, STATE_UNAVAILABLE
|
from homeassistant.const import EVENT_STATE_CHANGED, STATE_UNAVAILABLE
|
||||||
import homeassistant.core as ha
|
import homeassistant.core as ha
|
||||||
@ -535,7 +536,7 @@ 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):
|
async def test_setting_blocked_attribute_via_mqtt_json_message(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_blocked_attribute_via_mqtt_json_message(
|
await help_test_setting_blocked_attribute_via_mqtt_json_message(
|
||||||
hass, mqtt_mock, sensor.DOMAIN, DEFAULT_CONFIG, None
|
hass, mqtt_mock, sensor.DOMAIN, DEFAULT_CONFIG, MQTT_SENSOR_ATTRIBUTES_BLOCKED
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user