From de275878c43d4c60b53f40d1cd647cfef8edc9a5 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 25 May 2024 00:32:15 -1000 Subject: [PATCH] Small speed up to mqtt _async_queue_subscriptions (#118094) --- homeassistant/components/mqtt/client.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/mqtt/client.py b/homeassistant/components/mqtt/client.py index 7b43388fe93..b3fde3f8320 100644 --- a/homeassistant/components/mqtt/client.py +++ b/homeassistant/components/mqtt/client.py @@ -452,7 +452,7 @@ class MQTT: self._should_reconnect: bool = True self._available_future: asyncio.Future[bool] | None = None - self._max_qos: dict[str, int] = {} # topic, max qos + self._max_qos: defaultdict[str, int] = defaultdict(int) # topic, max qos self._pending_subscriptions: dict[str, int] = {} # topic, qos self._unsubscribe_debouncer = EnsureJobAfterCooldown( UNSUBSCRIBE_COOLDOWN, self._async_perform_unsubscribes @@ -820,8 +820,8 @@ class MQTT: """Queue requested subscriptions.""" for subscription in subscriptions: topic, qos = subscription - max_qos = max(qos, self._max_qos.setdefault(topic, qos)) - self._max_qos[topic] = max_qos + if (max_qos := self._max_qos[topic]) < qos: + self._max_qos[topic] = (max_qos := qos) self._pending_subscriptions[topic] = max_qos # Cancel any pending unsubscribe since we are subscribing now if topic in self._pending_unsubscribes: