Skip to content

Commit

Permalink
Abort myq homekit config when one is already setup. (home-assistant#3…
Browse files Browse the repository at this point in the history
…3218)

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 "+"
  • Loading branch information
bdraco authored Mar 25, 2020
1 parent 46985bb commit 2a36ada
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
8 changes: 8 additions & 0 deletions homeassistant/components/myq/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/myq/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@
"already_configured": "MyQ is already configured"
}
}
}
}
24 changes: 24 additions & 0 deletions tests/components/myq/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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"

0 comments on commit 2a36ada

Please sign in to comment.