From 5e9061ed17af15e5fafc83faf32ab26747625614 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Fri, 24 Apr 2020 15:51:32 +0000 Subject: [PATCH 1/4] Add ability to ignore tado discovery --- homeassistant/components/tado/config_flow.py | 4 ++++ tests/components/tado/test_config_flow.py | 8 ++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/tado/config_flow.py b/homeassistant/components/tado/config_flow.py index c14b4284cf3167..fb60b820ab98b2 100644 --- a/homeassistant/components/tado/config_flow.py +++ b/homeassistant/components/tado/config_flow.py @@ -92,6 +92,10 @@ async def async_step_homekit(self, homekit_info): # 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/tado/test_config_flow.py b/tests/components/tado/test_config_flow.py index fb9156d96d9e10..59d891ef6b2b39 100644 --- a/tests/components/tado/test_config_flow.py +++ b/tests/components/tado/test_config_flow.py @@ -151,7 +151,9 @@ 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"] == {} @@ -162,6 +164,8 @@ async def test_form_homekit(hass): 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" From b83f3fcf0609f6b82acde7bd4f292de1b709d6b2 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 25 Apr 2020 02:41:04 +0000 Subject: [PATCH 2/4] update test --- tests/components/tado/test_config_flow.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/components/tado/test_config_flow.py b/tests/components/tado/test_config_flow.py index 59d891ef6b2b39..aac679afe592bf 100644 --- a/tests/components/tado/test_config_flow.py +++ b/tests/components/tado/test_config_flow.py @@ -157,6 +157,8 @@ async def test_form_homekit(hass): ) assert result["type"] == "form" assert result["errors"] == {} + flows_in_progress = hass.config_entries.flow.async_progress() + assert flows_in_progress[0]["context"]["unique_id"] == "AA:BB:CC:DD:EE:FF" entry = MockConfigEntry( domain=DOMAIN, data={CONF_USERNAME: "mock", CONF_PASSWORD: "mock"} From f9f1736e2a0d0f5b084572affbd43a027337b2ca Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 25 Apr 2020 15:49:21 -0500 Subject: [PATCH 3/4] Update tests/components/tado/test_config_flow.py Co-Authored-By: Chris Talkington --- tests/components/tado/test_config_flow.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/components/tado/test_config_flow.py b/tests/components/tado/test_config_flow.py index aac679afe592bf..487742e2490c94 100644 --- a/tests/components/tado/test_config_flow.py +++ b/tests/components/tado/test_config_flow.py @@ -157,7 +157,11 @@ async def test_form_homekit(hass): ) assert result["type"] == "form" assert result["errors"] == {} - flows_in_progress = hass.config_entries.flow.async_progress() + flow = next( + flow + for flow in hass.config_entries.flow.async_progress() + if flow["flow_id"] == result["flow_id"] + ) assert flows_in_progress[0]["context"]["unique_id"] == "AA:BB:CC:DD:EE:FF" entry = MockConfigEntry( From ffc2047490770129a6b0c13298c304284a887fc9 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 25 Apr 2020 15:49:27 -0500 Subject: [PATCH 4/4] Update tests/components/tado/test_config_flow.py Co-Authored-By: Chris Talkington --- tests/components/tado/test_config_flow.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/components/tado/test_config_flow.py b/tests/components/tado/test_config_flow.py index 487742e2490c94..0c75eadfb0eb03 100644 --- a/tests/components/tado/test_config_flow.py +++ b/tests/components/tado/test_config_flow.py @@ -162,7 +162,7 @@ async def test_form_homekit(hass): for flow in hass.config_entries.flow.async_progress() if flow["flow_id"] == result["flow_id"] ) - assert flows_in_progress[0]["context"]["unique_id"] == "AA:BB:CC:DD:EE:FF" + assert flow["context"]["unique_id"] == "AA:BB:CC:DD:EE:FF" entry = MockConfigEntry( domain=DOMAIN, data={CONF_USERNAME: "mock", CONF_PASSWORD: "mock"}