From c4c2b4f9da8a5af674b4ae2854427da817a45535 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 25 Apr 2020 17:08:37 -0500 Subject: [PATCH] Add ability to ignore rachio discovery (#34649) * Add ability to ignore rachio discovery * update test * Update tests/components/rachio/test_config_flow.py Co-Authored-By: Chris Talkington * Update tests/components/rachio/test_config_flow.py Co-Authored-By: Chris Talkington Co-authored-by: Chris Talkington --- homeassistant/components/rachio/config_flow.py | 4 ++++ tests/components/rachio/test_config_flow.py | 14 ++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/rachio/config_flow.py b/homeassistant/components/rachio/config_flow.py index 2f5835ad614..df9ead463f7 100644 --- a/homeassistant/components/rachio/config_flow.py +++ b/homeassistant/components/rachio/config_flow.py @@ -89,6 +89,10 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): # they already have one configured as they can always # add a new one via "+" return self.async_abort(reason="already_configured") + properties = { + key.lower(): value for (key, value) in homekit_info["properties"].items() + } + await self.async_set_unique_id(properties["id"]) 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 57575fe5501..cadc346e403 100644 --- a/tests/components/rachio/test_config_flow.py +++ b/tests/components/rachio/test_config_flow.py @@ -111,16 +111,26 @@ async def test_form_homekit(hass): await setup.async_setup_component(hass, "persistent_notification", {}) result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "homekit"} + DOMAIN, + context={"source": "homekit"}, + data={"properties": {"id": "AA:BB:CC:DD:EE:FF"}}, ) assert result["type"] == "form" assert result["errors"] == {} + flow = next( + flow + for flow in hass.config_entries.flow.async_progress() + if flow["flow_id"] == result["flow_id"] + ) + assert flow["context"]["unique_id"] == "AA:BB:CC:DD:EE:FF" 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"} + DOMAIN, + context={"source": "homekit"}, + data={"properties": {"id": "AA:BB:CC:DD:EE:FF"}}, ) assert result["type"] == "abort" assert result["reason"] == "already_configured"