From 1d4d688af338454845acf26deccae5eda79aac7e Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 12 Feb 2023 13:41:03 -0600 Subject: [PATCH] Make mqtt discovery use callback functions (#87883) --- homeassistant/components/mqtt/discovery.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/homeassistant/components/mqtt/discovery.py b/homeassistant/components/mqtt/discovery.py index e76d73d6211..4573dfcb879 100644 --- a/homeassistant/components/mqtt/discovery.py +++ b/homeassistant/components/mqtt/discovery.py @@ -11,7 +11,7 @@ from typing import Any from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_DEVICE, CONF_PLATFORM -from homeassistant.core import HomeAssistant +from homeassistant.core import HomeAssistant, callback from homeassistant.data_entry_flow import FlowResultType import homeassistant.helpers.config_validation as cv from homeassistant.helpers.dispatcher import ( @@ -98,7 +98,8 @@ async def async_start( # noqa: C901 mqtt_data = get_mqtt_data(hass) mqtt_integrations = {} - async def async_discovery_message_received(msg: ReceiveMessage) -> None: + @callback + def async_discovery_message_received(msg: ReceiveMessage) -> None: """Process the received message.""" mqtt_data.last_discovery = time.time() payload = msg.payload @@ -205,11 +206,10 @@ async def async_start( # noqa: C901 ) return - await async_process_discovery_payload( - component, discovery_id, discovery_payload - ) + async_process_discovery_payload(component, discovery_id, discovery_payload) - async def async_process_discovery_payload( + @callback + def async_process_discovery_payload( component: str, discovery_id: str, payload: MQTTDiscoveryPayload ) -> None: """Process the payload of a new discovery.""" @@ -228,9 +228,7 @@ async def async_start( # noqa: C901 mqtt_data.discovery_pending_discovered.pop(discovery_hash) else: payload = pending.pop() - await async_process_discovery_payload( - component, discovery_id, payload - ) + async_process_discovery_payload(component, discovery_id, payload) if discovery_hash not in mqtt_data.discovery_pending_discovered: mqtt_data.discovery_pending_discovered[discovery_hash] = {