Skip to main content

matter_kit/clusters/generated/
actions.rs

1// Generated by `cargo xtask` from the CSA data model 1.6. Do not edit.
2//
3// Actions — cluster 0x0025.
4//
5// Regenerate with `cargo xtask clusters --dm <checkout>/data_model/1.6`; `cargo xtask check`
6// is the CI gate that keeps this file honest. The XML itself is not vendored here — it
7// carries the CSA's own copyright notice and is not redistributable.
8
9//! Actions (cluster `0x0025`, revision 1).
10//!
11//! 17 identifiers, 0 feature bits, and the specification's own conformance for
12//! every element. `CLUSTER` is the whole table.
13
14#![allow(unused_imports)]
15
16use crate::dm::conformance::{Clause, Condition, Conform, Conformance};
17use crate::dm::meta::{EventPriority, Reporting};
18use crate::dm::spec::{Attribute, Cluster, Command, Event, Feature};
19use crate::dm::{Access, AccessQualities, AttributeQualities, Privilege};
20use crate::error::Result;
21use crate::im::{AttributeId, ClusterId, CommandId, EventId};
22use crate::tlv::{
23    ContainerKind, Element, FromTlv, Nullable, Tag, TlvList, TlvReader, TlvWriter, ToTlv, Value,
24};
25
26/// The cluster id.
27pub const ID: ClusterId = 0x0025;
28
29/// The highest revision the specification's history defines — what `ClusterRevision`
30/// must report (Core §7.13.1).
31pub const REVISION: u16 = 1;
32
33/// The PICS code, which a certification declaration names the cluster by.
34pub const PICS: &str = "ACT";
35
36/// This cluster defines no features, so its `FeatureMap` is always zero.
37pub const FEATURES: &[Feature] = &[];
38
39/// The attribute ids.
40pub mod attribute {
41    use crate::im::AttributeId;
42
43    /// `ActionList`.
44    pub const ACTION_LIST: AttributeId = 0x00;
45    /// `EndpointLists`.
46    pub const ENDPOINT_LISTS: AttributeId = 0x01;
47    /// `SetupURL`.
48    pub const SETUP_URL: AttributeId = 0x02;
49}
50
51/// The command ids.
52pub mod command {
53    use crate::im::CommandId;
54
55    /// `InstantAction`.
56    pub const INSTANT_ACTION: CommandId = 0x00;
57    /// `InstantActionWithTransition`.
58    pub const INSTANT_ACTION_WITH_TRANSITION: CommandId = 0x01;
59    /// `StartAction`.
60    pub const START_ACTION: CommandId = 0x02;
61    /// `StartActionWithDuration`.
62    pub const START_ACTION_WITH_DURATION: CommandId = 0x03;
63    /// `StopAction`.
64    pub const STOP_ACTION: CommandId = 0x04;
65    /// `PauseAction`.
66    pub const PAUSE_ACTION: CommandId = 0x05;
67    /// `PauseActionWithDuration`.
68    pub const PAUSE_ACTION_WITH_DURATION: CommandId = 0x06;
69    /// `ResumeAction`.
70    pub const RESUME_ACTION: CommandId = 0x07;
71    /// `EnableAction`.
72    pub const ENABLE_ACTION: CommandId = 0x08;
73    /// `EnableActionWithDuration`.
74    pub const ENABLE_ACTION_WITH_DURATION: CommandId = 0x09;
75    /// `DisableAction`.
76    pub const DISABLE_ACTION: CommandId = 0x0A;
77    /// `DisableActionWithDuration`.
78    pub const DISABLE_ACTION_WITH_DURATION: CommandId = 0x0B;
79}
80
81/// The event ids.
82pub mod event {
83    use crate::im::EventId;
84
85    /// `StateChanged`.
86    pub const STATE_CHANGED: EventId = 0x00;
87    /// `ActionFailed`.
88    pub const ACTION_FAILED: EventId = 0x01;
89}
90
91/// `ActionErrorEnum`.
92#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
93#[repr(u8)]
94pub enum ActionErrorEnum {
95    /// Other reason not listed in the row(s) below
96    Unknown = 0,
97    /// The action was interrupted by another command or interaction
98    Interrupted = 1,
99}
100
101impl ActionErrorEnum {
102    /// Reads a wire value, or `None` for one this revision does not define.
103    #[must_use]
104    pub const fn from_value(value: u8) -> Option<Self> {
105        match value {
106            0 => Some(Self::Unknown),
107            1 => Some(Self::Interrupted),
108            _ => None,
109        }
110    }
111
112    /// Its wire value.
113    #[must_use]
114    pub const fn value(self) -> u8 {
115        self as u8
116    }
117}
118
119impl ToTlv for ActionErrorEnum {
120    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
121        self.value().to_tlv(w, tag)
122    }
123}
124
125impl<'a> FromTlv<'a> for ActionErrorEnum {
126    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
127        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
128        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
129    }
130}
131
132/// `ActionStateEnum`.
133#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
134#[repr(u8)]
135pub enum ActionStateEnum {
136    /// The action is not active
137    Inactive = 0,
138    /// The action is active
139    Active = 1,
140    /// The action has been paused
141    Paused = 2,
142    /// The action has been disabled
143    Disabled = 3,
144}
145
146impl ActionStateEnum {
147    /// Reads a wire value, or `None` for one this revision does not define.
148    #[must_use]
149    pub const fn from_value(value: u8) -> Option<Self> {
150        match value {
151            0 => Some(Self::Inactive),
152            1 => Some(Self::Active),
153            2 => Some(Self::Paused),
154            3 => Some(Self::Disabled),
155            _ => None,
156        }
157    }
158
159    /// Its wire value.
160    #[must_use]
161    pub const fn value(self) -> u8 {
162        self as u8
163    }
164}
165
166impl ToTlv for ActionStateEnum {
167    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
168        self.value().to_tlv(w, tag)
169    }
170}
171
172impl<'a> FromTlv<'a> for ActionStateEnum {
173    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
174        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
175        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
176    }
177}
178
179/// `ActionTypeEnum`.
180#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
181#[repr(u8)]
182pub enum ActionTypeEnum {
183    /// Use this only when none of the other values applies
184    Other = 0,
185    /// Bring the endpoints into a certain state
186    Scene = 1,
187    /// A sequence of states with a certain time pattern
188    Sequence = 2,
189    /// Control an automation (e.g. motion sensor controlling lights)
190    Automation = 3,
191    /// Sequence that will run when something doesn't happen
192    Exception = 4,
193    /// Use the endpoints to send a message to user
194    Notification = 5,
195    /// Higher priority notification
196    Alarm = 6,
197}
198
199impl ActionTypeEnum {
200    /// Reads a wire value, or `None` for one this revision does not define.
201    #[must_use]
202    pub const fn from_value(value: u8) -> Option<Self> {
203        match value {
204            0 => Some(Self::Other),
205            1 => Some(Self::Scene),
206            2 => Some(Self::Sequence),
207            3 => Some(Self::Automation),
208            4 => Some(Self::Exception),
209            5 => Some(Self::Notification),
210            6 => Some(Self::Alarm),
211            _ => None,
212        }
213    }
214
215    /// Its wire value.
216    #[must_use]
217    pub const fn value(self) -> u8 {
218        self as u8
219    }
220}
221
222impl ToTlv for ActionTypeEnum {
223    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
224        self.value().to_tlv(w, tag)
225    }
226}
227
228impl<'a> FromTlv<'a> for ActionTypeEnum {
229    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
230        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
231        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
232    }
233}
234
235/// `EndpointListTypeEnum`.
236#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
237#[repr(u8)]
238pub enum EndpointListTypeEnum {
239    /// Another group of endpoints
240    Other = 0,
241    /// User-configured group of endpoints where an endpoint can be in only one room
242    Room = 1,
243    /// User-configured group of endpoints where an endpoint can be in any number of zones
244    Zone = 2,
245}
246
247impl EndpointListTypeEnum {
248    /// Reads a wire value, or `None` for one this revision does not define.
249    #[must_use]
250    pub const fn from_value(value: u8) -> Option<Self> {
251        match value {
252            0 => Some(Self::Other),
253            1 => Some(Self::Room),
254            2 => Some(Self::Zone),
255            _ => None,
256        }
257    }
258
259    /// Its wire value.
260    #[must_use]
261    pub const fn value(self) -> u8 {
262        self as u8
263    }
264}
265
266impl ToTlv for EndpointListTypeEnum {
267    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
268        self.value().to_tlv(w, tag)
269    }
270}
271
272impl<'a> FromTlv<'a> for EndpointListTypeEnum {
273    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
274        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
275        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
276    }
277}
278
279bitflags::bitflags! {
280    /// `CommandBits`.
281    #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
282    pub struct CommandBits: u16 {
283        /// Indicate support for InstantAction command
284        const INSTANT_ACTION = 1 << 0;
285        /// Indicate support for InstantActionWithTransition command
286        const INSTANT_ACTION_WITH_TRANSITION = 1 << 1;
287        /// Indicate support for StartAction command
288        const START_ACTION = 1 << 2;
289        /// Indicate support for StartActionWithDuration command
290        const START_ACTION_WITH_DURATION = 1 << 3;
291        /// Indicate support for StopAction command
292        const STOP_ACTION = 1 << 4;
293        /// Indicate support for PauseAction command
294        const PAUSE_ACTION = 1 << 5;
295        /// Indicate support for PauseActionWithDuration command
296        const PAUSE_ACTION_WITH_DURATION = 1 << 6;
297        /// Indicate support for ResumeAction command
298        const RESUME_ACTION = 1 << 7;
299        /// Indicate support for EnableAction command
300        const ENABLE_ACTION = 1 << 8;
301        /// Indicate support for EnableActionWithDuration command
302        const ENABLE_ACTION_WITH_DURATION = 1 << 9;
303        /// Indicate support for DisableAction command
304        const DISABLE_ACTION = 1 << 10;
305        /// Indicate support for DisableActionWithDuration command
306        const DISABLE_ACTION_WITH_DURATION = 1 << 11;
307    }
308}
309
310impl ToTlv for CommandBits {
311    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
312        self.bits().to_tlv(w, tag)
313    }
314}
315
316impl<'a> FromTlv<'a> for CommandBits {
317    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
318        let bits = <u16 as FromTlv<'a>>::from_tlv(reader, element)?;
319        Self::from_bits(bits).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
320    }
321}
322
323/// `ActionStruct`.
324#[derive(Debug, Clone, Copy, PartialEq)]
325pub struct ActionStruct<'a> {
326    /// `ActionID`, field 0.
327    pub action_id: u16,
328    /// `Name`, field 1.
329    pub name: &'a str,
330    /// `Type`, field 2.
331    pub type_: ActionTypeEnum,
332    /// `EndpointListID`, field 3.
333    pub endpoint_list_id: u16,
334    /// `SupportedCommands`, field 4.
335    pub supported_commands: CommandBits,
336    /// `State`, field 5.
337    pub state: ActionStateEnum,
338}
339
340impl<'a> ToTlv for ActionStruct<'a> {
341    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
342        w.start_structure(tag)?;
343        self.action_id.to_tlv(w, Tag::Context(0))?;
344        self.name.to_tlv(w, Tag::Context(1))?;
345        self.type_.to_tlv(w, Tag::Context(2))?;
346        self.endpoint_list_id.to_tlv(w, Tag::Context(3))?;
347        self.supported_commands.to_tlv(w, Tag::Context(4))?;
348        self.state.to_tlv(w, Tag::Context(5))?;
349        w.end_container()
350    }
351}
352
353impl<'a> FromTlv<'a> for ActionStruct<'a> {
354    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
355        if element.value.container() != Some(ContainerKind::Structure) {
356            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
357        }
358        let mut action_id = None;
359        let mut name = None;
360        let mut type_ = None;
361        let mut endpoint_list_id = None;
362        let mut supported_commands = None;
363        let mut state = None;
364        loop {
365            let Some(field) = reader.next_element()? else {
366                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
367            };
368            if field.value == Value::EndOfContainer {
369                break;
370            }
371            match field.tag.context() {
372                Some(0) => action_id = Some(<u16>::from_tlv(reader, &field)?),
373                Some(1) => name = Some(<&'a str>::from_tlv(reader, &field)?),
374                Some(2) => type_ = Some(<ActionTypeEnum>::from_tlv(reader, &field)?),
375                Some(3) => endpoint_list_id = Some(<u16>::from_tlv(reader, &field)?),
376                Some(4) => supported_commands = Some(<CommandBits>::from_tlv(reader, &field)?),
377                Some(5) => state = Some(<ActionStateEnum>::from_tlv(reader, &field)?),
378                // A field this revision does not define. §7.19.2: a receiver
379                // ignores what it does not know rather than refusing the whole
380                // structure, which is what lets a newer peer talk to an older one.
381                _ => reader.skip_value(&field)?,
382            }
383        }
384        Ok(Self {
385            action_id: action_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
386            name: name.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
387            type_: type_.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
388            endpoint_list_id: endpoint_list_id
389                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
390            supported_commands: supported_commands
391                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
392            state: state.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
393        })
394    }
395}
396
397/// `EndpointListStruct`.
398#[derive(Debug, Clone, Copy, PartialEq)]
399pub struct EndpointListStruct<'a> {
400    /// `EndpointListID`, field 0.
401    pub endpoint_list_id: u16,
402    /// `Name`, field 1.
403    pub name: &'a str,
404    /// `Type`, field 2.
405    pub type_: EndpointListTypeEnum,
406    /// `Endpoints`, field 3.
407    pub endpoints: TlvList<'a, u16>,
408}
409
410impl<'a> ToTlv for EndpointListStruct<'a> {
411    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
412        w.start_structure(tag)?;
413        self.endpoint_list_id.to_tlv(w, Tag::Context(0))?;
414        self.name.to_tlv(w, Tag::Context(1))?;
415        self.type_.to_tlv(w, Tag::Context(2))?;
416        self.endpoints.to_tlv(w, Tag::Context(3))?;
417        w.end_container()
418    }
419}
420
421impl<'a> FromTlv<'a> for EndpointListStruct<'a> {
422    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
423        if element.value.container() != Some(ContainerKind::Structure) {
424            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
425        }
426        let mut endpoint_list_id = None;
427        let mut name = None;
428        let mut type_ = None;
429        let mut endpoints = None;
430        loop {
431            let Some(field) = reader.next_element()? else {
432                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
433            };
434            if field.value == Value::EndOfContainer {
435                break;
436            }
437            match field.tag.context() {
438                Some(0) => endpoint_list_id = Some(<u16>::from_tlv(reader, &field)?),
439                Some(1) => name = Some(<&'a str>::from_tlv(reader, &field)?),
440                Some(2) => type_ = Some(<EndpointListTypeEnum>::from_tlv(reader, &field)?),
441                Some(3) => endpoints = Some(<TlvList<'a, u16>>::from_tlv(reader, &field)?),
442                // A field this revision does not define. §7.19.2: a receiver
443                // ignores what it does not know rather than refusing the whole
444                // structure, which is what lets a newer peer talk to an older one.
445                _ => reader.skip_value(&field)?,
446            }
447        }
448        Ok(Self {
449            endpoint_list_id: endpoint_list_id
450                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
451            name: name.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
452            type_: type_.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
453            endpoints: endpoints.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
454        })
455    }
456}
457
458/// The fields of `InstantAction` (command `0x00`).
459#[derive(Debug, Clone, Copy, PartialEq)]
460pub struct InstantActionFields {
461    /// `ActionID`, field 0.
462    pub action_id: u16,
463    /// `InvokeID`, field 1.
464    pub invoke_id: Option<u32>,
465}
466
467impl ToTlv for InstantActionFields {
468    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
469        w.start_structure(tag)?;
470        self.action_id.to_tlv(w, Tag::Context(0))?;
471        if let Some(value) = &self.invoke_id {
472            value.to_tlv(w, Tag::Context(1))?;
473        }
474        w.end_container()
475    }
476}
477
478impl<'a> FromTlv<'a> for InstantActionFields {
479    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
480        if element.value.container() != Some(ContainerKind::Structure) {
481            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
482        }
483        let mut action_id = None;
484        let mut invoke_id = None;
485        loop {
486            let Some(field) = reader.next_element()? else {
487                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
488            };
489            if field.value == Value::EndOfContainer {
490                break;
491            }
492            match field.tag.context() {
493                Some(0) => action_id = Some(<u16>::from_tlv(reader, &field)?),
494                Some(1) => invoke_id = Some(<u32>::from_tlv(reader, &field)?),
495                // A field this revision does not define. §7.19.2: a receiver
496                // ignores what it does not know rather than refusing the whole
497                // structure, which is what lets a newer peer talk to an older one.
498                _ => reader.skip_value(&field)?,
499            }
500        }
501        Ok(Self {
502            action_id: action_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
503            invoke_id,
504        })
505    }
506}
507
508/// The fields of `InstantActionWithTransition` (command `0x01`).
509#[derive(Debug, Clone, Copy, PartialEq)]
510pub struct InstantActionWithTransitionFields {
511    /// `ActionID`, field 0.
512    pub action_id: u16,
513    /// `InvokeID`, field 1.
514    pub invoke_id: Option<u32>,
515    /// `TransitionTime`, field 2.
516    pub transition_time: u16,
517}
518
519impl ToTlv for InstantActionWithTransitionFields {
520    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
521        w.start_structure(tag)?;
522        self.action_id.to_tlv(w, Tag::Context(0))?;
523        if let Some(value) = &self.invoke_id {
524            value.to_tlv(w, Tag::Context(1))?;
525        }
526        self.transition_time.to_tlv(w, Tag::Context(2))?;
527        w.end_container()
528    }
529}
530
531impl<'a> FromTlv<'a> for InstantActionWithTransitionFields {
532    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
533        if element.value.container() != Some(ContainerKind::Structure) {
534            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
535        }
536        let mut action_id = None;
537        let mut invoke_id = None;
538        let mut transition_time = None;
539        loop {
540            let Some(field) = reader.next_element()? else {
541                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
542            };
543            if field.value == Value::EndOfContainer {
544                break;
545            }
546            match field.tag.context() {
547                Some(0) => action_id = Some(<u16>::from_tlv(reader, &field)?),
548                Some(1) => invoke_id = Some(<u32>::from_tlv(reader, &field)?),
549                Some(2) => transition_time = Some(<u16>::from_tlv(reader, &field)?),
550                // A field this revision does not define. §7.19.2: a receiver
551                // ignores what it does not know rather than refusing the whole
552                // structure, which is what lets a newer peer talk to an older one.
553                _ => reader.skip_value(&field)?,
554            }
555        }
556        Ok(Self {
557            action_id: action_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
558            invoke_id,
559            transition_time: transition_time
560                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
561        })
562    }
563}
564
565/// The fields of `StartAction` (command `0x02`).
566#[derive(Debug, Clone, Copy, PartialEq)]
567pub struct StartActionFields {
568    /// `ActionID`, field 0.
569    pub action_id: u16,
570    /// `InvokeID`, field 1.
571    pub invoke_id: Option<u32>,
572}
573
574impl ToTlv for StartActionFields {
575    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
576        w.start_structure(tag)?;
577        self.action_id.to_tlv(w, Tag::Context(0))?;
578        if let Some(value) = &self.invoke_id {
579            value.to_tlv(w, Tag::Context(1))?;
580        }
581        w.end_container()
582    }
583}
584
585impl<'a> FromTlv<'a> for StartActionFields {
586    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
587        if element.value.container() != Some(ContainerKind::Structure) {
588            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
589        }
590        let mut action_id = None;
591        let mut invoke_id = None;
592        loop {
593            let Some(field) = reader.next_element()? else {
594                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
595            };
596            if field.value == Value::EndOfContainer {
597                break;
598            }
599            match field.tag.context() {
600                Some(0) => action_id = Some(<u16>::from_tlv(reader, &field)?),
601                Some(1) => invoke_id = Some(<u32>::from_tlv(reader, &field)?),
602                // A field this revision does not define. §7.19.2: a receiver
603                // ignores what it does not know rather than refusing the whole
604                // structure, which is what lets a newer peer talk to an older one.
605                _ => reader.skip_value(&field)?,
606            }
607        }
608        Ok(Self {
609            action_id: action_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
610            invoke_id,
611        })
612    }
613}
614
615/// The fields of `StartActionWithDuration` (command `0x03`).
616#[derive(Debug, Clone, Copy, PartialEq)]
617pub struct StartActionWithDurationFields {
618    /// `ActionID`, field 0.
619    pub action_id: u16,
620    /// `InvokeID`, field 1.
621    pub invoke_id: Option<u32>,
622    /// `Duration`, field 2.
623    pub duration: u32,
624}
625
626impl ToTlv for StartActionWithDurationFields {
627    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
628        w.start_structure(tag)?;
629        self.action_id.to_tlv(w, Tag::Context(0))?;
630        if let Some(value) = &self.invoke_id {
631            value.to_tlv(w, Tag::Context(1))?;
632        }
633        self.duration.to_tlv(w, Tag::Context(2))?;
634        w.end_container()
635    }
636}
637
638impl<'a> FromTlv<'a> for StartActionWithDurationFields {
639    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
640        if element.value.container() != Some(ContainerKind::Structure) {
641            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
642        }
643        let mut action_id = None;
644        let mut invoke_id = None;
645        let mut duration = None;
646        loop {
647            let Some(field) = reader.next_element()? else {
648                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
649            };
650            if field.value == Value::EndOfContainer {
651                break;
652            }
653            match field.tag.context() {
654                Some(0) => action_id = Some(<u16>::from_tlv(reader, &field)?),
655                Some(1) => invoke_id = Some(<u32>::from_tlv(reader, &field)?),
656                Some(2) => duration = Some(<u32>::from_tlv(reader, &field)?),
657                // A field this revision does not define. §7.19.2: a receiver
658                // ignores what it does not know rather than refusing the whole
659                // structure, which is what lets a newer peer talk to an older one.
660                _ => reader.skip_value(&field)?,
661            }
662        }
663        Ok(Self {
664            action_id: action_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
665            invoke_id,
666            duration: duration.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
667        })
668    }
669}
670
671/// The fields of `StopAction` (command `0x04`).
672#[derive(Debug, Clone, Copy, PartialEq)]
673pub struct StopActionFields {
674    /// `ActionID`, field 0.
675    pub action_id: u16,
676    /// `InvokeID`, field 1.
677    pub invoke_id: Option<u32>,
678}
679
680impl ToTlv for StopActionFields {
681    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
682        w.start_structure(tag)?;
683        self.action_id.to_tlv(w, Tag::Context(0))?;
684        if let Some(value) = &self.invoke_id {
685            value.to_tlv(w, Tag::Context(1))?;
686        }
687        w.end_container()
688    }
689}
690
691impl<'a> FromTlv<'a> for StopActionFields {
692    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
693        if element.value.container() != Some(ContainerKind::Structure) {
694            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
695        }
696        let mut action_id = None;
697        let mut invoke_id = None;
698        loop {
699            let Some(field) = reader.next_element()? else {
700                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
701            };
702            if field.value == Value::EndOfContainer {
703                break;
704            }
705            match field.tag.context() {
706                Some(0) => action_id = Some(<u16>::from_tlv(reader, &field)?),
707                Some(1) => invoke_id = Some(<u32>::from_tlv(reader, &field)?),
708                // A field this revision does not define. §7.19.2: a receiver
709                // ignores what it does not know rather than refusing the whole
710                // structure, which is what lets a newer peer talk to an older one.
711                _ => reader.skip_value(&field)?,
712            }
713        }
714        Ok(Self {
715            action_id: action_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
716            invoke_id,
717        })
718    }
719}
720
721/// The fields of `PauseAction` (command `0x05`).
722#[derive(Debug, Clone, Copy, PartialEq)]
723pub struct PauseActionFields {
724    /// `ActionID`, field 0.
725    pub action_id: u16,
726    /// `InvokeID`, field 1.
727    pub invoke_id: Option<u32>,
728}
729
730impl ToTlv for PauseActionFields {
731    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
732        w.start_structure(tag)?;
733        self.action_id.to_tlv(w, Tag::Context(0))?;
734        if let Some(value) = &self.invoke_id {
735            value.to_tlv(w, Tag::Context(1))?;
736        }
737        w.end_container()
738    }
739}
740
741impl<'a> FromTlv<'a> for PauseActionFields {
742    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
743        if element.value.container() != Some(ContainerKind::Structure) {
744            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
745        }
746        let mut action_id = None;
747        let mut invoke_id = None;
748        loop {
749            let Some(field) = reader.next_element()? else {
750                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
751            };
752            if field.value == Value::EndOfContainer {
753                break;
754            }
755            match field.tag.context() {
756                Some(0) => action_id = Some(<u16>::from_tlv(reader, &field)?),
757                Some(1) => invoke_id = Some(<u32>::from_tlv(reader, &field)?),
758                // A field this revision does not define. §7.19.2: a receiver
759                // ignores what it does not know rather than refusing the whole
760                // structure, which is what lets a newer peer talk to an older one.
761                _ => reader.skip_value(&field)?,
762            }
763        }
764        Ok(Self {
765            action_id: action_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
766            invoke_id,
767        })
768    }
769}
770
771/// The fields of `PauseActionWithDuration` (command `0x06`).
772#[derive(Debug, Clone, Copy, PartialEq)]
773pub struct PauseActionWithDurationFields {
774    /// `ActionID`, field 0.
775    pub action_id: u16,
776    /// `InvokeID`, field 1.
777    pub invoke_id: Option<u32>,
778    /// `Duration`, field 2.
779    pub duration: u32,
780}
781
782impl ToTlv for PauseActionWithDurationFields {
783    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
784        w.start_structure(tag)?;
785        self.action_id.to_tlv(w, Tag::Context(0))?;
786        if let Some(value) = &self.invoke_id {
787            value.to_tlv(w, Tag::Context(1))?;
788        }
789        self.duration.to_tlv(w, Tag::Context(2))?;
790        w.end_container()
791    }
792}
793
794impl<'a> FromTlv<'a> for PauseActionWithDurationFields {
795    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
796        if element.value.container() != Some(ContainerKind::Structure) {
797            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
798        }
799        let mut action_id = None;
800        let mut invoke_id = None;
801        let mut duration = None;
802        loop {
803            let Some(field) = reader.next_element()? else {
804                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
805            };
806            if field.value == Value::EndOfContainer {
807                break;
808            }
809            match field.tag.context() {
810                Some(0) => action_id = Some(<u16>::from_tlv(reader, &field)?),
811                Some(1) => invoke_id = Some(<u32>::from_tlv(reader, &field)?),
812                Some(2) => duration = Some(<u32>::from_tlv(reader, &field)?),
813                // A field this revision does not define. §7.19.2: a receiver
814                // ignores what it does not know rather than refusing the whole
815                // structure, which is what lets a newer peer talk to an older one.
816                _ => reader.skip_value(&field)?,
817            }
818        }
819        Ok(Self {
820            action_id: action_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
821            invoke_id,
822            duration: duration.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
823        })
824    }
825}
826
827/// The fields of `ResumeAction` (command `0x07`).
828#[derive(Debug, Clone, Copy, PartialEq)]
829pub struct ResumeActionFields {
830    /// `ActionID`, field 0.
831    pub action_id: u16,
832    /// `InvokeID`, field 1.
833    pub invoke_id: Option<u32>,
834}
835
836impl ToTlv for ResumeActionFields {
837    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
838        w.start_structure(tag)?;
839        self.action_id.to_tlv(w, Tag::Context(0))?;
840        if let Some(value) = &self.invoke_id {
841            value.to_tlv(w, Tag::Context(1))?;
842        }
843        w.end_container()
844    }
845}
846
847impl<'a> FromTlv<'a> for ResumeActionFields {
848    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
849        if element.value.container() != Some(ContainerKind::Structure) {
850            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
851        }
852        let mut action_id = None;
853        let mut invoke_id = None;
854        loop {
855            let Some(field) = reader.next_element()? else {
856                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
857            };
858            if field.value == Value::EndOfContainer {
859                break;
860            }
861            match field.tag.context() {
862                Some(0) => action_id = Some(<u16>::from_tlv(reader, &field)?),
863                Some(1) => invoke_id = Some(<u32>::from_tlv(reader, &field)?),
864                // A field this revision does not define. §7.19.2: a receiver
865                // ignores what it does not know rather than refusing the whole
866                // structure, which is what lets a newer peer talk to an older one.
867                _ => reader.skip_value(&field)?,
868            }
869        }
870        Ok(Self {
871            action_id: action_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
872            invoke_id,
873        })
874    }
875}
876
877/// The fields of `EnableAction` (command `0x08`).
878#[derive(Debug, Clone, Copy, PartialEq)]
879pub struct EnableActionFields {
880    /// `ActionID`, field 0.
881    pub action_id: u16,
882    /// `InvokeID`, field 1.
883    pub invoke_id: Option<u32>,
884}
885
886impl ToTlv for EnableActionFields {
887    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
888        w.start_structure(tag)?;
889        self.action_id.to_tlv(w, Tag::Context(0))?;
890        if let Some(value) = &self.invoke_id {
891            value.to_tlv(w, Tag::Context(1))?;
892        }
893        w.end_container()
894    }
895}
896
897impl<'a> FromTlv<'a> for EnableActionFields {
898    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
899        if element.value.container() != Some(ContainerKind::Structure) {
900            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
901        }
902        let mut action_id = None;
903        let mut invoke_id = None;
904        loop {
905            let Some(field) = reader.next_element()? else {
906                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
907            };
908            if field.value == Value::EndOfContainer {
909                break;
910            }
911            match field.tag.context() {
912                Some(0) => action_id = Some(<u16>::from_tlv(reader, &field)?),
913                Some(1) => invoke_id = Some(<u32>::from_tlv(reader, &field)?),
914                // A field this revision does not define. §7.19.2: a receiver
915                // ignores what it does not know rather than refusing the whole
916                // structure, which is what lets a newer peer talk to an older one.
917                _ => reader.skip_value(&field)?,
918            }
919        }
920        Ok(Self {
921            action_id: action_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
922            invoke_id,
923        })
924    }
925}
926
927/// The fields of `EnableActionWithDuration` (command `0x09`).
928#[derive(Debug, Clone, Copy, PartialEq)]
929pub struct EnableActionWithDurationFields {
930    /// `ActionID`, field 0.
931    pub action_id: u16,
932    /// `InvokeID`, field 1.
933    pub invoke_id: Option<u32>,
934    /// `Duration`, field 2.
935    pub duration: u32,
936}
937
938impl ToTlv for EnableActionWithDurationFields {
939    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
940        w.start_structure(tag)?;
941        self.action_id.to_tlv(w, Tag::Context(0))?;
942        if let Some(value) = &self.invoke_id {
943            value.to_tlv(w, Tag::Context(1))?;
944        }
945        self.duration.to_tlv(w, Tag::Context(2))?;
946        w.end_container()
947    }
948}
949
950impl<'a> FromTlv<'a> for EnableActionWithDurationFields {
951    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
952        if element.value.container() != Some(ContainerKind::Structure) {
953            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
954        }
955        let mut action_id = None;
956        let mut invoke_id = None;
957        let mut duration = None;
958        loop {
959            let Some(field) = reader.next_element()? else {
960                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
961            };
962            if field.value == Value::EndOfContainer {
963                break;
964            }
965            match field.tag.context() {
966                Some(0) => action_id = Some(<u16>::from_tlv(reader, &field)?),
967                Some(1) => invoke_id = Some(<u32>::from_tlv(reader, &field)?),
968                Some(2) => duration = Some(<u32>::from_tlv(reader, &field)?),
969                // A field this revision does not define. §7.19.2: a receiver
970                // ignores what it does not know rather than refusing the whole
971                // structure, which is what lets a newer peer talk to an older one.
972                _ => reader.skip_value(&field)?,
973            }
974        }
975        Ok(Self {
976            action_id: action_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
977            invoke_id,
978            duration: duration.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
979        })
980    }
981}
982
983/// The fields of `DisableAction` (command `0x0A`).
984#[derive(Debug, Clone, Copy, PartialEq)]
985pub struct DisableActionFields {
986    /// `ActionID`, field 0.
987    pub action_id: u16,
988    /// `InvokeID`, field 1.
989    pub invoke_id: Option<u32>,
990}
991
992impl ToTlv for DisableActionFields {
993    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
994        w.start_structure(tag)?;
995        self.action_id.to_tlv(w, Tag::Context(0))?;
996        if let Some(value) = &self.invoke_id {
997            value.to_tlv(w, Tag::Context(1))?;
998        }
999        w.end_container()
1000    }
1001}
1002
1003impl<'a> FromTlv<'a> for DisableActionFields {
1004    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
1005        if element.value.container() != Some(ContainerKind::Structure) {
1006            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
1007        }
1008        let mut action_id = None;
1009        let mut invoke_id = None;
1010        loop {
1011            let Some(field) = reader.next_element()? else {
1012                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
1013            };
1014            if field.value == Value::EndOfContainer {
1015                break;
1016            }
1017            match field.tag.context() {
1018                Some(0) => action_id = Some(<u16>::from_tlv(reader, &field)?),
1019                Some(1) => invoke_id = Some(<u32>::from_tlv(reader, &field)?),
1020                // A field this revision does not define. §7.19.2: a receiver
1021                // ignores what it does not know rather than refusing the whole
1022                // structure, which is what lets a newer peer talk to an older one.
1023                _ => reader.skip_value(&field)?,
1024            }
1025        }
1026        Ok(Self {
1027            action_id: action_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
1028            invoke_id,
1029        })
1030    }
1031}
1032
1033/// The fields of `DisableActionWithDuration` (command `0x0B`).
1034#[derive(Debug, Clone, Copy, PartialEq)]
1035pub struct DisableActionWithDurationFields {
1036    /// `ActionID`, field 0.
1037    pub action_id: u16,
1038    /// `InvokeID`, field 1.
1039    pub invoke_id: Option<u32>,
1040    /// `Duration`, field 2.
1041    pub duration: u32,
1042}
1043
1044impl ToTlv for DisableActionWithDurationFields {
1045    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
1046        w.start_structure(tag)?;
1047        self.action_id.to_tlv(w, Tag::Context(0))?;
1048        if let Some(value) = &self.invoke_id {
1049            value.to_tlv(w, Tag::Context(1))?;
1050        }
1051        self.duration.to_tlv(w, Tag::Context(2))?;
1052        w.end_container()
1053    }
1054}
1055
1056impl<'a> FromTlv<'a> for DisableActionWithDurationFields {
1057    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
1058        if element.value.container() != Some(ContainerKind::Structure) {
1059            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
1060        }
1061        let mut action_id = None;
1062        let mut invoke_id = None;
1063        let mut duration = None;
1064        loop {
1065            let Some(field) = reader.next_element()? else {
1066                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
1067            };
1068            if field.value == Value::EndOfContainer {
1069                break;
1070            }
1071            match field.tag.context() {
1072                Some(0) => action_id = Some(<u16>::from_tlv(reader, &field)?),
1073                Some(1) => invoke_id = Some(<u32>::from_tlv(reader, &field)?),
1074                Some(2) => duration = Some(<u32>::from_tlv(reader, &field)?),
1075                // A field this revision does not define. §7.19.2: a receiver
1076                // ignores what it does not know rather than refusing the whole
1077                // structure, which is what lets a newer peer talk to an older one.
1078                _ => reader.skip_value(&field)?,
1079            }
1080        }
1081        Ok(Self {
1082            action_id: action_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
1083            invoke_id,
1084            duration: duration.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
1085        })
1086    }
1087}
1088
1089/// Every attribute the specification defines, with its conformance.
1090pub const ATTRIBUTES: &[Attribute] = &[
1091    Attribute {
1092        id: 0x0000,
1093        name: "ActionList",
1094        kind: "list[ActionStruct]",
1095        access: Access::read_only(Privilege::View),
1096        qualities: AttributeQualities::empty(),
1097        reporting: Reporting::OnChange,
1098        conform: Conform::MANDATORY,
1099    },
1100    Attribute {
1101        id: 0x0001,
1102        name: "EndpointLists",
1103        kind: "list[EndpointListStruct]",
1104        access: Access::read_only(Privilege::View),
1105        qualities: AttributeQualities::empty(),
1106        reporting: Reporting::OnChange,
1107        conform: Conform::MANDATORY,
1108    },
1109    Attribute {
1110        id: 0x0002,
1111        name: "SetupURL",
1112        kind: "string",
1113        access: Access::read_only(Privilege::View),
1114        qualities: AttributeQualities::empty(),
1115        reporting: Reporting::OnChange,
1116        conform: Conform::OPTIONAL,
1117    },
1118];
1119
1120/// Every command, with its conformance.
1121pub const COMMANDS: &[Command] = &[
1122    Command {
1123        id: 0x00,
1124        name: "InstantAction",
1125        to_server: true,
1126        response: None,
1127        access: Access::invoke(Privilege::Operate),
1128        conform: Conform::DESCRIBED,
1129    },
1130    Command {
1131        id: 0x01,
1132        name: "InstantActionWithTransition",
1133        to_server: true,
1134        response: None,
1135        access: Access::invoke(Privilege::Operate),
1136        conform: Conform::DESCRIBED,
1137    },
1138    Command {
1139        id: 0x02,
1140        name: "StartAction",
1141        to_server: true,
1142        response: None,
1143        access: Access::invoke(Privilege::Operate),
1144        conform: Conform::DESCRIBED,
1145    },
1146    Command {
1147        id: 0x03,
1148        name: "StartActionWithDuration",
1149        to_server: true,
1150        response: None,
1151        access: Access::invoke(Privilege::Operate),
1152        conform: Conform::DESCRIBED,
1153    },
1154    Command {
1155        id: 0x04,
1156        name: "StopAction",
1157        to_server: true,
1158        response: None,
1159        access: Access::invoke(Privilege::Operate),
1160        conform: Conform::DESCRIBED,
1161    },
1162    Command {
1163        id: 0x05,
1164        name: "PauseAction",
1165        to_server: true,
1166        response: None,
1167        access: Access::invoke(Privilege::Operate),
1168        conform: Conform::DESCRIBED,
1169    },
1170    Command {
1171        id: 0x06,
1172        name: "PauseActionWithDuration",
1173        to_server: true,
1174        response: None,
1175        access: Access::invoke(Privilege::Operate),
1176        conform: Conform::DESCRIBED,
1177    },
1178    Command {
1179        id: 0x07,
1180        name: "ResumeAction",
1181        to_server: true,
1182        response: None,
1183        access: Access::invoke(Privilege::Operate),
1184        conform: Conform::DESCRIBED,
1185    },
1186    Command {
1187        id: 0x08,
1188        name: "EnableAction",
1189        to_server: true,
1190        response: None,
1191        access: Access::invoke(Privilege::Operate),
1192        conform: Conform::DESCRIBED,
1193    },
1194    Command {
1195        id: 0x09,
1196        name: "EnableActionWithDuration",
1197        to_server: true,
1198        response: None,
1199        access: Access::invoke(Privilege::Operate),
1200        conform: Conform::DESCRIBED,
1201    },
1202    Command {
1203        id: 0x0A,
1204        name: "DisableAction",
1205        to_server: true,
1206        response: None,
1207        access: Access::invoke(Privilege::Operate),
1208        conform: Conform::DESCRIBED,
1209    },
1210    Command {
1211        id: 0x0B,
1212        name: "DisableActionWithDuration",
1213        to_server: true,
1214        response: None,
1215        access: Access::invoke(Privilege::Operate),
1216        conform: Conform::DESCRIBED,
1217    },
1218];
1219
1220/// Every event, with its conformance.
1221pub const EVENTS: &[Event] = &[
1222    Event {
1223        id: 0x00,
1224        name: "StateChanged",
1225        priority: EventPriority::Info,
1226        access: Access::read_only(Privilege::View),
1227        conform: Conform::MANDATORY,
1228    },
1229    Event {
1230        id: 0x01,
1231        name: "ActionFailed",
1232        priority: EventPriority::Info,
1233        access: Access::read_only(Privilege::View),
1234        conform: Conform::MANDATORY,
1235    },
1236];
1237
1238/// The whole cluster, as the specification defines it.
1239pub const CLUSTER: Cluster = Cluster {
1240    id: ID,
1241    name: "Actions",
1242    revision: REVISION,
1243    pics: "ACT",
1244    derived_from: None,
1245    features: FEATURES,
1246    attributes: ATTRIBUTES,
1247    commands: COMMANDS,
1248    events: EVENTS,
1249};