mirror of
https://github.com/home-assistant/core.git
synced 2025-07-29 18:28:14 +02:00
Subscribe per component for MQTT discovery (#119974)
* Subscribe per component for MQTT discovery * Use single assignment * Handle wildcard subscriptions first * Split subsRecription handling, update helper * Fix help_all_subscribe_calls * Fix import * Fix test * Update import order * Undo move self._last_subscribe * Recover removed test * Revert not needed changes to binary_sensor platform tests * Revert line removal * Rework interation of discovery topics * Reduce * Add comment * Move comment * Chain subscriptions
This commit is contained in:
@ -111,6 +111,7 @@ UNSUBSCRIBE_COOLDOWN = 0.1
|
||||
TIMEOUT_ACK = 10
|
||||
RECONNECT_INTERVAL_SECONDS = 10
|
||||
|
||||
MAX_WILDCARD_SUBSCRIBES_PER_CALL = 1
|
||||
MAX_SUBSCRIBES_PER_CALL = 500
|
||||
MAX_UNSUBSCRIBES_PER_CALL = 500
|
||||
|
||||
@ -893,14 +894,27 @@ class MQTT:
|
||||
if not self._pending_subscriptions:
|
||||
return
|
||||
|
||||
subscriptions: dict[str, int] = self._pending_subscriptions
|
||||
# Split out the wildcard subscriptions, we subscribe to them one by one
|
||||
pending_subscriptions: dict[str, int] = self._pending_subscriptions
|
||||
pending_wildcard_subscriptions = {
|
||||
subscription.topic: pending_subscriptions.pop(subscription.topic)
|
||||
for subscription in self._wildcard_subscriptions
|
||||
if subscription.topic in pending_subscriptions
|
||||
}
|
||||
|
||||
self._pending_subscriptions = {}
|
||||
|
||||
subscription_list = list(subscriptions.items())
|
||||
debug_enabled = _LOGGER.isEnabledFor(logging.DEBUG)
|
||||
|
||||
for chunk in chunked_or_all(subscription_list, MAX_SUBSCRIBES_PER_CALL):
|
||||
for chunk in chain(
|
||||
chunked_or_all(
|
||||
pending_wildcard_subscriptions.items(), MAX_WILDCARD_SUBSCRIBES_PER_CALL
|
||||
),
|
||||
chunked_or_all(pending_subscriptions.items(), MAX_SUBSCRIBES_PER_CALL),
|
||||
):
|
||||
chunk_list = list(chunk)
|
||||
if not chunk_list:
|
||||
continue
|
||||
|
||||
result, mid = self._mqttc.subscribe(chunk_list)
|
||||
|
||||
|
Reference in New Issue
Block a user