Make mqtt discovery use callback functions (#87883)
parent
87a8a3c166
commit
1d4d688af3
|
@ -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] = {
|
||||
|
|
Loading…
Reference in New Issue