diff --git a/homeassistant/components/myq/config_flow.py b/homeassistant/components/myq/config_flow.py index baa7aad4cffff..07d57921e35d0 100644 --- a/homeassistant/components/myq/config_flow.py +++ b/homeassistant/components/myq/config_flow.py @@ -67,6 +67,14 @@ async def async_step_user(self, user_input=None): 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): diff --git a/homeassistant/components/myq/strings.json b/homeassistant/components/myq/strings.json index c31162b28949f..2aa0eab328e47 100644 --- a/homeassistant/components/myq/strings.json +++ b/homeassistant/components/myq/strings.json @@ -19,4 +19,4 @@ "already_configured": "MyQ is already configured" } } -} \ No newline at end of file +} diff --git a/tests/components/myq/test_config_flow.py b/tests/components/myq/test_config_flow.py index c0bae8c522522..9fb3b34ca6318 100644 --- a/tests/components/myq/test_config_flow.py +++ b/tests/components/myq/test_config_flow.py @@ -4,6 +4,9 @@ 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"