Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions homeassistant/components/homekit_controller/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,25 +101,27 @@ def setup(self):

return True

async def async_refresh_entity_map(self, config_num):
def refresh_entity_map(self, config_num):
"""
Handle setup of a HomeKit accessory.

The sync version will be removed when homekit_controller migrates to
config flow.
"""
return await self.hass.async_add_executor_job(
self.refresh_entity_map,
self.hass.add_job(
self.async_refresh_entity_map,
config_num,
)

def refresh_entity_map(self, config_num):
async def async_refresh_entity_map(self, config_num):
"""Handle setup of a HomeKit accessory."""
# pylint: disable=import-error
from homekit.exceptions import AccessoryDisconnectedError

try:
accessories = self.pairing.list_accessories_and_characteristics()
self.accessories = await self.hass.async_add_executor_job(
self.pairing.list_accessories_and_characteristics,
)
except AccessoryDisconnectedError:
# If we fail to refresh this data then we will naturally retry
# later when Bonjour spots c# is still not up to date.
Expand All @@ -128,18 +130,17 @@ def refresh_entity_map(self, config_num):
self.hass.data[ENTITY_MAP].async_create_or_update_map(
self.unique_id,
config_num,
accessories,
self.accessories,
)

self.accessories = accessories
self.config_num = config_num

# For BLE, the Pairing instance relies on the entity map to map
# aid/iid to GATT characteristics. So push it to there as well.
self.pairing.pairing_data['accessories'] = accessories
self.pairing.pairing_data['accessories'] = self.accessories

# Register add new entities that are available
self.add_entities()
await self.hass.async_add_executor_job(self.add_entities)

return True

Expand Down