1
0
mirror of https://github.com/home-assistant/core.git synced 2026-04-02 08:26:41 +01:00

Add repair flow when MQTT YAML config is present but the broker is not set up correctly (#165090)

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
This commit is contained in:
Jan Bouwhuis
2026-03-30 16:16:31 +02:00
committed by GitHub
parent 607462028b
commit 14b9915914
3 changed files with 61 additions and 1 deletions

View File

@@ -311,6 +311,19 @@ def _platforms_in_use(hass: HomeAssistant, entry: ConfigEntry) -> set[str | Plat
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Set up the actions and websocket API for the MQTT component."""
if config.get(DOMAIN) and not mqtt_config_entry_enabled(hass):
issue_registry = ir.async_get(hass)
issue_registry.async_get_or_create(
DOMAIN,
"yaml_setup_without_active_setup",
is_fixable=False,
is_persistent=False,
severity=ir.IssueSeverity.WARNING,
learn_more_url="https://www.home-assistant.io/integrations/mqtt/"
"#configuration",
translation_key="yaml_setup_without_active_setup",
)
websocket_api.async_register_command(hass, websocket_subscribe)
websocket_api.async_register_command(hass, websocket_mqtt_info)

View File

@@ -1141,6 +1141,10 @@
}
},
"title": "MQTT device \"{name}\" subentry migration to YAML"
},
"yaml_setup_without_active_setup": {
"description": "Home Assistant detected manually configured MQTT items, but these items cannot be loaded because MQTT is not set up correctly. Make sure the MQTT broker is set up correctly, or remove the MQTT configuration from your `configuration.yaml` file and restart Home Assistant to fix this issue.",
"title": "MQTT is not set up correctly"
}
},
"options": {

View File

@@ -33,7 +33,12 @@ from homeassistant.const import (
)
from homeassistant.core import HomeAssistant, callback
from homeassistant.exceptions import HomeAssistantError, ServiceValidationError
from homeassistant.helpers import device_registry as dr, entity_registry as er, template
from homeassistant.helpers import (
device_registry as dr,
entity_registry as er,
issue_registry as ir,
template,
)
from homeassistant.helpers.entity import Entity
from homeassistant.helpers.entity_platform import async_get_platforms
from homeassistant.helpers.typing import ConfigType
@@ -2304,3 +2309,41 @@ async def test_multi_platform_discovery(
async def test_mqtt_integration_level_imports(attr: str) -> None:
"""Test mqtt integration level public published imports are available."""
assert hasattr(mqtt, attr)
@pytest.mark.usefixtures("mqtt_client_mock")
@pytest.mark.parametrize(
"hass_config", [{mqtt.DOMAIN: {"sensor": {"state_topic": "test-topic"}}}]
)
async def test_yaml_config_without_entry(
hass: HomeAssistant, hass_config: ConfigType, issue_registry: ir.IssueRegistry
) -> None:
"""Test a repair issue is created for YAML setup without an active config entry."""
await async_setup_component(hass, mqtt.DOMAIN, hass_config)
issue = issue_registry.async_get_issue(
mqtt.DOMAIN, "yaml_setup_without_active_setup"
)
assert issue is not None
assert (
issue.learn_more_url == "https://www.home-assistant.io/integrations/mqtt/"
"#configuration"
)
@pytest.mark.parametrize(
"hass_config", [{mqtt.DOMAIN: {"sensor": {"state_topic": "test-topic"}}}]
)
async def test_yaml_config_with_active_mqtt_config_entry(
hass: HomeAssistant,
hass_config: ConfigType,
mqtt_mock_entry: MqttMockHAClientGenerator,
issue_registry: ir.IssueRegistry,
) -> None:
"""Test no repair issue is created for YAML setup with an active config entry."""
await mqtt_mock_entry()
issue = issue_registry.async_get_issue(
mqtt.DOMAIN, "yaml_setup_without_active_setup"
)
state = hass.states.get("sensor.mqtt_sensor")
assert state is not None
assert issue is None