Abort rachio homekit config when one is already setup (#33285)

* Abort rachio homekit config when one is already setup.

We can see rachio 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 rachio controllers 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 "+"

* doc string freshness

* doc string freshness

* Update tests/components/rachio/test_config_flow.py

Co-Authored-By: Franck Nijhof <git@frenck.dev>

Co-authored-by: Franck Nijhof <git@frenck.dev>
This commit is contained in:
J. Nick Koston 2020-03-26 17:14:52 -05:00 committed by GitHub
parent b8afb9277a
commit f5a6c3484d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 0 deletions

View file

@ -84,6 +84,14 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
async def async_step_homekit(self, homekit_info): async def async_step_homekit(self, homekit_info):
"""Handle HomeKit discovery.""" """Handle HomeKit discovery."""
if self._async_current_entries():
# We can see rachio 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 rachio systems 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() return await self.async_step_user()
async def async_step_import(self, user_input): async def async_step_import(self, user_input):

View file

@ -10,6 +10,8 @@ from homeassistant.components.rachio.const import (
) )
from homeassistant.const import CONF_API_KEY from homeassistant.const import CONF_API_KEY
from tests.common import MockConfigEntry
def _mock_rachio_return_value(get=None, getInfo=None): def _mock_rachio_return_value(get=None, getInfo=None):
rachio_mock = MagicMock() rachio_mock = MagicMock()
@ -102,3 +104,23 @@ async def test_form_cannot_connect(hass):
assert result2["type"] == "form" assert result2["type"] == "form"
assert result2["errors"] == {"base": "cannot_connect"} assert result2["errors"] == {"base": "cannot_connect"}
async def test_form_homekit(hass):
"""Test that we abort from homekit if rachio 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_API_KEY: "api_key"})
entry.add_to_hass(hass)
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": "homekit"}
)
assert result["type"] == "abort"
assert result["reason"] == "already_configured"