diff --git a/homeassistant/components/mqtt/config_flow.py b/homeassistant/components/mqtt/config_flow.py index c6af0cc08b5..172657ded98 100644 --- a/homeassistant/components/mqtt/config_flow.py +++ b/homeassistant/components/mqtt/config_flow.py @@ -95,8 +95,7 @@ class FlowHandler(config_entries.ConfigFlow, domain=DOMAIN): async def async_step_hassio(self, discovery_info): """Receive a Hass.io discovery.""" - if self._async_current_entries(): - return self.async_abort(reason="single_instance_allowed") + await self._async_handle_discovery_without_unique_id() self._hassio_discovery = discovery_info diff --git a/homeassistant/components/mqtt/strings.json b/homeassistant/components/mqtt/strings.json index 9de9075f19d..155f9fcb4f2 100644 --- a/homeassistant/components/mqtt/strings.json +++ b/homeassistant/components/mqtt/strings.json @@ -20,6 +20,7 @@ } }, "abort": { + "already_configured": "[%key:common::config_flow::abort::already_configured_service%]", "single_instance_allowed": "[%key:common::config_flow::abort::single_instance_allowed%]" }, "error": { diff --git a/homeassistant/components/mqtt/translations/en.json b/homeassistant/components/mqtt/translations/en.json index 775b4d21c9b..23012946a71 100644 --- a/homeassistant/components/mqtt/translations/en.json +++ b/homeassistant/components/mqtt/translations/en.json @@ -1,6 +1,7 @@ { "config": { "abort": { + "already_configured": "Service is already configured", "single_instance_allowed": "Already configured. Only a single configuration possible." }, "error": { diff --git a/tests/components/mqtt/test_config_flow.py b/tests/components/mqtt/test_config_flow.py index 55bacb0ef91..e00e959e606 100644 --- a/tests/components/mqtt/test_config_flow.py +++ b/tests/components/mqtt/test_config_flow.py @@ -7,6 +7,7 @@ import voluptuous as vol from homeassistant import config_entries, data_entry_flow from homeassistant.components import mqtt +from homeassistant.core import HomeAssistant from homeassistant.setup import async_setup_component from tests.common import MockConfigEntry @@ -100,7 +101,7 @@ async def test_user_single_instance(hass): assert result["reason"] == "single_instance_allowed" -async def test_hassio_single_instance(hass): +async def test_hassio_already_configured(hass): """Test we only allow a single config flow.""" MockConfigEntry(domain="mqtt").add_to_hass(hass) @@ -108,7 +109,23 @@ async def test_hassio_single_instance(hass): "mqtt", context={"source": config_entries.SOURCE_HASSIO} ) assert result["type"] == "abort" - assert result["reason"] == "single_instance_allowed" + assert result["reason"] == "already_configured" + + +async def test_hassio_ignored(hass: HomeAssistant) -> None: + """Test we supervisor discovered instance can be ignored.""" + MockConfigEntry( + domain=mqtt.DOMAIN, source=config_entries.SOURCE_IGNORE + ).add_to_hass(hass) + + result = await hass.config_entries.flow.async_init( + mqtt.DOMAIN, + data={"addon": "Mosquitto", "host": "mock-mosquitto", "port": "1883"}, + context={"source": config_entries.SOURCE_HASSIO}, + ) + assert result + assert result.get("type") == data_entry_flow.RESULT_TYPE_ABORT + assert result.get("reason") == "already_configured" async def test_hassio_confirm(hass, mock_try_connection, mock_finish_setup):