mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 12:17:07 +00:00
Avoid creating tasks to subscribe to discovery in MQTT (#117890)
This commit is contained in:
parent
009c9e79ae
commit
09213d8933
@ -362,16 +362,15 @@ async def async_start( # noqa: C901
|
|||||||
hass, MQTT_DISCOVERY_DONE.format(*discovery_hash), None
|
hass, MQTT_DISCOVERY_DONE.format(*discovery_hash), None
|
||||||
)
|
)
|
||||||
|
|
||||||
discovery_topics = [
|
# async_subscribe will never suspend so there is no need to create a task
|
||||||
f"{discovery_topic}/+/+/config",
|
# here and its faster to await them in sequence
|
||||||
f"{discovery_topic}/+/+/+/config",
|
mqtt_data.discovery_unsubscribe = [
|
||||||
]
|
await mqtt.async_subscribe(hass, topic, async_discovery_message_received, 0)
|
||||||
mqtt_data.discovery_unsubscribe = await asyncio.gather(
|
for topic in (
|
||||||
*(
|
f"{discovery_topic}/+/+/config",
|
||||||
mqtt.async_subscribe(hass, topic, async_discovery_message_received, 0)
|
f"{discovery_topic}/+/+/+/config",
|
||||||
for topic in discovery_topics
|
|
||||||
)
|
)
|
||||||
)
|
]
|
||||||
|
|
||||||
mqtt_data.last_discovery = time.monotonic()
|
mqtt_data.last_discovery = time.monotonic()
|
||||||
mqtt_integrations = await async_get_mqtt(hass)
|
mqtt_integrations = await async_get_mqtt(hass)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user