Test discovery subscriptions not done when discovery is disabled (#129458)

Test discovery subscriptions not performend when discovery is disabled
pull/129502/head
Jan Bouwhuis 2024-10-30 14:38:44 +01:00 committed by GitHub
parent a6189106e1
commit 4e7397dc9d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 35 additions and 1 deletions

View File

@ -87,7 +87,8 @@ async def setup_with_birth_msg_client_mock(
patch("homeassistant.components.mqtt.client.SUBSCRIBE_COOLDOWN", 0.0), patch("homeassistant.components.mqtt.client.SUBSCRIBE_COOLDOWN", 0.0),
): ):
entry = MockConfigEntry( entry = MockConfigEntry(
domain=mqtt.DOMAIN, data={mqtt.CONF_BROKER: "test-broker"} domain=mqtt.DOMAIN,
data=mqtt_config_entry_data or {mqtt.CONF_BROKER: "test-broker"},
) )
entry.add_to_hass(hass) entry.add_to_hass(hass)
hass.config.components.add(mqtt.DOMAIN) hass.config.components.add(mqtt.DOMAIN)

View File

@ -1716,6 +1716,39 @@ async def test_mqtt_subscribes_topics_on_connect(
assert ("still/pending", 1) in subscribe_calls assert ("still/pending", 1) in subscribe_calls
@pytest.mark.parametrize(
"mqtt_config_entry_data",
[ENTRY_DEFAULT_BIRTH_MESSAGE | {mqtt.CONF_DISCOVERY: False}],
)
async def test_mqtt_discovery_not_subscribes_when_disabled(
hass: HomeAssistant,
mock_debouncer: asyncio.Event,
setup_with_birth_msg_client_mock: MqttMockPahoClient,
) -> None:
"""Test discovery subscriptions not performend when discovery is disabled."""
mqtt_client_mock = setup_with_birth_msg_client_mock
await mock_debouncer.wait()
subscribe_calls = help_all_subscribe_calls(mqtt_client_mock)
for component in SUPPORTED_COMPONENTS:
assert (f"homeassistant/{component}/+/config", 0) not in subscribe_calls
assert (f"homeassistant/{component}/+/+/config", 0) not in subscribe_calls
mqtt_client_mock.on_disconnect(Mock(), None, 0)
mqtt_client_mock.reset_mock()
mock_debouncer.clear()
mqtt_client_mock.on_connect(Mock(), None, 0, 0)
await mock_debouncer.wait()
subscribe_calls = help_all_subscribe_calls(mqtt_client_mock)
for component in SUPPORTED_COMPONENTS:
assert (f"homeassistant/{component}/+/config", 0) not in subscribe_calls
assert (f"homeassistant/{component}/+/+/config", 0) not in subscribe_calls
@pytest.mark.parametrize( @pytest.mark.parametrize(
"mqtt_config_entry_data", "mqtt_config_entry_data",
[ENTRY_DEFAULT_BIRTH_MESSAGE], [ENTRY_DEFAULT_BIRTH_MESSAGE],