matter-kit 0.3.0

Matter (CSA smart-home standard) protocol implementation in Rust: no_std, no-alloc, executor-agnostic
Documentation
// Generated by `cargo xtask` from the CSA data model 1.6. Do not edit.
//
// Switch — cluster 0x003B.
//
// Regenerate with `cargo xtask clusters --dm <checkout>/data_model/1.6`; `cargo xtask check`
// is the CI gate that keeps this file honest. The XML itself is not vendored here — it
// carries the CSA's own copyright notice and is not redistributable.

//! Switch (cluster `0x003B`, revision 2).
//!
//! 10 identifiers, 6 feature bits, and the specification's own conformance for
//! every element. `CLUSTER` is the whole table.

#![allow(unused_imports)]

use crate::dm::conformance::{Clause, Condition, Conform, Conformance};
use crate::dm::meta::{EventPriority, Reporting};
use crate::dm::spec::{Attribute, Cluster, Command, Event, Feature};
use crate::dm::{Access, AccessQualities, AttributeQualities, Privilege};
use crate::error::Result;
use crate::im::{AttributeId, ClusterId, CommandId, EventId};
use crate::tlv::{
    ContainerKind, Element, FromTlv, Nullable, Tag, TlvList, TlvReader, TlvWriter, ToTlv, Value,
};

/// The cluster id.
pub const ID: ClusterId = 0x003B;

/// The highest revision the specification's history defines — what `ClusterRevision`
/// must report (Core §7.13.1).
pub const REVISION: u16 = 2;

/// The PICS code, which a certification declaration names the cluster by.
pub const PICS: &str = "SWTCH";

/// The `FeatureMap` bits (Core §7.13.2).
///
/// A feature has conformance of its own: a device may not claim one the
/// specification forbids it alongside another.
pub mod feature {
    /// Switch is latching
    ///
    /// Code `LS`, bit 0.
    pub const LATCHING_SWITCH: u32 = 1 << 0;
    /// Switch is momentary
    ///
    /// Code `MS`, bit 1.
    pub const MOMENTARY_SWITCH: u32 = 1 << 1;
    /// Switch supports release events generation
    ///
    /// Code `MSR`, bit 2.
    pub const MOMENTARY_SWITCH_RELEASE: u32 = 1 << 2;
    /// Switch supports long press detection
    ///
    /// Code `MSL`, bit 3.
    pub const MOMENTARY_SWITCH_LONG_PRESS: u32 = 1 << 3;
    /// Switch supports multi-press detection
    ///
    /// Code `MSM`, bit 4.
    pub const MOMENTARY_SWITCH_MULTI_PRESS: u32 = 1 << 4;
    /// Switch is momentary, targeted at specific user actions (focus on multi-press and optionally long press) with a reduced event generation scheme
    ///
    /// Code `AS`, bit 5.
    pub const ACTION_SWITCH: u32 = 1 << 5;
}

/// Every feature bit, with its conformance.
pub const FEATURES: &[Feature] = &[
    Feature {
        bit: 0,
        code: "LS",
        name: "LatchingSwitch",
        conform: Conform::OPTIONAL,
    },
    Feature {
        bit: 1,
        code: "MS",
        name: "MomentarySwitch",
        conform: Conform::OPTIONAL,
    },
    Feature {
        bit: 2,
        code: "MSR",
        name: "MomentarySwitchRelease",
        conform: Conform {
            clauses: &[Clause {
                verdict: Conformance::Optional,
                when: Condition::All(&[
                    Condition::Feature(1),
                    Condition::Not(&Condition::Feature(5)),
                ]),
            }],
        },
    },
    Feature {
        bit: 3,
        code: "MSL",
        name: "MomentarySwitchLongPress",
        conform: Conform {
            clauses: &[Clause {
                verdict: Conformance::Optional,
                when: Condition::All(&[
                    Condition::Feature(1),
                    Condition::Any(&[Condition::Feature(2), Condition::Feature(5)]),
                ]),
            }],
        },
    },
    Feature {
        bit: 4,
        code: "MSM",
        name: "MomentarySwitchMultiPress",
        conform: Conform {
            clauses: &[
                Clause {
                    verdict: Conformance::Mandatory,
                    when: Condition::Feature(5),
                },
                Clause {
                    verdict: Conformance::Optional,
                    when: Condition::All(&[Condition::Feature(1), Condition::Feature(2)]),
                },
            ],
        },
    },
    Feature {
        bit: 5,
        code: "AS",
        name: "ActionSwitch",
        conform: Conform {
            clauses: &[Clause {
                verdict: Conformance::Optional,
                when: Condition::Feature(1),
            }],
        },
    },
];

/// The attribute ids.
pub mod attribute {
    use crate::im::AttributeId;

    /// `NumberOfPositions`.
    pub const NUMBER_OF_POSITIONS: AttributeId = 0x00;
    /// `CurrentPosition`.
    pub const CURRENT_POSITION: AttributeId = 0x01;
    /// `MultiPressMax`.
    pub const MULTI_PRESS_MAX: AttributeId = 0x02;
}

/// The event ids.
pub mod event {
    use crate::im::EventId;

    /// `SwitchLatched`.
    pub const SWITCH_LATCHED: EventId = 0x00;
    /// `InitialPress`.
    pub const INITIAL_PRESS: EventId = 0x01;
    /// `LongPress`.
    pub const LONG_PRESS: EventId = 0x02;
    /// `ShortRelease`.
    pub const SHORT_RELEASE: EventId = 0x03;
    /// `LongRelease`.
    pub const LONG_RELEASE: EventId = 0x04;
    /// `MultiPressOngoing`.
    pub const MULTI_PRESS_ONGOING: EventId = 0x05;
    /// `MultiPressComplete`.
    pub const MULTI_PRESS_COMPLETE: EventId = 0x06;
}

/// Every attribute the specification defines, with its conformance.
pub const ATTRIBUTES: &[Attribute] = &[
    Attribute {
        id: 0x0000,
        name: "NumberOfPositions",
        kind: "uint8",
        access: Access::read_only(Privilege::View),
        qualities: AttributeQualities::FIXED,
        reporting: Reporting::OnChange,
        conform: Conform::MANDATORY,
    },
    Attribute {
        id: 0x0001,
        name: "CurrentPosition",
        kind: "uint8",
        access: Access::read_only(Privilege::View),
        qualities: AttributeQualities::NON_VOLATILE,
        reporting: Reporting::OnChange,
        conform: Conform::MANDATORY,
    },
    Attribute {
        id: 0x0002,
        name: "MultiPressMax",
        kind: "uint8",
        access: Access::read_only(Privilege::View),
        qualities: AttributeQualities::FIXED,
        reporting: Reporting::OnChange,
        conform: Conform {
            clauses: &[Clause {
                verdict: Conformance::Mandatory,
                when: Condition::Feature(4),
            }],
        },
    },
];

/// Every command, with its conformance.
pub const COMMANDS: &[Command] = &[];

/// Every event, with its conformance.
pub const EVENTS: &[Event] = &[
    Event {
        id: 0x00,
        name: "SwitchLatched",
        priority: EventPriority::Info,
        access: Access::read_only(Privilege::View),
        conform: Conform {
            clauses: &[Clause {
                verdict: Conformance::Mandatory,
                when: Condition::Feature(0),
            }],
        },
    },
    Event {
        id: 0x01,
        name: "InitialPress",
        priority: EventPriority::Info,
        access: Access::read_only(Privilege::View),
        conform: Conform {
            clauses: &[Clause {
                verdict: Conformance::Mandatory,
                when: Condition::Feature(1),
            }],
        },
    },
    Event {
        id: 0x02,
        name: "LongPress",
        priority: EventPriority::Info,
        access: Access::read_only(Privilege::View),
        conform: Conform {
            clauses: &[Clause {
                verdict: Conformance::Mandatory,
                when: Condition::Feature(3),
            }],
        },
    },
    Event {
        id: 0x03,
        name: "ShortRelease",
        priority: EventPriority::Info,
        access: Access::read_only(Privilege::View),
        conform: Conform {
            clauses: &[Clause {
                verdict: Conformance::Mandatory,
                when: Condition::Feature(2),
            }],
        },
    },
    Event {
        id: 0x04,
        name: "LongRelease",
        priority: EventPriority::Info,
        access: Access::read_only(Privilege::View),
        conform: Conform {
            clauses: &[Clause {
                verdict: Conformance::Mandatory,
                when: Condition::Feature(3),
            }],
        },
    },
    Event {
        id: 0x05,
        name: "MultiPressOngoing",
        priority: EventPriority::Info,
        access: Access::read_only(Privilege::View),
        conform: Conform {
            clauses: &[Clause {
                verdict: Conformance::Mandatory,
                when: Condition::All(&[
                    Condition::Feature(4),
                    Condition::Not(&Condition::Feature(5)),
                ]),
            }],
        },
    },
    Event {
        id: 0x06,
        name: "MultiPressComplete",
        priority: EventPriority::Info,
        access: Access::read_only(Privilege::View),
        conform: Conform {
            clauses: &[Clause {
                verdict: Conformance::Mandatory,
                when: Condition::Feature(4),
            }],
        },
    },
];

/// The whole cluster, as the specification defines it.
pub const CLUSTER: Cluster = Cluster {
    id: ID,
    name: "Switch",
    revision: REVISION,
    pics: "SWTCH",
    derived_from: None,
    features: FEATURES,
    attributes: ATTRIBUTES,
    commands: COMMANDS,
    events: EVENTS,
};