Avoid creating tasks to subscribe to discovery in MQTT (#117890)

This commit is contained in:
J. Nick Koston 2024-05-21 16:39:23 -10:00 committed by GitHub
parent 009c9e79ae
commit 09213d8933
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -362,16 +362,15 @@ async def async_start( # noqa: C901
hass, MQTT_DISCOVERY_DONE.format(*discovery_hash), None
)
discovery_topics = [
f"{discovery_topic}/+/+/config",
f"{discovery_topic}/+/+/+/config",
]
mqtt_data.discovery_unsubscribe = await asyncio.gather(
*(
mqtt.async_subscribe(hass, topic, async_discovery_message_received, 0)
for topic in discovery_topics
# async_subscribe will never suspend so there is no need to create a task
# here and its faster to await them in sequence
mqtt_data.discovery_unsubscribe = [
await mqtt.async_subscribe(hass, topic, async_discovery_message_received, 0)
for topic in (
f"{discovery_topic}/+/+/config",
f"{discovery_topic}/+/+/+/config",
)
)
]
mqtt_data.last_discovery = time.monotonic()
mqtt_integrations = await async_get_mqtt(hass)