mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 05:37:44 +00:00
Abort myq homekit config when one is already setup. (#33218)
We can see myq on the network to tell them to configure it, but since the device will not give up the account it is bound to and there can be multiple myq gateways on a single account, we avoid showing the device as discovered once they already have one configured as they can always add a new one via "+"
This commit is contained in:
parent
46985bba0d
commit
2a36adae46
@ -67,6 +67,14 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
|
||||
async def async_step_homekit(self, homekit_info):
|
||||
"""Handle HomeKit discovery."""
|
||||
if self._async_current_entries():
|
||||
# We can see myq on the network to tell them to configure
|
||||
# it, but since the device will not give up the account it is
|
||||
# bound to and there can be multiple myq gateways on a single
|
||||
# account, we avoid showing the device as discovered once
|
||||
# they already have one configured as they can always
|
||||
# add a new one via "+"
|
||||
return self.async_abort(reason="already_configured")
|
||||
return await self.async_step_user()
|
||||
|
||||
async def async_step_import(self, user_input):
|
||||
|
@ -19,4 +19,4 @@
|
||||
"already_configured": "MyQ is already configured"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,9 @@ from pymyq.errors import InvalidCredentialsError, MyQError
|
||||
|
||||
from homeassistant import config_entries, setup
|
||||
from homeassistant.components.myq.const import DOMAIN
|
||||
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
async def test_form_user(hass):
|
||||
@ -101,3 +104,24 @@ async def test_form_cannot_connect(hass):
|
||||
|
||||
assert result2["type"] == "form"
|
||||
assert result2["errors"] == {"base": "cannot_connect"}
|
||||
|
||||
|
||||
async def test_form_homekit(hass):
|
||||
"""Test that we abort from homekit if myq is already setup."""
|
||||
await setup.async_setup_component(hass, "persistent_notification", {})
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": "homekit"}
|
||||
)
|
||||
assert result["type"] == "form"
|
||||
assert result["errors"] == {}
|
||||
|
||||
entry = MockConfigEntry(
|
||||
domain=DOMAIN, data={CONF_USERNAME: "mock", CONF_PASSWORD: "mock"}
|
||||
)
|
||||
entry.add_to_hass(hass)
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": "homekit"}
|
||||
)
|
||||
assert result["type"] == "abort"
|
||||
|
Loading…
x
Reference in New Issue
Block a user