Suppress MQTT discovery updates without changes (#38568)
This commit is contained in:
1 parent
896bdbff8f
commit
4ed1f8023b
18 files changed
+266
-31
No files matched your search
@@ -44,6 +44,7 @@ from . import config_flow # noqa: F401 pylint: disable=unused-import
|
||||
from . import debug_info, discovery
|
||||
from .const import (
|
||||
ATTR_DISCOVERY_HASH,
|
||||
ATTR_DISCOVERY_PAYLOAD,
|
||||
ATTR_DISCOVERY_TOPIC,
|
||||
ATTR_PAYLOAD,
|
||||
ATTR_QOS,
|
||||
@@ -1169,6 +1170,7 @@ class MqttDiscoveryUpdate(Entity):
|
||||
_LOGGER.info(
|
||||
"Got update for entity with hash: %s '%s'", discovery_hash, payload,
|
||||
)
|
||||
old_payload = self._discovery_data[ATTR_DISCOVERY_PAYLOAD]
|
||||
debug_info.update_entity_discovery_data(self.hass, payload, self.entity_id)
|
||||
if not payload:
|
||||
# Empty payload: Remove component
|
||||
@@ -1176,9 +1178,13 @@ class MqttDiscoveryUpdate(Entity):
|
||||
self._cleanup_discovery_on_remove()
|
||||
await _async_remove_state_and_registry_entry(self)
|
||||
elif self._discovery_update:
|
||||
# Non-empty payload: Notify component
|
||||
_LOGGER.info("Updating component: %s", self.entity_id)
|
||||
await self._discovery_update(payload)
|
||||
if old_payload != self._discovery_data[ATTR_DISCOVERY_PAYLOAD]:
|
||||
# Non-empty, changed payload: Notify component
|
||||
_LOGGER.info("Updating component: %s", self.entity_id)
|
||||
await self._discovery_update(payload)
|
||||
else:
|
||||
# Non-empty, unchanged payload: Ignore to avoid changing states
|
||||
_LOGGER.info("Ignoring unchanged update for: %s", self.entity_id)
|
||||
|
||||
if discovery_hash:
|
||||
debug_info.add_entity_discovery_data(
|
||||
|
||||
@@ -169,7 +169,8 @@ class MqttBinarySensor(
|
||||
|
||||
if expire_after is not None and expire_after > 0:
|
||||
|
||||
# When expire_after is set, and we receive a message, assume device is not expired since it has to be to receive the message
|
||||
# When expire_after is set, and we receive a message, assume device is
|
||||
# not expired since it has to be to receive the message
|
||||
self._expired = False
|
||||
|
||||
# Reset old trigger
|
||||
|
||||
@@ -101,10 +101,10 @@ async def async_setup_entity_template(
|
||||
config, async_add_entities, config_entry, discovery_data
|
||||
):
|
||||
"""Set up a MQTT Template light."""
|
||||
async_add_entities([MqttTemplate(config, config_entry, discovery_data)])
|
||||
async_add_entities([MqttLightTemplate(config, config_entry, discovery_data)])
|
||||
|
||||
|
||||
class MqttTemplate(
|
||||
class MqttLightTemplate(
|
||||
MqttAttributes,
|
||||
MqttAvailability,
|
||||
MqttDiscoveryUpdate,
|
||||
|
||||
Reference in new issue
Block a user