Fix mqtt is not reloading without yaml config (#103159)
This commit is contained in:
parent
6ea5af7575
commit
daee5baef6
2 changed files with 37 additions and 1 deletions
|
@ -233,7 +233,7 @@ async def async_check_config_schema(
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Validate manually configured MQTT items."""
|
"""Validate manually configured MQTT items."""
|
||||||
mqtt_data = get_mqtt_data(hass)
|
mqtt_data = get_mqtt_data(hass)
|
||||||
mqtt_config: list[dict[str, list[ConfigType]]] = config_yaml[DOMAIN]
|
mqtt_config: list[dict[str, list[ConfigType]]] = config_yaml.get(DOMAIN, {})
|
||||||
for mqtt_config_item in mqtt_config:
|
for mqtt_config_item in mqtt_config:
|
||||||
for domain, config_items in mqtt_config_item.items():
|
for domain, config_items in mqtt_config_item.items():
|
||||||
schema = mqtt_data.reload_schema[domain]
|
schema = mqtt_data.reload_schema[domain]
|
||||||
|
|
|
@ -3974,3 +3974,39 @@ async def test_reload_with_invalid_config(
|
||||||
|
|
||||||
# Test nothing changed as loading the config failed
|
# Test nothing changed as loading the config failed
|
||||||
assert hass.states.get("sensor.test") is not None
|
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
|
||||||
|
|
Loading…
Add table
Reference in a new issue