From f5a6c3484d1ecf4f1ffe4d5b7a471a08862aeffc Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 26 Mar 2020 17:14:52 -0500 Subject: [PATCH] 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 Co-authored-by: Franck Nijhof --- .../components/rachio/config_flow.py | 8 +++++++ tests/components/rachio/test_config_flow.py | 22 +++++++++++++++++++ 2 files changed, 30 insertions(+) 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"