From 09b509da94b690ec01ea38056e3dc3a1e3420f7f Mon Sep 17 00:00:00 2001 From: Jan Bouwhuis Date: Wed, 15 Feb 2023 10:46:57 +0100 Subject: [PATCH] Add note on always subscribing to the MQTT broker when topics are shared (#88159) Add note on always subscribing --- homeassistant/components/mqtt/client.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/homeassistant/components/mqtt/client.py b/homeassistant/components/mqtt/client.py index 8a18c392ca2..6355e992a0d 100644 --- a/homeassistant/components/mqtt/client.py +++ b/homeassistant/components/mqtt/client.py @@ -565,6 +565,18 @@ class MQTT: ) -> None: """Perform MQTT client subscriptions.""" + # Section 3.3.1.3 in the specification: + # http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html + # When sending a PUBLISH Packet to a Client the Server MUST + # set the RETAIN flag to 1 if a message is sent as a result of a + # new subscription being made by a Client [MQTT-3.3.1-8]. + # It MUST set the RETAIN flag to 0 when a PUBLISH Packet is sent to + # a Client because it matches an established subscription regardless + # of how the flag was set in the message it received [MQTT-3.3.1-9]. + # + # Since we do not know if a published value is retained we need to + # (re)subscribe, to ensure retained messages are replayed + def _process_client_subscriptions() -> list[tuple[int, int]]: """Initiate all subscriptions on the MQTT client and return the results.""" subscribe_result_list = []