def value(self, char_type, default_value=None) -> Any: char_type = normalize_uuid(char_type) if char_type not in self.characteristics_by_type: return default_value return self.characteristics_by_type[char_type].value
async def identify(self): """ This call can be used to trigger the identification of a paired accessory. A successful call should cause the accessory to perform some specific action by which it can be distinguished from the others (blink a LED for example). It uses the identify characteristic as described on page 152 of the spec. :return True, if the identification was run, False otherwise """ await self._ensure_connected() if "accessories" not in self.pairing_data: await self.list_accessories_and_characteristics() # we are looking for a characteristic of the identify type identify_type = CharacteristicsTypes.IDENTIFY # search all accessories, all services and all characteristics for accessory in self.pairing_data["accessories"]: aid = accessory["aid"] for service in accessory["services"]: for characteristic in service["characteristics"]: iid = characteristic["iid"] c_type = normalize_uuid(characteristic["type"]) if identify_type == c_type: # found the identify characteristic, so let's put a value there if not await self.put_characteristics([(aid, iid, True)]): return True return False
def filter(self, char_types=None) -> Iterable[Characteristic]: matches = iter(self) if char_types: char_types = [normalize_uuid(c) for c in char_types] matches = filter(lambda char: char.type in char_types, matches) return matches
async def list_accessories_and_characteristics(self): """ This retrieves a current set of accessories and characteristics behind this pairing. :return: the accessory data as described in the spec on page 73 and following :raises AccessoryNotFoundError: if the device can not be found via zeroconf """ await self._ensure_connected() response = await self.connection.get_json("/accessories") accessories = response["accessories"] for accessory in accessories: for service in accessory["services"]: service["type"] = normalize_uuid(service["type"]) for characteristic in service["characteristics"]: characteristic["type"] = normalize_uuid(characteristic["type"]) self.pairing_data["accessories"] = accessories return accessories
def __init__( self, accessory: Accessory, service_type: str, name: str | None = None, add_required: bool = False, ): self.type = normalize_uuid(service_type) self.accessory = accessory self.iid = accessory.get_next_id() self.characteristics = Characteristics() self.characteristics_by_type = {} self.linked = [] if name: char = self.add_char(CharacteristicsTypes.NAME) char.set_value(name) if add_required: for required in services[self.type]["required"]: if required not in self.characteristics_by_type: self.add_char(required)
fp.write(f" \"min_value\": {min_value},\n") if "step_value" in char: step_value = json.dumps(char["step_value"]) fp.write(f" \"min_step\": {step_value},\n") fp.write(" },\n") pass fp.write("}\n") from aiohomekit.model.services import ServicesTypes for serv in data.get('Services', []): name = serv['Name'].replace(" ", "_").upper() short = normalize_uuid(serv['UUID']) print(f'{name} = "{short}"') services = {} for serv in data.get('Services', []): name = serv['Name'].replace(" ", "_").upper() s = services[serv['UUID']] = { 'name': name, 'description': serv['Name'], 'required': serv.get("RequiredCharacteristics", []), 'optional': serv.get("OptionalCharacteristics", []), }
def has(self, char_type) -> bool: char_type = normalize_uuid(char_type) return char_type in self.characteristics_by_type
def __getitem__(self, key) -> Characteristic: key = normalize_uuid(key) return self.characteristics_by_type[key]
def test_normalize_invalid_uuid(): with pytest.raises(Exception): normalize_uuid("NOT_A_VALID_UUID")
def test_normalize_uuid(): assert ( normalize_uuid("00000121-0000-1000-8000-0026BB765291") == "00000121-0000-1000-8000-0026BB765291" )
def test_normalize_short_uuid(): assert normalize_uuid("121") == "00000121-0000-1000-8000-0026BB765291"