diff --git a/homeassistant/components/rachio/config_flow.py b/homeassistant/components/rachio/config_flow.py index 3a4c2a1c171..9eff7c99334 100644 --- a/homeassistant/components/rachio/config_flow.py +++ b/homeassistant/components/rachio/config_flow.py @@ -84,6 +84,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 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() async def async_step_import(self, user_input): diff --git a/tests/components/rachio/test_config_flow.py b/tests/components/rachio/test_config_flow.py index f5df0817846..57575fe5501 100644 --- a/tests/components/rachio/test_config_flow.py +++ b/tests/components/rachio/test_config_flow.py @@ -10,6 +10,8 @@ from homeassistant.components.rachio.const import ( ) from homeassistant.const import CONF_API_KEY +from tests.common import MockConfigEntry + def _mock_rachio_return_value(get=None, getInfo=None): rachio_mock = MagicMock() @@ -102,3 +104,23 @@ 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 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"