Refactor platform loading in homekit_controller (#65338)

This commit is contained in:
Jc2k 2022-02-01 07:38:42 +00:00 committed by GitHub
parent b05b4c4b38
commit 2a193e1016
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -11,7 +11,6 @@ from aiohomekit.exceptions import (
from aiohomekit.model import Accessories, Accessory from aiohomekit.model import Accessories, Accessory
from aiohomekit.model.characteristics import CharacteristicsTypes from aiohomekit.model.characteristics import CharacteristicsTypes
from aiohomekit.model.services import ServicesTypes from aiohomekit.model.services import ServicesTypes
from aiohomekit.uuid import normalize_uuid
from homeassistant.const import ATTR_VIA_DEVICE from homeassistant.const import ATTR_VIA_DEVICE
from homeassistant.core import callback from homeassistant.core import callback
@ -493,21 +492,16 @@ class HKDevice:
async def async_load_platforms(self): async def async_load_platforms(self):
"""Load any platforms needed by this HomeKit device.""" """Load any platforms needed by this HomeKit device."""
tasks = [] tasks = []
for accessory in self.accessories: for accessory in self.entity_map.accessories:
for service in accessory["services"]: for service in accessory.services:
try: if service.type in HOMEKIT_ACCESSORY_DISPATCH:
stype = normalize_uuid(service["type"]) platform = HOMEKIT_ACCESSORY_DISPATCH[service.type]
except KeyError:
stype = service["type"].upper()
if stype in HOMEKIT_ACCESSORY_DISPATCH:
platform = HOMEKIT_ACCESSORY_DISPATCH[stype]
if platform not in self.platforms: if platform not in self.platforms:
tasks.append(self.async_load_platform(platform)) tasks.append(self.async_load_platform(platform))
for char in service["characteristics"]: for char in service.characteristics:
if char["type"].upper() in CHARACTERISTIC_PLATFORMS: if char.type in CHARACTERISTIC_PLATFORMS:
platform = CHARACTERISTIC_PLATFORMS[char["type"].upper()] platform = CHARACTERISTIC_PLATFORMS[char.type]
if platform not in self.platforms: if platform not in self.platforms:
tasks.append(self.async_load_platform(platform)) tasks.append(self.async_load_platform(platform))