mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 12:17:07 +00:00
Ensure MQTT subscriptions can be made when the broker is disconnected (#132270)
This commit is contained in:
parent
4fd4ba7813
commit
333ada7670
@ -227,7 +227,7 @@ def async_subscribe_internal(
|
||||
translation_placeholders={"topic": topic},
|
||||
) from exc
|
||||
client = mqtt_data.client
|
||||
if not client.connected and not mqtt_config_entry_enabled(hass):
|
||||
if not mqtt_config_entry_enabled(hass):
|
||||
raise HomeAssistantError(
|
||||
f"Cannot subscribe to topic '{topic}', MQTT is not enabled",
|
||||
translation_key="mqtt_not_setup_cannot_subscribe",
|
||||
|
@ -1045,10 +1045,17 @@ async def test_restore_subscriptions_on_reconnect(
|
||||
mqtt_client_mock.reset_mock()
|
||||
mqtt_client_mock.on_disconnect(None, None, 0)
|
||||
|
||||
# Test to subscribe orther topic while the client is not connected
|
||||
await mqtt.async_subscribe(hass, "test/other", record_calls)
|
||||
async_fire_time_changed(hass, utcnow() + timedelta(seconds=3)) # cooldown
|
||||
assert ("test/other", 0) not in help_all_subscribe_calls(mqtt_client_mock)
|
||||
|
||||
mock_debouncer.clear()
|
||||
mqtt_client_mock.on_connect(None, None, None, 0)
|
||||
await mock_debouncer.wait()
|
||||
# Assert all subscriptions are performed at the broker
|
||||
assert ("test/state", 0) in help_all_subscribe_calls(mqtt_client_mock)
|
||||
assert ("test/other", 0) in help_all_subscribe_calls(mqtt_client_mock)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
Loading…
x
Reference in New Issue
Block a user