Remove deprecated features from MQTT platforms (#32909)
* Remove deprecated features * Lint
This commit is contained in:
1 parent
5c1dc60505
commit
e0d2e5dcb0
6 files changed
+30
-305
No files matched your search
@@ -11,7 +11,7 @@ from homeassistant.helpers.dispatcher import async_dispatcher_send
|
||||
from homeassistant.helpers.typing import HomeAssistantType
|
||||
|
||||
from .abbreviations import ABBREVIATIONS, DEVICE_ABBREVIATIONS
|
||||
from .const import ATTR_DISCOVERY_HASH, ATTR_DISCOVERY_TOPIC, CONF_STATE_TOPIC
|
||||
from .const import ATTR_DISCOVERY_HASH, ATTR_DISCOVERY_TOPIC
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
@@ -50,15 +50,6 @@ CONFIG_ENTRY_COMPONENTS = [
|
||||
"vacuum",
|
||||
]
|
||||
|
||||
DEPRECATED_PLATFORM_TO_SCHEMA = {
|
||||
"light": {"mqtt_json": "json", "mqtt_template": "template"}
|
||||
}
|
||||
|
||||
# These components require state_topic to be set.
|
||||
# If not specified, infer state_topic from discovery topic.
|
||||
IMPLICIT_STATE_TOPIC_COMPONENTS = ["alarm_control_panel", "binary_sensor", "sensor"]
|
||||
|
||||
|
||||
ALREADY_DISCOVERED = "mqtt_discovered_components"
|
||||
DATA_CONFIG_ENTRY_LOCK = "mqtt_config_entry_lock"
|
||||
CONFIG_ENTRY_IS_SETUP = "mqtt_config_entry_is_setup"
|
||||
@@ -143,39 +134,8 @@ async def async_start(
|
||||
}
|
||||
setattr(payload, "discovery_data", discovery_data)
|
||||
|
||||
if CONF_PLATFORM in payload and "schema" not in payload:
|
||||
platform = payload[CONF_PLATFORM]
|
||||
if (
|
||||
component in DEPRECATED_PLATFORM_TO_SCHEMA
|
||||
and platform in DEPRECATED_PLATFORM_TO_SCHEMA[component]
|
||||
):
|
||||
schema = DEPRECATED_PLATFORM_TO_SCHEMA[component][platform]
|
||||
payload["schema"] = schema
|
||||
_LOGGER.warning(
|
||||
'"platform": "%s" is deprecated, ' 'replace with "schema":"%s"',
|
||||
platform,
|
||||
schema,
|
||||
)
|
||||
payload[CONF_PLATFORM] = "mqtt"
|
||||
|
||||
if (
|
||||
CONF_STATE_TOPIC not in payload
|
||||
and component in IMPLICIT_STATE_TOPIC_COMPONENTS
|
||||
):
|
||||
# state_topic not specified, infer from discovery topic
|
||||
fmt_node_id = f"{node_id}/" if node_id else ""
|
||||
payload[
|
||||
CONF_STATE_TOPIC
|
||||
] = f"{discovery_topic}/{component}/{fmt_node_id}{object_id}/state"
|
||||
_LOGGER.warning(
|
||||
'implicit %s is deprecated, add "%s":"%s" to '
|
||||
"%s discovery message",
|
||||
CONF_STATE_TOPIC,
|
||||
CONF_STATE_TOPIC,
|
||||
payload[CONF_STATE_TOPIC],
|
||||
topic,
|
||||
)
|
||||
|
||||
if ALREADY_DISCOVERED not in hass.data:
|
||||
hass.data[ALREADY_DISCOVERED] = {}
|
||||
if discovery_hash in hass.data[ALREADY_DISCOVERED]:
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
"""Support for MQTT sensors."""
|
||||
from datetime import timedelta
|
||||
import json
|
||||
import logging
|
||||
from typing import Optional
|
||||
|
||||
@@ -41,7 +40,6 @@ from .discovery import MQTT_DISCOVERY_NEW, clear_discovery_hash
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
CONF_EXPIRE_AFTER = "expire_after"
|
||||
CONF_JSON_ATTRS = "json_attributes"
|
||||
|
||||
DEFAULT_NAME = "MQTT Sensor"
|
||||
DEFAULT_FORCE_UPDATE = False
|
||||
@@ -53,7 +51,6 @@ PLATFORM_SCHEMA = (
|
||||
vol.Optional(CONF_EXPIRE_AFTER): cv.positive_int,
|
||||
vol.Optional(CONF_FORCE_UPDATE, default=DEFAULT_FORCE_UPDATE): cv.boolean,
|
||||
vol.Optional(CONF_ICON): cv.icon,
|
||||
vol.Optional(CONF_JSON_ATTRS, default=[]): cv.ensure_list_csv,
|
||||
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
|
||||
vol.Optional(CONF_UNIQUE_ID): cv.string,
|
||||
vol.Optional(CONF_UNIT_OF_MEASUREMENT): cv.string,
|
||||
@@ -110,16 +107,9 @@ class MqttSensor(
|
||||
self._state = None
|
||||
self._sub_state = None
|
||||
self._expiration_trigger = None
|
||||
self._attributes = None
|
||||
|
||||
device_config = config.get(CONF_DEVICE)
|
||||
|
||||
if config.get(CONF_JSON_ATTRS):
|
||||
_LOGGER.warning(
|
||||
'configuration variable "json_attributes" is '
|
||||
'deprecated, replace with "json_attributes_topic"'
|
||||
)
|
||||
|
||||
MqttAttributes.__init__(self, config)
|
||||
MqttAvailability.__init__(self, config)
|
||||
MqttDiscoveryUpdate.__init__(self, discovery_data, self.discovery_update)
|
||||
@@ -165,22 +155,6 @@ class MqttSensor(
|
||||
self.hass, self.value_is_expired, expiration_at
|
||||
)
|
||||
|
||||
json_attributes = set(self._config[CONF_JSON_ATTRS])
|
||||
if json_attributes:
|
||||
self._attributes = {}
|
||||
try:
|
||||
json_dict = json.loads(payload)
|
||||
if isinstance(json_dict, dict):
|
||||
attrs = {
|
||||
k: json_dict[k] for k in json_attributes & json_dict.keys()
|
||||
}
|
||||
self._attributes = attrs
|
||||
else:
|
||||
_LOGGER.warning("JSON result was not a dictionary")
|
||||
except ValueError:
|
||||
_LOGGER.warning("MQTT payload could not be parsed as JSON")
|
||||
_LOGGER.debug("Erroneous JSON: %s", payload)
|
||||
|
||||
if template is not None:
|
||||
payload = template.async_render_with_possible_json_value(
|
||||
payload, self._state
|
||||
@@ -241,11 +215,6 @@ class MqttSensor(
|
||||
"""Return the state of the entity."""
|
||||
return self._state
|
||||
|
||||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return the state attributes."""
|
||||
return self._attributes
|
||||
|
||||
@property
|
||||
def unique_id(self):
|
||||
"""Return a unique ID."""
|
||||
|
||||
Reference in new issue
Block a user