1#![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
26pub const ID: ClusterId = 0x0025;
28
29pub const REVISION: u16 = 1;
32
33pub const PICS: &str = "ACT";
35
36pub const FEATURES: &[Feature] = &[];
38
39pub mod attribute {
41 use crate::im::AttributeId;
42
43 pub const ACTION_LIST: AttributeId = 0x00;
45 pub const ENDPOINT_LISTS: AttributeId = 0x01;
47 pub const SETUP_URL: AttributeId = 0x02;
49}
50
51pub mod command {
53 use crate::im::CommandId;
54
55 pub const INSTANT_ACTION: CommandId = 0x00;
57 pub const INSTANT_ACTION_WITH_TRANSITION: CommandId = 0x01;
59 pub const START_ACTION: CommandId = 0x02;
61 pub const START_ACTION_WITH_DURATION: CommandId = 0x03;
63 pub const STOP_ACTION: CommandId = 0x04;
65 pub const PAUSE_ACTION: CommandId = 0x05;
67 pub const PAUSE_ACTION_WITH_DURATION: CommandId = 0x06;
69 pub const RESUME_ACTION: CommandId = 0x07;
71 pub const ENABLE_ACTION: CommandId = 0x08;
73 pub const ENABLE_ACTION_WITH_DURATION: CommandId = 0x09;
75 pub const DISABLE_ACTION: CommandId = 0x0A;
77 pub const DISABLE_ACTION_WITH_DURATION: CommandId = 0x0B;
79}
80
81pub mod event {
83 use crate::im::EventId;
84
85 pub const STATE_CHANGED: EventId = 0x00;
87 pub const ACTION_FAILED: EventId = 0x01;
89}
90
91#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
93#[repr(u8)]
94pub enum ActionErrorEnum {
95 Unknown = 0,
97 Interrupted = 1,
99}
100
101impl ActionErrorEnum {
102 #[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 #[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#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
134#[repr(u8)]
135pub enum ActionStateEnum {
136 Inactive = 0,
138 Active = 1,
140 Paused = 2,
142 Disabled = 3,
144}
145
146impl ActionStateEnum {
147 #[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 #[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#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
181#[repr(u8)]
182pub enum ActionTypeEnum {
183 Other = 0,
185 Scene = 1,
187 Sequence = 2,
189 Automation = 3,
191 Exception = 4,
193 Notification = 5,
195 Alarm = 6,
197}
198
199impl ActionTypeEnum {
200 #[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 #[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#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
237#[repr(u8)]
238pub enum EndpointListTypeEnum {
239 Other = 0,
241 Room = 1,
243 Zone = 2,
245}
246
247impl EndpointListTypeEnum {
248 #[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 #[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 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
282 pub struct CommandBits: u16 {
283 const INSTANT_ACTION = 1 << 0;
285 const INSTANT_ACTION_WITH_TRANSITION = 1 << 1;
287 const START_ACTION = 1 << 2;
289 const START_ACTION_WITH_DURATION = 1 << 3;
291 const STOP_ACTION = 1 << 4;
293 const PAUSE_ACTION = 1 << 5;
295 const PAUSE_ACTION_WITH_DURATION = 1 << 6;
297 const RESUME_ACTION = 1 << 7;
299 const ENABLE_ACTION = 1 << 8;
301 const ENABLE_ACTION_WITH_DURATION = 1 << 9;
303 const DISABLE_ACTION = 1 << 10;
305 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#[derive(Debug, Clone, Copy, PartialEq)]
325pub struct ActionStruct<'a> {
326 pub action_id: u16,
328 pub name: &'a str,
330 pub type_: ActionTypeEnum,
332 pub endpoint_list_id: u16,
334 pub supported_commands: CommandBits,
336 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 _ => 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#[derive(Debug, Clone, Copy, PartialEq)]
399pub struct EndpointListStruct<'a> {
400 pub endpoint_list_id: u16,
402 pub name: &'a str,
404 pub type_: EndpointListTypeEnum,
406 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 _ => 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#[derive(Debug, Clone, Copy, PartialEq)]
460pub struct InstantActionFields {
461 pub action_id: u16,
463 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 _ => 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#[derive(Debug, Clone, Copy, PartialEq)]
510pub struct InstantActionWithTransitionFields {
511 pub action_id: u16,
513 pub invoke_id: Option<u32>,
515 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 _ => 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#[derive(Debug, Clone, Copy, PartialEq)]
567pub struct StartActionFields {
568 pub action_id: u16,
570 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 _ => 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#[derive(Debug, Clone, Copy, PartialEq)]
617pub struct StartActionWithDurationFields {
618 pub action_id: u16,
620 pub invoke_id: Option<u32>,
622 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 _ => 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#[derive(Debug, Clone, Copy, PartialEq)]
673pub struct StopActionFields {
674 pub action_id: u16,
676 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 _ => 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#[derive(Debug, Clone, Copy, PartialEq)]
723pub struct PauseActionFields {
724 pub action_id: u16,
726 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 _ => 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#[derive(Debug, Clone, Copy, PartialEq)]
773pub struct PauseActionWithDurationFields {
774 pub action_id: u16,
776 pub invoke_id: Option<u32>,
778 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 _ => 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#[derive(Debug, Clone, Copy, PartialEq)]
829pub struct ResumeActionFields {
830 pub action_id: u16,
832 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 _ => 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#[derive(Debug, Clone, Copy, PartialEq)]
879pub struct EnableActionFields {
880 pub action_id: u16,
882 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 _ => 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#[derive(Debug, Clone, Copy, PartialEq)]
929pub struct EnableActionWithDurationFields {
930 pub action_id: u16,
932 pub invoke_id: Option<u32>,
934 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 _ => 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#[derive(Debug, Clone, Copy, PartialEq)]
985pub struct DisableActionFields {
986 pub action_id: u16,
988 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 _ => 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#[derive(Debug, Clone, Copy, PartialEq)]
1035pub struct DisableActionWithDurationFields {
1036 pub action_id: u16,
1038 pub invoke_id: Option<u32>,
1040 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 _ => 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
1089pub 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
1120pub 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
1220pub 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
1238pub 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};