mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Make mqtt discovery use callback functions (#87883)
This commit is contained in:
parent
87a8a3c166
commit
1d4d688af3
@ -11,7 +11,7 @@ from typing import Any
|
|||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import CONF_DEVICE, CONF_PLATFORM
|
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
|
from homeassistant.data_entry_flow import FlowResultType
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers.dispatcher import (
|
from homeassistant.helpers.dispatcher import (
|
||||||
@ -98,7 +98,8 @@ async def async_start( # noqa: C901
|
|||||||
mqtt_data = get_mqtt_data(hass)
|
mqtt_data = get_mqtt_data(hass)
|
||||||
mqtt_integrations = {}
|
mqtt_integrations = {}
|
||||||
|
|
||||||
async def async_discovery_message_received(msg: ReceiveMessage) -> None:
|
@callback
|
||||||
|
def async_discovery_message_received(msg: ReceiveMessage) -> None:
|
||||||
"""Process the received message."""
|
"""Process the received message."""
|
||||||
mqtt_data.last_discovery = time.time()
|
mqtt_data.last_discovery = time.time()
|
||||||
payload = msg.payload
|
payload = msg.payload
|
||||||
@ -205,11 +206,10 @@ async def async_start( # noqa: C901
|
|||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
await async_process_discovery_payload(
|
async_process_discovery_payload(component, discovery_id, 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
|
component: str, discovery_id: str, payload: MQTTDiscoveryPayload
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Process the payload of a new discovery."""
|
"""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)
|
mqtt_data.discovery_pending_discovered.pop(discovery_hash)
|
||||||
else:
|
else:
|
||||||
payload = pending.pop()
|
payload = pending.pop()
|
||||||
await async_process_discovery_payload(
|
async_process_discovery_payload(component, discovery_id, payload)
|
||||||
component, discovery_id, payload
|
|
||||||
)
|
|
||||||
|
|
||||||
if discovery_hash not in mqtt_data.discovery_pending_discovered:
|
if discovery_hash not in mqtt_data.discovery_pending_discovered:
|
||||||
mqtt_data.discovery_pending_discovered[discovery_hash] = {
|
mqtt_data.discovery_pending_discovered[discovery_hash] = {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user