def has(self, char_type) -> bool: try: char_type = CharacteristicsTypes.get_uuid(char_type) except KeyError: pass return char_type in self.characteristics_by_type
key=CharacteristicsTypes.DENSITY_VOC, name="Volatile Organic Compound Density", device_class=SensorDeviceClass.VOLATILE_ORGANIC_COMPOUNDS, state_class=SensorStateClass.MEASUREMENT, native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER, ), } # For legacy reasons, "built-in" characteristic types are in their short form # And vendor types don't have a short form # This means long and short forms get mixed up in this dict, and comparisons # don't work! # We call get_uuid on *every* type to normalise them to the long form # Eventually aiohomekit will use the long form exclusively amd this can be removed. for k, v in list(SIMPLE_SENSOR.items()): SIMPLE_SENSOR[CharacteristicsTypes.get_uuid(k)] = SIMPLE_SENSOR.pop(k) class HomeKitHumiditySensor(HomeKitEntity, SensorEntity): """Representation of a Homekit humidity sensor.""" _attr_device_class = SensorDeviceClass.HUMIDITY _attr_native_unit_of_measurement = PERCENTAGE def get_characteristic_types(self): """Define the homekit characteristics the entity is tracking.""" return [CharacteristicsTypes.RELATIVE_HUMIDITY_CURRENT] @property def name(self): """Return the name of the device."""
def __getitem__(self, key): try: key = CharacteristicsTypes.get_uuid(key) except KeyError: pass return self.characteristics_by_type[key]