Skip to content

Commit

Permalink
Small speed up to mqtt _async_queue_subscriptions (#118094)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco committed May 25, 2024
1 parent 09cbc35 commit de27587
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions homeassistant/components/mqtt/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ def __init__(
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
Expand Down Expand Up @@ -820,8 +820,8 @@ def _async_queue_subscriptions(
"""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:
Expand Down

0 comments on commit de27587

Please sign in to comment.