Compare commits

...

4 Commits

Author SHA1 Message Date
jbouwh
8c7478eb26 Add extra test case 2026-03-07 23:14:50 +00:00
Jan Bouwhuis
75c2ba223b Apply suggestion from @Copilot
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2026-03-08 00:05:58 +01:00
Jan Bouwhuis
f09441e47a Apply suggestion from @Copilot
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2026-03-08 00:05:37 +01:00
jbouwh
f21c48f80f Add repair flow when MQTT YAML config is present but the broker is not set up correctly 2026-03-07 22:52:51 +00:00
3 changed files with 62 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,42 @@ 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
) -> 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_registry = ir.async_get(hass)
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_entry_(
hass: HomeAssistant,
hass_config: ConfigType,
mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None:
"""Test no repair issue is created for YAML setup with an active config entry."""
await mqtt_mock_entry()
issue_registry = ir.async_get(hass)
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