Use the shared zeroconf instance for homekit_controller (#37691)

* Use the shared zeroconf instance for homekit_controller

* bump version

* Update for upstream changes. Thank you @Jc2k !

* naming

* bump version

* empty commit to reset CI as re-run is not working
pull/37747/head
J. Nick Koston 2020-07-10 12:18:53 -10:00 committed by GitHub
parent e61da2fff3
commit 52939865fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 5 deletions

View File

@ -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"]

View File

@ -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"]
}

View File

@ -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

View File

@ -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