Refactor platform loading in homekit_controller (#65338)

pull/65360/head
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
1 changed files with 7 additions and 13 deletions

View File

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