Fix MQTT add-on discovery to be ignorable (#55250)
parent
03d3bbfba1
commit
96303a1d80
|
@ -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
|
||||
|
||||
|
|
|
@ -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": {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
{
|
||||
"config": {
|
||||
"abort": {
|
||||
"already_configured": "Service is already configured",
|
||||
"single_instance_allowed": "Already configured. Only a single configuration possible."
|
||||
},
|
||||
"error": {
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue