Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Abort myq homekit config when one is already setup. #33218

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"