Migrate mqtt discovery subscribes to use internal helper (#118279)
parent
63227f14ed
commit
69a177e864
|
@ -329,8 +329,7 @@ async def async_start( # noqa: C901
|
||||||
|
|
||||||
mqtt_data.last_discovery = time.monotonic()
|
mqtt_data.last_discovery = time.monotonic()
|
||||||
mqtt_integrations = await async_get_mqtt(hass)
|
mqtt_integrations = await async_get_mqtt(hass)
|
||||||
|
integration_unsubscribe = mqtt_data.integration_unsubscribe
|
||||||
for integration, topics in mqtt_integrations.items():
|
|
||||||
|
|
||||||
async def async_integration_message_received(
|
async def async_integration_message_received(
|
||||||
integration: str, msg: ReceiveMessage
|
integration: str, msg: ReceiveMessage
|
||||||
|
@ -344,7 +343,7 @@ async def async_start( # noqa: C901
|
||||||
# Note: The lock is not intended to prevent a race, only for performance
|
# Note: The lock is not intended to prevent a race, only for performance
|
||||||
async with mqtt_data.data_config_flow_lock:
|
async with mqtt_data.data_config_flow_lock:
|
||||||
# Already unsubscribed
|
# Already unsubscribed
|
||||||
if key not in mqtt_data.integration_unsubscribe:
|
if key not in integration_unsubscribe:
|
||||||
return
|
return
|
||||||
|
|
||||||
data = MqttServiceInfo(
|
data = MqttServiceInfo(
|
||||||
|
@ -364,16 +363,18 @@ async def async_start( # noqa: C901
|
||||||
and result["reason"]
|
and result["reason"]
|
||||||
in ("already_configured", "single_instance_allowed")
|
in ("already_configured", "single_instance_allowed")
|
||||||
):
|
):
|
||||||
mqtt_data.integration_unsubscribe.pop(key)()
|
integration_unsubscribe.pop(key)()
|
||||||
|
|
||||||
mqtt_data.integration_unsubscribe.update(
|
integration_unsubscribe.update(
|
||||||
{
|
{
|
||||||
f"{integration}_{topic}": await mqtt.async_subscribe(
|
f"{integration}_{topic}": mqtt.async_subscribe_internal(
|
||||||
hass,
|
hass,
|
||||||
topic,
|
topic,
|
||||||
functools.partial(async_integration_message_received, integration),
|
functools.partial(async_integration_message_received, integration),
|
||||||
0,
|
0,
|
||||||
|
job_type=HassJobType.Coroutinefunction,
|
||||||
)
|
)
|
||||||
|
for integration, topics in mqtt_integrations.items()
|
||||||
for topic in topics
|
for topic in topics
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue