Fix mqtt is not reloading without yaml config (#103159)

This commit is contained in:
Jan Bouwhuis
2023-11-01 09:25:56 +01:00
committed by GitHub
parent 6ea5af7575
commit daee5baef6
2 changed files with 37 additions and 1 deletions

View File

@ -3974,3 +3974,39 @@ async def test_reload_with_invalid_config(
# Test nothing changed as loading the config failed
assert hass.states.get("sensor.test") is not None
@pytest.mark.parametrize(
"hass_config",
[
{
"mqtt": [
{
"sensor": {
"name": "test",
"state_topic": "test-topic",
}
},
]
}
],
)
async def test_reload_with_empty_config(
hass: HomeAssistant,
mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None:
"""Test reloading yaml config fails."""
await mqtt_mock_entry()
assert hass.states.get("sensor.test") is not None
# Reload with an empty config and assert again
with patch("homeassistant.config.load_yaml_config_file", return_value={}):
await hass.services.async_call(
"mqtt",
SERVICE_RELOAD,
{},
blocking=True,
)
await hass.async_block_till_done()
assert hass.states.get("sensor.test") is None