mirror of
https://github.com/home-assistant/core.git
synced 2025-07-26 06:37:52 +00:00
Fix MQTT add-on discovery to be ignorable (#55250)
This commit is contained in:
parent
03d3bbfba1
commit
96303a1d80
@ -95,8 +95,7 @@ class FlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
|
|
||||||
async def async_step_hassio(self, discovery_info):
|
async def async_step_hassio(self, discovery_info):
|
||||||
"""Receive a Hass.io discovery."""
|
"""Receive a Hass.io discovery."""
|
||||||
if self._async_current_entries():
|
await self._async_handle_discovery_without_unique_id()
|
||||||
return self.async_abort(reason="single_instance_allowed")
|
|
||||||
|
|
||||||
self._hassio_discovery = discovery_info
|
self._hassio_discovery = discovery_info
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"abort": {
|
"abort": {
|
||||||
|
"already_configured": "[%key:common::config_flow::abort::already_configured_service%]",
|
||||||
"single_instance_allowed": "[%key:common::config_flow::abort::single_instance_allowed%]"
|
"single_instance_allowed": "[%key:common::config_flow::abort::single_instance_allowed%]"
|
||||||
},
|
},
|
||||||
"error": {
|
"error": {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
"config": {
|
"config": {
|
||||||
"abort": {
|
"abort": {
|
||||||
|
"already_configured": "Service is already configured",
|
||||||
"single_instance_allowed": "Already configured. Only a single configuration possible."
|
"single_instance_allowed": "Already configured. Only a single configuration possible."
|
||||||
},
|
},
|
||||||
"error": {
|
"error": {
|
||||||
|
@ -7,6 +7,7 @@ import voluptuous as vol
|
|||||||
|
|
||||||
from homeassistant import config_entries, data_entry_flow
|
from homeassistant import config_entries, data_entry_flow
|
||||||
from homeassistant.components import mqtt
|
from homeassistant.components import mqtt
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from tests.common import MockConfigEntry
|
from tests.common import MockConfigEntry
|
||||||
@ -100,7 +101,7 @@ async def test_user_single_instance(hass):
|
|||||||
assert result["reason"] == "single_instance_allowed"
|
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."""
|
"""Test we only allow a single config flow."""
|
||||||
MockConfigEntry(domain="mqtt").add_to_hass(hass)
|
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}
|
"mqtt", context={"source": config_entries.SOURCE_HASSIO}
|
||||||
)
|
)
|
||||||
assert result["type"] == "abort"
|
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):
|
async def test_hassio_confirm(hass, mock_try_connection, mock_finish_setup):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user