Subscribe per component for MQTT discovery (#119974)

* Subscribe per component for MQTT discovery

* Use single assignment

* Handle wildcard subscriptions first

* Split subsRecription handling, update helper

* Fix help_all_subscribe_calls

* Fix import

* Fix test

* Update import order

* Undo move self._last_subscribe

* Recover removed test

* Revert not needed changes to binary_sensor platform tests

* Revert line removal

* Rework interation of discovery topics

* Reduce

* Add comment

* Move comment

* Chain subscriptions
This commit is contained in:
Jan Bouwhuis
2024-08-20 17:02:48 +02:00
committed by GitHub
parent a1e3e7f24f
commit b74aced6f3
5 changed files with 50 additions and 26 deletions

View File

@@ -13,6 +13,7 @@ import pytest
from homeassistant.components import mqtt
from homeassistant.components.mqtt.client import RECONNECT_INTERVAL_SECONDS
from homeassistant.components.mqtt.const import SUPPORTED_COMPONENTS
from homeassistant.components.mqtt.models import MessageCallbackType, ReceiveMessage
from homeassistant.config_entries import ConfigEntryDisabler, ConfigEntryState
from homeassistant.const import (
@@ -1614,8 +1615,9 @@ async def test_subscription_done_when_birth_message_is_sent(
"""Test sending birth message until initial subscription has been completed."""
mqtt_client_mock = setup_with_birth_msg_client_mock
subscribe_calls = help_all_subscribe_calls(mqtt_client_mock)
assert ("homeassistant/+/+/config", 0) in subscribe_calls
assert ("homeassistant/+/+/+/config", 0) in subscribe_calls
for component in SUPPORTED_COMPONENTS:
assert (f"homeassistant/{component}/+/config", 0) in subscribe_calls
assert (f"homeassistant/{component}/+/+/config", 0) in subscribe_calls
mqtt_client_mock.publish.assert_called_with(
"homeassistant/status", "online", 0, False
)