From 8ec30aa9ad506b75125e85767dc02099f6f953f3 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Sun, 21 Nov 2021 14:55:54 +0100 Subject: [PATCH] Use ZeroconfServiceInfo in rachio (#60054) --- homeassistant/components/rachio/config_flow.py | 13 ++++++++----- tests/components/rachio/test_config_flow.py | 9 +++++++-- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/homeassistant/components/rachio/config_flow.py b/homeassistant/components/rachio/config_flow.py index aa4efd971a6..73712135785 100644 --- a/homeassistant/components/rachio/config_flow.py +++ b/homeassistant/components/rachio/config_flow.py @@ -7,8 +7,10 @@ from requests.exceptions import ConnectTimeout import voluptuous as vol from homeassistant import config_entries, core, exceptions +from homeassistant.components import zeroconf from homeassistant.const import CONF_API_KEY from homeassistant.core import callback +from homeassistant.data_entry_flow import FlowResult from .const import ( CONF_MANUAL_RUN_MINS, @@ -78,13 +80,14 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): step_id="user", data_schema=DATA_SCHEMA, errors=errors ) - async def async_step_homekit(self, discovery_info): + async def async_step_homekit( + self, discovery_info: zeroconf.ZeroconfServiceInfo + ) -> FlowResult: """Handle HomeKit discovery.""" self._async_abort_entries_match() - properties = { - key.lower(): value for (key, value) in discovery_info["properties"].items() - } - await self.async_set_unique_id(properties["id"]) + await self.async_set_unique_id( + discovery_info[zeroconf.ATTR_PROPERTIES][zeroconf.ATTR_PROPERTIES_ID] + ) return await self.async_step_user() @staticmethod diff --git a/tests/components/rachio/test_config_flow.py b/tests/components/rachio/test_config_flow.py index 182f5e45dd7..8afcaca1886 100644 --- a/tests/components/rachio/test_config_flow.py +++ b/tests/components/rachio/test_config_flow.py @@ -2,6 +2,7 @@ from unittest.mock import MagicMock, patch from homeassistant import config_entries +from homeassistant.components import zeroconf from homeassistant.components.rachio.const import ( CONF_CUSTOM_URL, CONF_MANUAL_RUN_MINS, @@ -111,7 +112,9 @@ async def test_form_homekit(hass): result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_HOMEKIT}, - data={"properties": {"id": "AA:BB:CC:DD:EE:FF"}}, + data=zeroconf.ZeroconfServiceInfo( + properties={zeroconf.ATTR_PROPERTIES_ID: "AA:BB:CC:DD:EE:FF"} + ), ) assert result["type"] == "form" assert result["errors"] == {} @@ -128,7 +131,9 @@ async def test_form_homekit(hass): result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_HOMEKIT}, - data={"properties": {"id": "AA:BB:CC:DD:EE:FF"}}, + data=zeroconf.ZeroconfServiceInfo( + properties={zeroconf.ATTR_PROPERTIES_ID: "AA:BB:CC:DD:EE:FF"} + ), ) assert result["type"] == "abort" assert result["reason"] == "already_configured"