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 = 0x0431;
28
29pub const REVISION: u16 = 1;
32
33pub const PICS: &str = "ACS";
35
36pub mod feature {
41 pub const HUMAN_ACTIVITY: u32 = 1 << 0;
45 pub const OBJECT_COUNTING: u32 = 1 << 1;
49 pub const OBJECT_IDENTIFICATION: u32 = 1 << 2;
53 pub const SOUND_IDENTIFICATION: u32 = 1 << 3;
57 pub const PREDICTED_ACTIVITY: u32 = 1 << 4;
61}
62
63pub const FEATURES: &[Feature] = &[
65 Feature {
66 bit: 0,
67 code: "HA",
68 name: "HumanActivity",
69 conform: Conform {
70 clauses: &[
71 Clause {
72 verdict: Conformance::Provisional,
73 when: Condition::Always,
74 },
75 Clause {
76 verdict: Conformance::Optional,
77 when: Condition::Always,
78 },
79 ],
80 },
81 },
82 Feature {
83 bit: 1,
84 code: "OC",
85 name: "ObjectCounting",
86 conform: Conform {
87 clauses: &[
88 Clause {
89 verdict: Conformance::Provisional,
90 when: Condition::Always,
91 },
92 Clause {
93 verdict: Conformance::Optional,
94 when: Condition::Always,
95 },
96 ],
97 },
98 },
99 Feature {
100 bit: 2,
101 code: "OI",
102 name: "ObjectIdentification",
103 conform: Conform {
104 clauses: &[
105 Clause {
106 verdict: Conformance::Provisional,
107 when: Condition::Always,
108 },
109 Clause {
110 verdict: Conformance::Optional,
111 when: Condition::Always,
112 },
113 ],
114 },
115 },
116 Feature {
117 bit: 3,
118 code: "AUD",
119 name: "SoundIdentification",
120 conform: Conform {
121 clauses: &[
122 Clause {
123 verdict: Conformance::Provisional,
124 when: Condition::Always,
125 },
126 Clause {
127 verdict: Conformance::Optional,
128 when: Condition::Always,
129 },
130 ],
131 },
132 },
133 Feature {
134 bit: 4,
135 code: "PRED",
136 name: "PredictedActivity",
137 conform: Conform {
138 clauses: &[
139 Clause {
140 verdict: Conformance::Provisional,
141 when: Condition::Always,
142 },
143 Clause {
144 verdict: Conformance::Optional,
145 when: Condition::Always,
146 },
147 ],
148 },
149 },
150];
151
152pub mod attribute {
154 use crate::im::AttributeId;
155
156 pub const HUMAN_ACTIVITY_DETECTED: AttributeId = 0x00;
158 pub const OBJECT_IDENTIFIED: AttributeId = 0x01;
160 pub const AUDIO_CONTEXT_DETECTED: AttributeId = 0x02;
162 pub const AMBIENT_CONTEXT_TYPE: AttributeId = 0x03;
164 pub const AMBIENT_CONTEXT_TYPE_SUPPORTED: AttributeId = 0x04;
166 pub const OBJECT_COUNT_REACHED: AttributeId = 0x05;
168 pub const OBJECT_COUNT_CONFIG: AttributeId = 0x06;
170 pub const OBJECT_COUNT: AttributeId = 0x07;
172 pub const SIMULTANEOUS_DETECTION_LIMIT: AttributeId = 0x08;
174 pub const HOLD_TIME: AttributeId = 0x09;
176 pub const HOLD_TIME_LIMITS: AttributeId = 0x0A;
178 pub const PREDICTED_ACTIVITY: AttributeId = 0x0B;
180}
181
182pub mod event {
184 use crate::im::EventId;
185
186 pub const AMBIENT_CONTEXT_DETECT_STARTED: EventId = 0x00;
188 pub const AMBIENT_CONTEXT_DETECT_ENDED: EventId = 0x01;
190}
191
192#[derive(Debug, Clone, Copy, PartialEq)]
194pub struct AmbientContextTypeStruct<'a> {
195 pub ambient_context_sensed:
197 TlvList<'a, crate::clusters::generated::globals::SemanticTagStruct<'a>>,
198}
199
200impl<'a> ToTlv for AmbientContextTypeStruct<'a> {
201 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
202 w.start_structure(tag)?;
203 self.ambient_context_sensed.to_tlv(w, Tag::Context(0))?;
204 w.end_container()
205 }
206}
207
208impl<'a> FromTlv<'a> for AmbientContextTypeStruct<'a> {
209 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
210 if element.value.container() != Some(ContainerKind::Structure) {
211 return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
212 }
213 let mut ambient_context_sensed = None;
214 loop {
215 let Some(field) = reader.next_element()? else {
216 return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
217 };
218 if field.value == Value::EndOfContainer {
219 break;
220 }
221 match field.tag.context() {
222 Some(0) => {
223 ambient_context_sensed = Some(<TlvList<
224 'a,
225 crate::clusters::generated::globals::SemanticTagStruct<'a>,
226 >>::from_tlv(reader, &field)?)
227 }
228 _ => reader.skip_value(&field)?,
232 }
233 }
234 Ok(Self {
235 ambient_context_sensed: ambient_context_sensed
236 .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
237 })
238 }
239}
240
241#[derive(Debug, Clone, Copy, PartialEq)]
243pub struct HoldTimeLimitsStruct {
244 pub hold_time_min: u16,
246 pub hold_time_max: u16,
248 pub hold_time_default: u16,
250}
251
252impl ToTlv for HoldTimeLimitsStruct {
253 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
254 w.start_structure(tag)?;
255 self.hold_time_min.to_tlv(w, Tag::Context(0))?;
256 self.hold_time_max.to_tlv(w, Tag::Context(1))?;
257 self.hold_time_default.to_tlv(w, Tag::Context(2))?;
258 w.end_container()
259 }
260}
261
262impl<'a> FromTlv<'a> for HoldTimeLimitsStruct {
263 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
264 if element.value.container() != Some(ContainerKind::Structure) {
265 return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
266 }
267 let mut hold_time_min = None;
268 let mut hold_time_max = None;
269 let mut hold_time_default = None;
270 loop {
271 let Some(field) = reader.next_element()? else {
272 return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
273 };
274 if field.value == Value::EndOfContainer {
275 break;
276 }
277 match field.tag.context() {
278 Some(0) => hold_time_min = Some(<u16>::from_tlv(reader, &field)?),
279 Some(1) => hold_time_max = Some(<u16>::from_tlv(reader, &field)?),
280 Some(2) => hold_time_default = Some(<u16>::from_tlv(reader, &field)?),
281 _ => reader.skip_value(&field)?,
285 }
286 }
287 Ok(Self {
288 hold_time_min: hold_time_min.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
289 hold_time_max: hold_time_max.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
290 hold_time_default: hold_time_default
291 .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
292 })
293 }
294}
295
296#[derive(Debug, Clone, Copy, PartialEq)]
298pub struct ObjectCountConfigStruct<'a> {
299 pub counting_object: crate::clusters::generated::globals::SemanticTagStruct<'a>,
301 pub object_count_threshold: u16,
303}
304
305impl<'a> ToTlv for ObjectCountConfigStruct<'a> {
306 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
307 w.start_structure(tag)?;
308 self.counting_object.to_tlv(w, Tag::Context(0))?;
309 self.object_count_threshold.to_tlv(w, Tag::Context(1))?;
310 w.end_container()
311 }
312}
313
314impl<'a> FromTlv<'a> for ObjectCountConfigStruct<'a> {
315 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
316 if element.value.container() != Some(ContainerKind::Structure) {
317 return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
318 }
319 let mut counting_object = None;
320 let mut object_count_threshold = None;
321 loop {
322 let Some(field) = reader.next_element()? else {
323 return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
324 };
325 if field.value == Value::EndOfContainer {
326 break;
327 }
328 match field.tag.context() {
329 Some(0) => {
330 counting_object = Some(<crate::clusters::generated::globals::SemanticTagStruct<
331 'a,
332 >>::from_tlv(reader, &field)?)
333 }
334 Some(1) => object_count_threshold = Some(<u16>::from_tlv(reader, &field)?),
335 _ => reader.skip_value(&field)?,
339 }
340 }
341 Ok(Self {
342 counting_object: counting_object
343 .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
344 object_count_threshold: object_count_threshold
345 .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
346 })
347 }
348}
349
350#[derive(Debug, Clone, Copy, PartialEq)]
352pub struct PredictedActivityStruct<'a> {
353 pub start_timestamp: u32,
355 pub end_timestamp: u32,
357 pub ambient_context_type:
359 Option<TlvList<'a, crate::clusters::generated::globals::SemanticTagStruct<'a>>>,
360 pub crowd_detected: Option<bool>,
362 pub crowd_count: Option<u8>,
364 pub confidence: u8,
366}
367
368impl<'a> ToTlv for PredictedActivityStruct<'a> {
369 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
370 w.start_structure(tag)?;
371 self.start_timestamp.to_tlv(w, Tag::Context(0))?;
372 self.end_timestamp.to_tlv(w, Tag::Context(1))?;
373 if let Some(value) = &self.ambient_context_type {
374 value.to_tlv(w, Tag::Context(2))?;
375 }
376 if let Some(value) = &self.crowd_detected {
377 value.to_tlv(w, Tag::Context(3))?;
378 }
379 if let Some(value) = &self.crowd_count {
380 value.to_tlv(w, Tag::Context(4))?;
381 }
382 self.confidence.to_tlv(w, Tag::Context(5))?;
383 w.end_container()
384 }
385}
386
387impl<'a> FromTlv<'a> for PredictedActivityStruct<'a> {
388 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
389 if element.value.container() != Some(ContainerKind::Structure) {
390 return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
391 }
392 let mut start_timestamp = None;
393 let mut end_timestamp = None;
394 let mut ambient_context_type = None;
395 let mut crowd_detected = None;
396 let mut crowd_count = None;
397 let mut confidence = None;
398 loop {
399 let Some(field) = reader.next_element()? else {
400 return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
401 };
402 if field.value == Value::EndOfContainer {
403 break;
404 }
405 match field.tag.context() {
406 Some(0) => start_timestamp = Some(<u32>::from_tlv(reader, &field)?),
407 Some(1) => end_timestamp = Some(<u32>::from_tlv(reader, &field)?),
408 Some(2) => {
409 ambient_context_type = Some(<TlvList<
410 'a,
411 crate::clusters::generated::globals::SemanticTagStruct<'a>,
412 >>::from_tlv(reader, &field)?)
413 }
414 Some(3) => crowd_detected = Some(<bool>::from_tlv(reader, &field)?),
415 Some(4) => crowd_count = Some(<u8>::from_tlv(reader, &field)?),
416 Some(5) => confidence = Some(<u8>::from_tlv(reader, &field)?),
417 _ => reader.skip_value(&field)?,
421 }
422 }
423 Ok(Self {
424 start_timestamp: start_timestamp
425 .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
426 end_timestamp: end_timestamp.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
427 ambient_context_type,
428 crowd_detected,
429 crowd_count,
430 confidence: confidence.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
431 })
432 }
433}
434
435pub const ATTRIBUTES: &[Attribute] = &[
437 Attribute {
438 id: 0x0000,
439 name: "HumanActivityDetected",
440 kind: "bool",
441 access: Access::read_only(Privilege::View),
442 qualities: AttributeQualities::empty(),
443 reporting: Reporting::OnChange,
444 conform: Conform {
445 clauses: &[
446 Clause {
447 verdict: Conformance::Provisional,
448 when: Condition::Always,
449 },
450 Clause {
451 verdict: Conformance::Mandatory,
452 when: Condition::Feature(0),
453 },
454 ],
455 },
456 },
457 Attribute {
458 id: 0x0001,
459 name: "ObjectIdentified",
460 kind: "bool",
461 access: Access::read_only(Privilege::View),
462 qualities: AttributeQualities::empty(),
463 reporting: Reporting::OnChange,
464 conform: Conform {
465 clauses: &[
466 Clause {
467 verdict: Conformance::Provisional,
468 when: Condition::Always,
469 },
470 Clause {
471 verdict: Conformance::Mandatory,
472 when: Condition::Feature(2),
473 },
474 ],
475 },
476 },
477 Attribute {
478 id: 0x0002,
479 name: "AudioContextDetected",
480 kind: "bool",
481 access: Access::read_only(Privilege::View),
482 qualities: AttributeQualities::empty(),
483 reporting: Reporting::OnChange,
484 conform: Conform {
485 clauses: &[
486 Clause {
487 verdict: Conformance::Provisional,
488 when: Condition::Always,
489 },
490 Clause {
491 verdict: Conformance::Mandatory,
492 when: Condition::Feature(3),
493 },
494 ],
495 },
496 },
497 Attribute {
498 id: 0x0003,
499 name: "AmbientContextType",
500 kind: "list[AmbientContextTypeStruct]",
501 access: Access::read_only(Privilege::View),
502 qualities: AttributeQualities::empty(),
503 reporting: Reporting::OnChange,
504 conform: Conform {
505 clauses: &[
506 Clause {
507 verdict: Conformance::Provisional,
508 when: Condition::Always,
509 },
510 Clause {
511 verdict: Conformance::Mandatory,
512 when: Condition::Feature(0),
513 },
514 Clause {
515 verdict: Conformance::Mandatory,
516 when: Condition::Feature(2),
517 },
518 Clause {
519 verdict: Conformance::Mandatory,
520 when: Condition::Feature(3),
521 },
522 ],
523 },
524 },
525 Attribute {
526 id: 0x0004,
527 name: "AmbientContextTypeSupported",
528 kind: "list[SemanticTagStruct]",
529 access: Access::read_only(Privilege::View),
530 qualities: AttributeQualities::empty(),
531 reporting: Reporting::OnChange,
532 conform: Conform {
533 clauses: &[
534 Clause {
535 verdict: Conformance::Provisional,
536 when: Condition::Always,
537 },
538 Clause {
539 verdict: Conformance::Mandatory,
540 when: Condition::Feature(0),
541 },
542 Clause {
543 verdict: Conformance::Mandatory,
544 when: Condition::Feature(2),
545 },
546 Clause {
547 verdict: Conformance::Mandatory,
548 when: Condition::Feature(3),
549 },
550 ],
551 },
552 },
553 Attribute {
554 id: 0x0005,
555 name: "ObjectCountReached",
556 kind: "bool",
557 access: Access::read_only(Privilege::View),
558 qualities: AttributeQualities::empty(),
559 reporting: Reporting::OnChange,
560 conform: Conform {
561 clauses: &[
562 Clause {
563 verdict: Conformance::Provisional,
564 when: Condition::Always,
565 },
566 Clause {
567 verdict: Conformance::Mandatory,
568 when: Condition::All(&[Condition::Feature(1), Condition::Feature(2)]),
569 },
570 ],
571 },
572 },
573 Attribute {
574 id: 0x0006,
575 name: "ObjectCountConfig",
576 kind: "ObjectCountConfigStruct",
577 access: Access::read_write_with(Privilege::View, Privilege::Manage),
578 qualities: AttributeQualities::NON_VOLATILE,
579 reporting: Reporting::OnChange,
580 conform: Conform {
581 clauses: &[
582 Clause {
583 verdict: Conformance::Provisional,
584 when: Condition::Always,
585 },
586 Clause {
587 verdict: Conformance::Mandatory,
588 when: Condition::All(&[Condition::Feature(1), Condition::Feature(2)]),
589 },
590 ],
591 },
592 },
593 Attribute {
594 id: 0x0007,
595 name: "ObjectCount",
596 kind: "uint16",
597 access: Access::read_only(Privilege::View),
598 qualities: AttributeQualities::empty(),
599 reporting: Reporting::OnChange,
600 conform: Conform {
601 clauses: &[
602 Clause {
603 verdict: Conformance::Provisional,
604 when: Condition::Always,
605 },
606 Clause {
607 verdict: Conformance::Optional,
608 when: Condition::All(&[Condition::Feature(1), Condition::Feature(2)]),
609 },
610 ],
611 },
612 },
613 Attribute {
614 id: 0x0008,
615 name: "SimultaneousDetectionLimit",
616 kind: "uint8",
617 access: Access::read_write_with(Privilege::View, Privilege::Operate),
618 qualities: AttributeQualities::empty(),
619 reporting: Reporting::OnChange,
620 conform: Conform {
621 clauses: &[
622 Clause {
623 verdict: Conformance::Provisional,
624 when: Condition::Always,
625 },
626 Clause {
627 verdict: Conformance::Mandatory,
628 when: Condition::Always,
629 },
630 ],
631 },
632 },
633 Attribute {
634 id: 0x0009,
635 name: "HoldTime",
636 kind: "uint16",
637 access: Access::read_write_with(Privilege::View, Privilege::Manage),
638 qualities: AttributeQualities::NON_VOLATILE,
639 reporting: Reporting::OnChange,
640 conform: Conform {
641 clauses: &[
642 Clause {
643 verdict: Conformance::Provisional,
644 when: Condition::Always,
645 },
646 Clause {
647 verdict: Conformance::Mandatory,
648 when: Condition::Always,
649 },
650 ],
651 },
652 },
653 Attribute {
654 id: 0x000A,
655 name: "HoldTimeLimits",
656 kind: "HoldTimeLimitsStruct",
657 access: Access::read_only(Privilege::View),
658 qualities: AttributeQualities::FIXED,
659 reporting: Reporting::OnChange,
660 conform: Conform {
661 clauses: &[
662 Clause {
663 verdict: Conformance::Provisional,
664 when: Condition::Always,
665 },
666 Clause {
667 verdict: Conformance::Mandatory,
668 when: Condition::Always,
669 },
670 ],
671 },
672 },
673 Attribute {
674 id: 0x000B,
675 name: "PredictedActivity",
676 kind: "list[PredictedActivityStruct]",
677 access: Access::read_only(Privilege::View),
678 qualities: AttributeQualities::empty(),
679 reporting: Reporting::OnChange,
680 conform: Conform {
681 clauses: &[
682 Clause {
683 verdict: Conformance::Provisional,
684 when: Condition::Always,
685 },
686 Clause {
687 verdict: Conformance::Mandatory,
688 when: Condition::Feature(4),
689 },
690 ],
691 },
692 },
693];
694
695pub const COMMANDS: &[Command] = &[];
697
698pub const EVENTS: &[Event] = &[
700 Event {
701 id: 0x00,
702 name: "AmbientContextDetectStarted",
703 priority: EventPriority::Info,
704 access: Access::read_only(Privilege::View),
705 conform: Conform {
706 clauses: &[
707 Clause {
708 verdict: Conformance::Provisional,
709 when: Condition::Always,
710 },
711 Clause {
712 verdict: Conformance::Mandatory,
713 when: Condition::Feature(0),
714 },
715 Clause {
716 verdict: Conformance::Mandatory,
717 when: Condition::Feature(2),
718 },
719 Clause {
720 verdict: Conformance::Mandatory,
721 when: Condition::Feature(3),
722 },
723 Clause {
724 verdict: Conformance::Mandatory,
725 when: Condition::All(&[Condition::Feature(1), Condition::Feature(2)]),
726 },
727 ],
728 },
729 },
730 Event {
731 id: 0x01,
732 name: "AmbientContextDetectEnded",
733 priority: EventPriority::Info,
734 access: Access::read_only(Privilege::View),
735 conform: Conform {
736 clauses: &[
737 Clause {
738 verdict: Conformance::Provisional,
739 when: Condition::Always,
740 },
741 Clause {
742 verdict: Conformance::Mandatory,
743 when: Condition::Feature(0),
744 },
745 Clause {
746 verdict: Conformance::Mandatory,
747 when: Condition::Feature(2),
748 },
749 Clause {
750 verdict: Conformance::Mandatory,
751 when: Condition::Feature(3),
752 },
753 Clause {
754 verdict: Conformance::Mandatory,
755 when: Condition::All(&[Condition::Feature(1), Condition::Feature(2)]),
756 },
757 ],
758 },
759 },
760];
761
762pub const CLUSTER: Cluster = Cluster {
764 id: ID,
765 name: "Ambient Context Sensing",
766 revision: REVISION,
767 pics: "ACS",
768 derived_from: None,
769 features: FEATURES,
770 attributes: ATTRIBUTES,
771 commands: COMMANDS,
772 events: EVENTS,
773};