Make mqtt discovery use callback functions (#87883)

pull/87950/head^2
J. Nick Koston 2023-02-12 13:41:03 -06:00 committed by GitHub
parent 87a8a3c166
commit 1d4d688af3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 9 deletions

View File

@ -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] = {