hap-model 1.0.0

HomeKit Accessory Protocol attribute database: accessory/service/characteristic model and HAP-defined types.
Documentation
// @generated by `cargo xtask codegen-hap-types` from xtask/model/hap-types.json.
// Do not edit by hand. Re-run the codegen command to regenerate.

#![allow(clippy::match_same_arms)]

#[allow(unused_imports)]
use crate::format::CharFormat;
use crate::uuid::Uuid;

/// HAP-defined ServiceType (generated). `Unknown` carries any non-HAP UUID.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum ServiceType {
    /// HAP short type "3E".
    AccessoryInformation,
    /// HAP short type "A2".
    ProtocolInformation,
    /// HAP short type "43".
    LightBulb,
    /// HAP short type "49".
    Switch,
    /// HAP short type "47".
    Outlet,
    /// HAP short type "40".
    Fan,
    /// HAP short type "4A".
    Thermostat,
    /// HAP short type "8A".
    TemperatureSensor,
    /// HAP short type "82".
    HumiditySensor,
    /// HAP short type "85".
    MotionSensor,
    /// HAP short type "80".
    ContactSensor,
    /// HAP short type "41".
    GarageDoorOpener,
    /// HAP short type "45".
    LockMechanism,
    /// HAP short type "96".
    Battery,
    /// A type not in the generated table.
    Unknown(Uuid),
}

impl ServiceType {
    /// Map a parsed [`Uuid`] to its named variant, or `Unknown`.
    pub fn from_uuid(u: &Uuid) -> Self {
        match u.as_full() {
            "0000003e-0000-1000-8000-0026bb765291" => Self::AccessoryInformation,
            "000000a2-0000-1000-8000-0026bb765291" => Self::ProtocolInformation,
            "00000043-0000-1000-8000-0026bb765291" => Self::LightBulb,
            "00000049-0000-1000-8000-0026bb765291" => Self::Switch,
            "00000047-0000-1000-8000-0026bb765291" => Self::Outlet,
            "00000040-0000-1000-8000-0026bb765291" => Self::Fan,
            "0000004a-0000-1000-8000-0026bb765291" => Self::Thermostat,
            "0000008a-0000-1000-8000-0026bb765291" => Self::TemperatureSensor,
            "00000082-0000-1000-8000-0026bb765291" => Self::HumiditySensor,
            "00000085-0000-1000-8000-0026bb765291" => Self::MotionSensor,
            "00000080-0000-1000-8000-0026bb765291" => Self::ContactSensor,
            "00000041-0000-1000-8000-0026bb765291" => Self::GarageDoorOpener,
            "00000045-0000-1000-8000-0026bb765291" => Self::LockMechanism,
            "00000096-0000-1000-8000-0026bb765291" => Self::Battery,
            _ => Self::Unknown(u.clone()),
        }
    }

    /// The canonical [`Uuid`] for this type.
    pub fn uuid(&self) -> Uuid {
        match self {
            Self::AccessoryInformation => {
                Uuid::from_full_unchecked("0000003e-0000-1000-8000-0026bb765291".to_string())
            }
            Self::ProtocolInformation => {
                Uuid::from_full_unchecked("000000a2-0000-1000-8000-0026bb765291".to_string())
            }
            Self::LightBulb => {
                Uuid::from_full_unchecked("00000043-0000-1000-8000-0026bb765291".to_string())
            }
            Self::Switch => {
                Uuid::from_full_unchecked("00000049-0000-1000-8000-0026bb765291".to_string())
            }
            Self::Outlet => {
                Uuid::from_full_unchecked("00000047-0000-1000-8000-0026bb765291".to_string())
            }
            Self::Fan => {
                Uuid::from_full_unchecked("00000040-0000-1000-8000-0026bb765291".to_string())
            }
            Self::Thermostat => {
                Uuid::from_full_unchecked("0000004a-0000-1000-8000-0026bb765291".to_string())
            }
            Self::TemperatureSensor => {
                Uuid::from_full_unchecked("0000008a-0000-1000-8000-0026bb765291".to_string())
            }
            Self::HumiditySensor => {
                Uuid::from_full_unchecked("00000082-0000-1000-8000-0026bb765291".to_string())
            }
            Self::MotionSensor => {
                Uuid::from_full_unchecked("00000085-0000-1000-8000-0026bb765291".to_string())
            }
            Self::ContactSensor => {
                Uuid::from_full_unchecked("00000080-0000-1000-8000-0026bb765291".to_string())
            }
            Self::GarageDoorOpener => {
                Uuid::from_full_unchecked("00000041-0000-1000-8000-0026bb765291".to_string())
            }
            Self::LockMechanism => {
                Uuid::from_full_unchecked("00000045-0000-1000-8000-0026bb765291".to_string())
            }
            Self::Battery => {
                Uuid::from_full_unchecked("00000096-0000-1000-8000-0026bb765291".to_string())
            }
            Self::Unknown(u) => u.clone(),
        }
    }
}

/// HAP-defined CharacteristicType (generated). `Unknown` carries any non-HAP UUID.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum CharacteristicType {
    /// HAP short type "14".
    Identify,
    /// HAP short type "20".
    Manufacturer,
    /// HAP short type "21".
    Model,
    /// HAP short type "23".
    Name,
    /// HAP short type "30".
    SerialNumber,
    /// HAP short type "52".
    FirmwareRevision,
    /// HAP short type "25".
    On,
    /// HAP short type "8".
    Brightness,
    /// HAP short type "13".
    Hue,
    /// HAP short type "2F".
    Saturation,
    /// HAP short type "CE".
    ColorTemperature,
    /// HAP short type "11".
    CurrentTemperature,
    /// HAP short type "35".
    TargetTemperature,
    /// HAP short type "10".
    CurrentRelativeHumidity,
    /// HAP short type "22".
    MotionDetected,
    /// HAP short type "6A".
    ContactSensorState,
    /// HAP short type "1D".
    LockCurrentState,
    /// HAP short type "1E".
    LockTargetState,
    /// HAP short type "68".
    BatteryLevel,
    /// HAP short type "79".
    StatusLowBattery,
    /// HAP short type "26".
    OutletInUse,
    /// A type not in the generated table.
    Unknown(Uuid),
}

impl CharacteristicType {
    /// Map a parsed [`Uuid`] to its named variant, or `Unknown`.
    pub fn from_uuid(u: &Uuid) -> Self {
        match u.as_full() {
            "00000014-0000-1000-8000-0026bb765291" => Self::Identify,
            "00000020-0000-1000-8000-0026bb765291" => Self::Manufacturer,
            "00000021-0000-1000-8000-0026bb765291" => Self::Model,
            "00000023-0000-1000-8000-0026bb765291" => Self::Name,
            "00000030-0000-1000-8000-0026bb765291" => Self::SerialNumber,
            "00000052-0000-1000-8000-0026bb765291" => Self::FirmwareRevision,
            "00000025-0000-1000-8000-0026bb765291" => Self::On,
            "00000008-0000-1000-8000-0026bb765291" => Self::Brightness,
            "00000013-0000-1000-8000-0026bb765291" => Self::Hue,
            "0000002f-0000-1000-8000-0026bb765291" => Self::Saturation,
            "000000ce-0000-1000-8000-0026bb765291" => Self::ColorTemperature,
            "00000011-0000-1000-8000-0026bb765291" => Self::CurrentTemperature,
            "00000035-0000-1000-8000-0026bb765291" => Self::TargetTemperature,
            "00000010-0000-1000-8000-0026bb765291" => Self::CurrentRelativeHumidity,
            "00000022-0000-1000-8000-0026bb765291" => Self::MotionDetected,
            "0000006a-0000-1000-8000-0026bb765291" => Self::ContactSensorState,
            "0000001d-0000-1000-8000-0026bb765291" => Self::LockCurrentState,
            "0000001e-0000-1000-8000-0026bb765291" => Self::LockTargetState,
            "00000068-0000-1000-8000-0026bb765291" => Self::BatteryLevel,
            "00000079-0000-1000-8000-0026bb765291" => Self::StatusLowBattery,
            "00000026-0000-1000-8000-0026bb765291" => Self::OutletInUse,
            _ => Self::Unknown(u.clone()),
        }
    }

    /// The canonical [`Uuid`] for this type.
    pub fn uuid(&self) -> Uuid {
        match self {
            Self::Identify => {
                Uuid::from_full_unchecked("00000014-0000-1000-8000-0026bb765291".to_string())
            }
            Self::Manufacturer => {
                Uuid::from_full_unchecked("00000020-0000-1000-8000-0026bb765291".to_string())
            }
            Self::Model => {
                Uuid::from_full_unchecked("00000021-0000-1000-8000-0026bb765291".to_string())
            }
            Self::Name => {
                Uuid::from_full_unchecked("00000023-0000-1000-8000-0026bb765291".to_string())
            }
            Self::SerialNumber => {
                Uuid::from_full_unchecked("00000030-0000-1000-8000-0026bb765291".to_string())
            }
            Self::FirmwareRevision => {
                Uuid::from_full_unchecked("00000052-0000-1000-8000-0026bb765291".to_string())
            }
            Self::On => {
                Uuid::from_full_unchecked("00000025-0000-1000-8000-0026bb765291".to_string())
            }
            Self::Brightness => {
                Uuid::from_full_unchecked("00000008-0000-1000-8000-0026bb765291".to_string())
            }
            Self::Hue => {
                Uuid::from_full_unchecked("00000013-0000-1000-8000-0026bb765291".to_string())
            }
            Self::Saturation => {
                Uuid::from_full_unchecked("0000002f-0000-1000-8000-0026bb765291".to_string())
            }
            Self::ColorTemperature => {
                Uuid::from_full_unchecked("000000ce-0000-1000-8000-0026bb765291".to_string())
            }
            Self::CurrentTemperature => {
                Uuid::from_full_unchecked("00000011-0000-1000-8000-0026bb765291".to_string())
            }
            Self::TargetTemperature => {
                Uuid::from_full_unchecked("00000035-0000-1000-8000-0026bb765291".to_string())
            }
            Self::CurrentRelativeHumidity => {
                Uuid::from_full_unchecked("00000010-0000-1000-8000-0026bb765291".to_string())
            }
            Self::MotionDetected => {
                Uuid::from_full_unchecked("00000022-0000-1000-8000-0026bb765291".to_string())
            }
            Self::ContactSensorState => {
                Uuid::from_full_unchecked("0000006a-0000-1000-8000-0026bb765291".to_string())
            }
            Self::LockCurrentState => {
                Uuid::from_full_unchecked("0000001d-0000-1000-8000-0026bb765291".to_string())
            }
            Self::LockTargetState => {
                Uuid::from_full_unchecked("0000001e-0000-1000-8000-0026bb765291".to_string())
            }
            Self::BatteryLevel => {
                Uuid::from_full_unchecked("00000068-0000-1000-8000-0026bb765291".to_string())
            }
            Self::StatusLowBattery => {
                Uuid::from_full_unchecked("00000079-0000-1000-8000-0026bb765291".to_string())
            }
            Self::OutletInUse => {
                Uuid::from_full_unchecked("00000026-0000-1000-8000-0026bb765291".to_string())
            }
            Self::Unknown(u) => u.clone(),
        }
    }

    /// The HAP default value format for this characteristic, if known.
    pub fn default_format(&self) -> Option<CharFormat> {
        match self {
            Self::Identify => Some(CharFormat::Bool),
            Self::Manufacturer => Some(CharFormat::String),
            Self::Model => Some(CharFormat::String),
            Self::Name => Some(CharFormat::String),
            Self::SerialNumber => Some(CharFormat::String),
            Self::FirmwareRevision => Some(CharFormat::String),
            Self::On => Some(CharFormat::Bool),
            Self::Brightness => Some(CharFormat::Int),
            Self::Hue => Some(CharFormat::Float),
            Self::Saturation => Some(CharFormat::Float),
            Self::ColorTemperature => Some(CharFormat::Uint32),
            Self::CurrentTemperature => Some(CharFormat::Float),
            Self::TargetTemperature => Some(CharFormat::Float),
            Self::CurrentRelativeHumidity => Some(CharFormat::Float),
            Self::MotionDetected => Some(CharFormat::Bool),
            Self::ContactSensorState => Some(CharFormat::Uint8),
            Self::LockCurrentState => Some(CharFormat::Uint8),
            Self::LockTargetState => Some(CharFormat::Uint8),
            Self::BatteryLevel => Some(CharFormat::Uint8),
            Self::StatusLowBattery => Some(CharFormat::Uint8),
            Self::OutletInUse => Some(CharFormat::Bool),
            _ => None,
        }
    }
}