Skip to content

Commit

Permalink
Avoid creating tasks to subscribe to discovery in MQTT (#117890)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco committed May 22, 2024
1 parent 009c9e7 commit 09213d8
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions homeassistant/components/mqtt/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,16 +362,15 @@ def discovery_done(_: Any) -> None:
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)
Expand Down

0 comments on commit 09213d8

Please sign in to comment.