From 16e0953f267f6b24cbbfebee282a48cb542f7bb4 Mon Sep 17 00:00:00 2001 From: Jc2k Date: Tue, 2 Apr 2019 08:57:58 +0100 Subject: [PATCH] Fix racy homekit_controller platform setup caused by #22368 (#22655) --- homeassistant/components/homekit_controller/__init__.py | 3 +-- homeassistant/components/homekit_controller/connection.py | 5 ++++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/homekit_controller/__init__.py b/homeassistant/components/homekit_controller/__init__.py index 44af8bffe26..2a43d0ac9ce 100644 --- a/homeassistant/components/homekit_controller/__init__.py +++ b/homeassistant/components/homekit_controller/__init__.py @@ -191,8 +191,7 @@ def setup(hass, config): return _LOGGER.debug('Discovered unique device %s', hkid) - device = HKDevice(hass, host, port, model, hkid, config_num, config) - hass.data[KNOWN_DEVICES][hkid] = device + HKDevice(hass, host, port, model, hkid, config_num, config) hass.data[KNOWN_DEVICES] = {} discovery.listen(hass, SERVICE_HOMEKIT, discovery_dispatch) diff --git a/homeassistant/components/homekit_controller/connection.py b/homeassistant/components/homekit_controller/connection.py index d875b91eb2c..2ca568b547f 100644 --- a/homeassistant/components/homekit_controller/connection.py +++ b/homeassistant/components/homekit_controller/connection.py @@ -7,7 +7,8 @@ from homeassistant.helpers import discovery from homeassistant.helpers.event import call_later from .const import ( - CONTROLLER, DOMAIN, HOMEKIT_ACCESSORY_DISPATCH, PAIRING_FILE, HOMEKIT_DIR + CONTROLLER, DOMAIN, HOMEKIT_ACCESSORY_DISPATCH, KNOWN_DEVICES, + PAIRING_FILE, HOMEKIT_DIR ) @@ -76,6 +77,8 @@ class HKDevice(): self.pairing = self.controller.pairings.get(hkid) + hass.data[KNOWN_DEVICES][hkid] = self + if self.pairing is not None: self.accessory_setup() else: