diff --git a/homeassistant/components/homekit_controller/config_flow.py b/homeassistant/components/homekit_controller/config_flow.py index 812d10eb8c4..4f704d7ea59 100644 --- a/homeassistant/components/homekit_controller/config_flow.py +++ b/homeassistant/components/homekit_controller/config_flow.py @@ -6,6 +6,7 @@ import aiohomekit import voluptuous as vol from homeassistant import config_entries +from homeassistant.components import zeroconf from homeassistant.core import callback from .connection import get_accessory_name, get_bridge_information @@ -59,9 +60,14 @@ class HomekitControllerFlowHandler(config_entries.ConfigFlow): self.model = None self.hkid = None self.devices = {} - self.controller = aiohomekit.Controller() + self.controller = None self.finish_pairing = None + async def _async_setup_controller(self): + """Create the controller.""" + zeroconf_instance = await zeroconf.async_get_instance(self.hass) + self.controller = aiohomekit.Controller(zeroconf_instance=zeroconf_instance) + async def async_step_user(self, user_input=None): """Handle a flow start.""" errors = {} @@ -75,6 +81,9 @@ class HomekitControllerFlowHandler(config_entries.ConfigFlow): ) return await self.async_step_pair() + if self.controller is None: + await self._async_setup_controller() + all_hosts = await self.controller.discover_ip() self.devices = {} @@ -101,7 +110,10 @@ class HomekitControllerFlowHandler(config_entries.ConfigFlow): unique_id = user_input["unique_id"] await self.async_set_unique_id(unique_id) - devices = await self.controller.discover_ip(5) + if self.controller is None: + await self._async_setup_controller() + + devices = await self.controller.discover_ip(max_seconds=5) for device in devices: if normalize_hkid(device.device_id) != unique_id: continue @@ -226,6 +238,8 @@ class HomekitControllerFlowHandler(config_entries.ConfigFlow): # in. errors = {} + if self.controller is None: + await self._async_setup_controller() if pair_info: code = pair_info["pairing_code"] diff --git a/homeassistant/components/homekit_controller/manifest.json b/homeassistant/components/homekit_controller/manifest.json index 4676abfb896..9bbaf959012 100644 --- a/homeassistant/components/homekit_controller/manifest.json +++ b/homeassistant/components/homekit_controller/manifest.json @@ -3,7 +3,8 @@ "name": "HomeKit Controller", "config_flow": true, "documentation": "https://www.home-assistant.io/integrations/homekit_controller", - "requirements": ["aiohomekit[IP]==0.2.41"], + "requirements": ["aiohomekit[IP]==0.2.45"], "zeroconf": ["_hap._tcp.local."], + "after_dependencies": ["zeroconf"], "codeowners": ["@Jc2k"] } diff --git a/requirements_all.txt b/requirements_all.txt index a324054327c..223a6ec05b9 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -185,7 +185,7 @@ aioguardian==1.0.1 aioharmony==0.2.5 # homeassistant.components.homekit_controller -aiohomekit[IP]==0.2.41 +aiohomekit[IP]==0.2.45 # homeassistant.components.emulated_hue # homeassistant.components.http diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 34a892fdf69..a3a3a7a1abe 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -91,7 +91,7 @@ aioguardian==1.0.1 aioharmony==0.2.5 # homeassistant.components.homekit_controller -aiohomekit[IP]==0.2.41 +aiohomekit[IP]==0.2.45 # homeassistant.components.emulated_hue # homeassistant.components.http