async def async_load_platforms(self): """Load any platforms needed by this HomeKit device.""" for accessory in self.accessories: for service in accessory["services"]: stype = ServicesTypes.get_short(service["type"].upper()) if stype not in HOMEKIT_ACCESSORY_DISPATCH: continue platform = HOMEKIT_ACCESSORY_DISPATCH[stype] if platform in self.platforms: continue self.platforms.add(platform) try: await self.hass.config_entries.async_forward_entry_setup( self.config_entry, platform) except Exception: self.platforms.remove(platform) raise
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"]: stype = ServicesTypes.get_short(service["type"].upper()) if stype in HOMEKIT_ACCESSORY_DISPATCH: platform = HOMEKIT_ACCESSORY_DISPATCH[stype] 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()] if platform not in self.platforms: tasks.append(self.async_load_platform(platform)) if tasks: await asyncio.gather(*tasks)
async def setup_test_component(hass, setup_accessory, capitalize=False, suffix=None): """Load a fake homekit accessory based on a homekit accessory model. If capitalize is True, property names will be in upper case. If suffix is set, entityId will include the suffix """ accessory = Accessory.create_with_info( "TestDevice", "example.com", "Test", "0001", "0.1" ) setup_accessory(accessory) domain = None for service in accessory.services: service_name = ServicesTypes.get_short(service.type) if service_name in HOMEKIT_ACCESSORY_DISPATCH: domain = HOMEKIT_ACCESSORY_DISPATCH[service_name] break assert domain, "Cannot map test homekit services to Home Assistant domain" config_entry, pairing = await setup_test_accessories(hass, [accessory]) entity = "testdevice" if suffix is None else f"testdevice_{suffix}" return Helper(hass, ".".join((domain, entity)), pairing, accessory, config_entry)
def test_get_short_no_service(): assert ( ServicesTypes.get_short("00000023-0000-1000-8000-0026BB765291") == "Unknown Service: 00000023-0000-1000-8000-0026BB765291" )
def test_get_short_no_baseid(): assert ( ServicesTypes.get_short("00000023-0000-1000-8000-NOTBASEID") == "Unknown Service: 00000023-0000-1000-8000-NOTBASEID" )
def test_get_short_lowercase(): assert ( ServicesTypes.get_short("00000086-0000-1000-8000-0026bb765291") == "occupancy" )
def test_get_short(): assert ( ServicesTypes.get_short("00000086-0000-1000-8000-0026BB765291") == "occupancy" )