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 = 0x0550;
28
29pub const REVISION: u16 = 1;
32
33pub const PICS: &str = "ZONEMGMT";
35
36pub mod feature {
41 pub const TWO_DIMENSIONAL_CARTESIAN_ZONE: u32 = 1 << 0;
45 pub const PER_ZONE_SENSITIVITY: u32 = 1 << 1;
49 pub const USER_DEFINED: u32 = 1 << 2;
53 pub const FOCUS_ZONES: u32 = 1 << 3;
57}
58
59pub const FEATURES: &[Feature] = &[
61 Feature {
62 bit: 0,
63 code: "TWODCART",
64 name: "TwoDimensionalCartesianZone",
65 conform: Conform::OPTIONAL,
66 },
67 Feature {
68 bit: 1,
69 code: "PERZONESENS",
70 name: "PerZoneSensitivity",
71 conform: Conform {
72 clauses: &[Clause {
73 verdict: Conformance::Optional,
74 when: Condition::Feature(0),
75 }],
76 },
77 },
78 Feature {
79 bit: 2,
80 code: "USERDEFINED",
81 name: "UserDefined",
82 conform: Conform {
83 clauses: &[Clause {
84 verdict: Conformance::Optional,
85 when: Condition::Feature(0),
86 }],
87 },
88 },
89 Feature {
90 bit: 3,
91 code: "FOCUSZONES",
92 name: "FocusZones",
93 conform: Conform {
94 clauses: &[Clause {
95 verdict: Conformance::Optional,
96 when: Condition::Feature(2),
97 }],
98 },
99 },
100];
101
102pub mod attribute {
104 use crate::im::AttributeId;
105
106 pub const MAX_USER_DEFINED_ZONES: AttributeId = 0x00;
108 pub const MAX_ZONES: AttributeId = 0x01;
110 pub const ZONES: AttributeId = 0x02;
112 pub const TRIGGERS: AttributeId = 0x03;
114 pub const SENSITIVITY_MAX: AttributeId = 0x04;
116 pub const SENSITIVITY: AttributeId = 0x05;
118 pub const TWO_D_CARTESIAN_MAX: AttributeId = 0x06;
120}
121
122pub mod command {
124 use crate::im::CommandId;
125
126 pub const CREATE_TWO_D_CARTESIAN_ZONE: CommandId = 0x00;
128 pub const CREATE_TWO_D_CARTESIAN_ZONE_RESPONSE: CommandId = 0x01;
130 pub const UPDATE_TWO_D_CARTESIAN_ZONE: CommandId = 0x02;
132 pub const REMOVE_ZONE: CommandId = 0x03;
134 pub const CREATE_OR_UPDATE_TRIGGER: CommandId = 0x04;
136 pub const REMOVE_TRIGGER: CommandId = 0x05;
138}
139
140pub mod event {
142 use crate::im::EventId;
143
144 pub const ZONE_TRIGGERED: EventId = 0x00;
146 pub const ZONE_STOPPED: EventId = 0x01;
148}
149
150#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
152#[repr(u8)]
153pub enum ZoneEventStoppedReasonEnum {
154 ActionStopped = 0,
156 Timeout = 1,
158}
159
160impl ZoneEventStoppedReasonEnum {
161 #[must_use]
163 pub const fn from_value(value: u8) -> Option<Self> {
164 match value {
165 0 => Some(Self::ActionStopped),
166 1 => Some(Self::Timeout),
167 _ => None,
168 }
169 }
170
171 #[must_use]
173 pub const fn value(self) -> u8 {
174 self as u8
175 }
176}
177
178impl ToTlv for ZoneEventStoppedReasonEnum {
179 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
180 self.value().to_tlv(w, tag)
181 }
182}
183
184impl<'a> FromTlv<'a> for ZoneEventStoppedReasonEnum {
185 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
186 let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
187 Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
188 }
189}
190
191#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
193#[repr(u8)]
194pub enum ZoneEventTriggeredReasonEnum {
195 Motion = 0,
197}
198
199impl ZoneEventTriggeredReasonEnum {
200 #[must_use]
202 pub const fn from_value(value: u8) -> Option<Self> {
203 match value {
204 0 => Some(Self::Motion),
205 _ => None,
206 }
207 }
208
209 #[must_use]
211 pub const fn value(self) -> u8 {
212 self as u8
213 }
214}
215
216impl ToTlv for ZoneEventTriggeredReasonEnum {
217 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
218 self.value().to_tlv(w, tag)
219 }
220}
221
222impl<'a> FromTlv<'a> for ZoneEventTriggeredReasonEnum {
223 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
224 let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
225 Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
226 }
227}
228
229#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
231#[repr(u8)]
232pub enum ZoneSourceEnum {
233 Mfg = 0,
235 User = 1,
237}
238
239impl ZoneSourceEnum {
240 #[must_use]
242 pub const fn from_value(value: u8) -> Option<Self> {
243 match value {
244 0 => Some(Self::Mfg),
245 1 => Some(Self::User),
246 _ => None,
247 }
248 }
249
250 #[must_use]
252 pub const fn value(self) -> u8 {
253 self as u8
254 }
255}
256
257impl ToTlv for ZoneSourceEnum {
258 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
259 self.value().to_tlv(w, tag)
260 }
261}
262
263impl<'a> FromTlv<'a> for ZoneSourceEnum {
264 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
265 let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
266 Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
267 }
268}
269
270#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
272#[repr(u8)]
273pub enum ZoneTypeEnum {
274 TwoDCARTZone = 0,
276}
277
278impl ZoneTypeEnum {
279 #[must_use]
281 pub const fn from_value(value: u8) -> Option<Self> {
282 match value {
283 0 => Some(Self::TwoDCARTZone),
284 _ => None,
285 }
286 }
287
288 #[must_use]
290 pub const fn value(self) -> u8 {
291 self as u8
292 }
293}
294
295impl ToTlv for ZoneTypeEnum {
296 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
297 self.value().to_tlv(w, tag)
298 }
299}
300
301impl<'a> FromTlv<'a> for ZoneTypeEnum {
302 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
303 let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
304 Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
305 }
306}
307
308#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
310#[repr(u8)]
311pub enum ZoneUseEnum {
312 Motion = 0,
314 Privacy = 1,
316 Focus = 2,
318}
319
320impl ZoneUseEnum {
321 #[must_use]
323 pub const fn from_value(value: u8) -> Option<Self> {
324 match value {
325 0 => Some(Self::Motion),
326 1 => Some(Self::Privacy),
327 2 => Some(Self::Focus),
328 _ => None,
329 }
330 }
331
332 #[must_use]
334 pub const fn value(self) -> u8 {
335 self as u8
336 }
337}
338
339impl ToTlv for ZoneUseEnum {
340 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
341 self.value().to_tlv(w, tag)
342 }
343}
344
345impl<'a> FromTlv<'a> for ZoneUseEnum {
346 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
347 let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
348 Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
349 }
350}
351
352#[derive(Debug, Clone, Copy, PartialEq)]
354pub struct TwoDCartesianVertexStruct {
355 pub x: u16,
357 pub y: u16,
359}
360
361impl ToTlv for TwoDCartesianVertexStruct {
362 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
363 w.start_structure(tag)?;
364 self.x.to_tlv(w, Tag::Context(0))?;
365 self.y.to_tlv(w, Tag::Context(1))?;
366 w.end_container()
367 }
368}
369
370impl<'a> FromTlv<'a> for TwoDCartesianVertexStruct {
371 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
372 if element.value.container() != Some(ContainerKind::Structure) {
373 return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
374 }
375 let mut x = None;
376 let mut y = None;
377 loop {
378 let Some(field) = reader.next_element()? else {
379 return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
380 };
381 if field.value == Value::EndOfContainer {
382 break;
383 }
384 match field.tag.context() {
385 Some(0) => x = Some(<u16>::from_tlv(reader, &field)?),
386 Some(1) => y = Some(<u16>::from_tlv(reader, &field)?),
387 _ => reader.skip_value(&field)?,
391 }
392 }
393 Ok(Self {
394 x: x.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
395 y: y.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
396 })
397 }
398}
399
400#[derive(Debug, Clone, Copy, PartialEq)]
402pub struct TwoDCartesianZoneStruct<'a> {
403 pub name: &'a str,
405 pub use_: ZoneUseEnum,
407 pub vertices: TlvList<'a, TwoDCartesianVertexStruct>,
409 pub color: Option<&'a str>,
411}
412
413impl<'a> ToTlv for TwoDCartesianZoneStruct<'a> {
414 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
415 w.start_structure(tag)?;
416 self.name.to_tlv(w, Tag::Context(0))?;
417 self.use_.to_tlv(w, Tag::Context(1))?;
418 self.vertices.to_tlv(w, Tag::Context(2))?;
419 if let Some(value) = &self.color {
420 value.to_tlv(w, Tag::Context(3))?;
421 }
422 w.end_container()
423 }
424}
425
426impl<'a> FromTlv<'a> for TwoDCartesianZoneStruct<'a> {
427 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
428 if element.value.container() != Some(ContainerKind::Structure) {
429 return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
430 }
431 let mut name = None;
432 let mut use_ = None;
433 let mut vertices = None;
434 let mut color = None;
435 loop {
436 let Some(field) = reader.next_element()? else {
437 return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
438 };
439 if field.value == Value::EndOfContainer {
440 break;
441 }
442 match field.tag.context() {
443 Some(0) => name = Some(<&'a str>::from_tlv(reader, &field)?),
444 Some(1) => use_ = Some(<ZoneUseEnum>::from_tlv(reader, &field)?),
445 Some(2) => {
446 vertices = Some(<TlvList<'a, TwoDCartesianVertexStruct>>::from_tlv(
447 reader, &field,
448 )?)
449 }
450 Some(3) => color = Some(<&'a str>::from_tlv(reader, &field)?),
451 _ => reader.skip_value(&field)?,
455 }
456 }
457 Ok(Self {
458 name: name.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
459 use_: use_.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
460 vertices: vertices.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
461 color,
462 })
463 }
464}
465
466#[derive(Debug, Clone, Copy, PartialEq)]
468pub struct ZoneInformationStruct<'a> {
469 pub zone_id: u16,
471 pub zone_type: ZoneTypeEnum,
473 pub zone_source: ZoneSourceEnum,
475 pub two_d_cartesian_zone: Option<TwoDCartesianZoneStruct<'a>>,
477}
478
479impl<'a> ToTlv for ZoneInformationStruct<'a> {
480 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
481 w.start_structure(tag)?;
482 self.zone_id.to_tlv(w, Tag::Context(0))?;
483 self.zone_type.to_tlv(w, Tag::Context(1))?;
484 self.zone_source.to_tlv(w, Tag::Context(2))?;
485 if let Some(value) = &self.two_d_cartesian_zone {
486 value.to_tlv(w, Tag::Context(3))?;
487 }
488 w.end_container()
489 }
490}
491
492impl<'a> FromTlv<'a> for ZoneInformationStruct<'a> {
493 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
494 if element.value.container() != Some(ContainerKind::Structure) {
495 return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
496 }
497 let mut zone_id = None;
498 let mut zone_type = None;
499 let mut zone_source = None;
500 let mut two_d_cartesian_zone = None;
501 loop {
502 let Some(field) = reader.next_element()? else {
503 return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
504 };
505 if field.value == Value::EndOfContainer {
506 break;
507 }
508 match field.tag.context() {
509 Some(0) => zone_id = Some(<u16>::from_tlv(reader, &field)?),
510 Some(1) => zone_type = Some(<ZoneTypeEnum>::from_tlv(reader, &field)?),
511 Some(2) => zone_source = Some(<ZoneSourceEnum>::from_tlv(reader, &field)?),
512 Some(3) => {
513 two_d_cartesian_zone =
514 Some(<TwoDCartesianZoneStruct<'a>>::from_tlv(reader, &field)?)
515 }
516 _ => reader.skip_value(&field)?,
520 }
521 }
522 Ok(Self {
523 zone_id: zone_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
524 zone_type: zone_type.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
525 zone_source: zone_source.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
526 two_d_cartesian_zone,
527 })
528 }
529}
530
531#[derive(Debug, Clone, Copy, PartialEq)]
533pub struct ZoneTriggerControlStruct {
534 pub zone_id: u16,
536 pub initial_duration: u32,
538 pub augmentation_duration: u32,
540 pub max_duration: u32,
542 pub blind_duration: u32,
544 pub sensitivity: Option<u8>,
546}
547
548impl ToTlv for ZoneTriggerControlStruct {
549 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
550 w.start_structure(tag)?;
551 self.zone_id.to_tlv(w, Tag::Context(0))?;
552 self.initial_duration.to_tlv(w, Tag::Context(1))?;
553 self.augmentation_duration.to_tlv(w, Tag::Context(2))?;
554 self.max_duration.to_tlv(w, Tag::Context(3))?;
555 self.blind_duration.to_tlv(w, Tag::Context(4))?;
556 if let Some(value) = &self.sensitivity {
557 value.to_tlv(w, Tag::Context(5))?;
558 }
559 w.end_container()
560 }
561}
562
563impl<'a> FromTlv<'a> for ZoneTriggerControlStruct {
564 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
565 if element.value.container() != Some(ContainerKind::Structure) {
566 return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
567 }
568 let mut zone_id = None;
569 let mut initial_duration = None;
570 let mut augmentation_duration = None;
571 let mut max_duration = None;
572 let mut blind_duration = None;
573 let mut sensitivity = None;
574 loop {
575 let Some(field) = reader.next_element()? else {
576 return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
577 };
578 if field.value == Value::EndOfContainer {
579 break;
580 }
581 match field.tag.context() {
582 Some(0) => zone_id = Some(<u16>::from_tlv(reader, &field)?),
583 Some(1) => initial_duration = Some(<u32>::from_tlv(reader, &field)?),
584 Some(2) => augmentation_duration = Some(<u32>::from_tlv(reader, &field)?),
585 Some(3) => max_duration = Some(<u32>::from_tlv(reader, &field)?),
586 Some(4) => blind_duration = Some(<u32>::from_tlv(reader, &field)?),
587 Some(5) => sensitivity = Some(<u8>::from_tlv(reader, &field)?),
588 _ => reader.skip_value(&field)?,
592 }
593 }
594 Ok(Self {
595 zone_id: zone_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
596 initial_duration: initial_duration
597 .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
598 augmentation_duration: augmentation_duration
599 .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
600 max_duration: max_duration.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
601 blind_duration: blind_duration
602 .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
603 sensitivity,
604 })
605 }
606}
607
608#[derive(Debug, Clone, Copy, PartialEq)]
610pub struct CreateTwoDCartesianZoneFields<'a> {
611 pub zone: TwoDCartesianZoneStruct<'a>,
613}
614
615impl<'a> ToTlv for CreateTwoDCartesianZoneFields<'a> {
616 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
617 w.start_structure(tag)?;
618 self.zone.to_tlv(w, Tag::Context(0))?;
619 w.end_container()
620 }
621}
622
623impl<'a> FromTlv<'a> for CreateTwoDCartesianZoneFields<'a> {
624 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
625 if element.value.container() != Some(ContainerKind::Structure) {
626 return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
627 }
628 let mut zone = None;
629 loop {
630 let Some(field) = reader.next_element()? else {
631 return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
632 };
633 if field.value == Value::EndOfContainer {
634 break;
635 }
636 match field.tag.context() {
637 Some(0) => zone = Some(<TwoDCartesianZoneStruct<'a>>::from_tlv(reader, &field)?),
638 _ => reader.skip_value(&field)?,
642 }
643 }
644 Ok(Self {
645 zone: zone.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
646 })
647 }
648}
649
650#[derive(Debug, Clone, Copy, PartialEq)]
652pub struct CreateTwoDCartesianZoneResponseFields {
653 pub zone_id: u16,
655}
656
657impl ToTlv for CreateTwoDCartesianZoneResponseFields {
658 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
659 w.start_structure(tag)?;
660 self.zone_id.to_tlv(w, Tag::Context(0))?;
661 w.end_container()
662 }
663}
664
665impl<'a> FromTlv<'a> for CreateTwoDCartesianZoneResponseFields {
666 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
667 if element.value.container() != Some(ContainerKind::Structure) {
668 return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
669 }
670 let mut zone_id = None;
671 loop {
672 let Some(field) = reader.next_element()? else {
673 return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
674 };
675 if field.value == Value::EndOfContainer {
676 break;
677 }
678 match field.tag.context() {
679 Some(0) => zone_id = Some(<u16>::from_tlv(reader, &field)?),
680 _ => reader.skip_value(&field)?,
684 }
685 }
686 Ok(Self {
687 zone_id: zone_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
688 })
689 }
690}
691
692#[derive(Debug, Clone, Copy, PartialEq)]
694pub struct UpdateTwoDCartesianZoneFields<'a> {
695 pub zone_id: u16,
697 pub zone: TwoDCartesianZoneStruct<'a>,
699}
700
701impl<'a> ToTlv for UpdateTwoDCartesianZoneFields<'a> {
702 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
703 w.start_structure(tag)?;
704 self.zone_id.to_tlv(w, Tag::Context(0))?;
705 self.zone.to_tlv(w, Tag::Context(1))?;
706 w.end_container()
707 }
708}
709
710impl<'a> FromTlv<'a> for UpdateTwoDCartesianZoneFields<'a> {
711 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
712 if element.value.container() != Some(ContainerKind::Structure) {
713 return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
714 }
715 let mut zone_id = None;
716 let mut zone = None;
717 loop {
718 let Some(field) = reader.next_element()? else {
719 return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
720 };
721 if field.value == Value::EndOfContainer {
722 break;
723 }
724 match field.tag.context() {
725 Some(0) => zone_id = Some(<u16>::from_tlv(reader, &field)?),
726 Some(1) => zone = Some(<TwoDCartesianZoneStruct<'a>>::from_tlv(reader, &field)?),
727 _ => reader.skip_value(&field)?,
731 }
732 }
733 Ok(Self {
734 zone_id: zone_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
735 zone: zone.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
736 })
737 }
738}
739
740#[derive(Debug, Clone, Copy, PartialEq)]
742pub struct RemoveZoneFields {
743 pub zone_id: u16,
745}
746
747impl ToTlv for RemoveZoneFields {
748 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
749 w.start_structure(tag)?;
750 self.zone_id.to_tlv(w, Tag::Context(0))?;
751 w.end_container()
752 }
753}
754
755impl<'a> FromTlv<'a> for RemoveZoneFields {
756 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
757 if element.value.container() != Some(ContainerKind::Structure) {
758 return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
759 }
760 let mut zone_id = None;
761 loop {
762 let Some(field) = reader.next_element()? else {
763 return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
764 };
765 if field.value == Value::EndOfContainer {
766 break;
767 }
768 match field.tag.context() {
769 Some(0) => zone_id = Some(<u16>::from_tlv(reader, &field)?),
770 _ => reader.skip_value(&field)?,
774 }
775 }
776 Ok(Self {
777 zone_id: zone_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
778 })
779 }
780}
781
782#[derive(Debug, Clone, Copy, PartialEq)]
784pub struct CreateOrUpdateTriggerFields {
785 pub trigger: ZoneTriggerControlStruct,
787}
788
789impl ToTlv for CreateOrUpdateTriggerFields {
790 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
791 w.start_structure(tag)?;
792 self.trigger.to_tlv(w, Tag::Context(0))?;
793 w.end_container()
794 }
795}
796
797impl<'a> FromTlv<'a> for CreateOrUpdateTriggerFields {
798 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
799 if element.value.container() != Some(ContainerKind::Structure) {
800 return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
801 }
802 let mut trigger = None;
803 loop {
804 let Some(field) = reader.next_element()? else {
805 return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
806 };
807 if field.value == Value::EndOfContainer {
808 break;
809 }
810 match field.tag.context() {
811 Some(0) => trigger = Some(<ZoneTriggerControlStruct>::from_tlv(reader, &field)?),
812 _ => reader.skip_value(&field)?,
816 }
817 }
818 Ok(Self {
819 trigger: trigger.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
820 })
821 }
822}
823
824#[derive(Debug, Clone, Copy, PartialEq)]
826pub struct RemoveTriggerFields {
827 pub zone_id: u16,
829}
830
831impl ToTlv for RemoveTriggerFields {
832 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
833 w.start_structure(tag)?;
834 self.zone_id.to_tlv(w, Tag::Context(0))?;
835 w.end_container()
836 }
837}
838
839impl<'a> FromTlv<'a> for RemoveTriggerFields {
840 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
841 if element.value.container() != Some(ContainerKind::Structure) {
842 return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
843 }
844 let mut zone_id = None;
845 loop {
846 let Some(field) = reader.next_element()? else {
847 return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
848 };
849 if field.value == Value::EndOfContainer {
850 break;
851 }
852 match field.tag.context() {
853 Some(0) => zone_id = Some(<u16>::from_tlv(reader, &field)?),
854 _ => reader.skip_value(&field)?,
858 }
859 }
860 Ok(Self {
861 zone_id: zone_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
862 })
863 }
864}
865
866pub const ATTRIBUTES: &[Attribute] = &[
868 Attribute {
869 id: 0x0000,
870 name: "MaxUserDefinedZones",
871 kind: "uint8",
872 access: Access::read_only(Privilege::View),
873 qualities: AttributeQualities::FIXED,
874 reporting: Reporting::OnChange,
875 conform: Conform {
876 clauses: &[Clause {
877 verdict: Conformance::Mandatory,
878 when: Condition::Feature(2),
879 }],
880 },
881 },
882 Attribute {
883 id: 0x0001,
884 name: "MaxZones",
885 kind: "uint8",
886 access: Access::read_only(Privilege::View),
887 qualities: AttributeQualities::FIXED,
888 reporting: Reporting::OnChange,
889 conform: Conform::MANDATORY,
890 },
891 Attribute {
892 id: 0x0002,
893 name: "Zones",
894 kind: "list[ZoneInformationStruct]",
895 access: Access::read_only(Privilege::View),
896 qualities: AttributeQualities::NON_VOLATILE,
897 reporting: Reporting::OnChange,
898 conform: Conform::MANDATORY,
899 },
900 Attribute {
901 id: 0x0003,
902 name: "Triggers",
903 kind: "list[ZoneTriggerControlStruct]",
904 access: Access::read_only(Privilege::View),
905 qualities: AttributeQualities::NON_VOLATILE,
906 reporting: Reporting::OnChange,
907 conform: Conform::MANDATORY,
908 },
909 Attribute {
910 id: 0x0004,
911 name: "SensitivityMax",
912 kind: "uint8",
913 access: Access::read_only(Privilege::View),
914 qualities: AttributeQualities::FIXED,
915 reporting: Reporting::OnChange,
916 conform: Conform::MANDATORY,
917 },
918 Attribute {
919 id: 0x0005,
920 name: "Sensitivity",
921 kind: "uint8",
922 access: Access::read_write_with(Privilege::View, Privilege::Operate),
923 qualities: AttributeQualities::NON_VOLATILE,
924 reporting: Reporting::OnChange,
925 conform: Conform {
926 clauses: &[Clause {
927 verdict: Conformance::Mandatory,
928 when: Condition::Not(&Condition::Feature(1)),
929 }],
930 },
931 },
932 Attribute {
933 id: 0x0006,
934 name: "TwoDCartesianMax",
935 kind: "TwoDCartesianVertexStruct",
936 access: Access::read_only(Privilege::View),
937 qualities: AttributeQualities::FIXED,
938 reporting: Reporting::OnChange,
939 conform: Conform {
940 clauses: &[Clause {
941 verdict: Conformance::Mandatory,
942 when: Condition::Feature(0),
943 }],
944 },
945 },
946];
947
948pub const COMMANDS: &[Command] = &[
950 Command {
951 id: 0x00,
952 name: "CreateTwoDCartesianZone",
953 to_server: true,
954 response: Some(0x01),
955 access: Access::invoke(Privilege::Manage),
956 conform: Conform {
957 clauses: &[Clause {
958 verdict: Conformance::Mandatory,
959 when: Condition::All(&[Condition::Feature(0), Condition::Feature(2)]),
960 }],
961 },
962 },
963 Command {
964 id: 0x01,
965 name: "CreateTwoDCartesianZoneResponse",
966 to_server: false,
967 response: None,
968 access: Access::invoke(Privilege::Operate),
969 conform: Conform {
970 clauses: &[Clause {
971 verdict: Conformance::Mandatory,
972 when: Condition::All(&[Condition::Feature(0), Condition::Feature(2)]),
973 }],
974 },
975 },
976 Command {
977 id: 0x02,
978 name: "UpdateTwoDCartesianZone",
979 to_server: true,
980 response: None,
981 access: Access::invoke(Privilege::Manage),
982 conform: Conform {
983 clauses: &[Clause {
984 verdict: Conformance::Mandatory,
985 when: Condition::All(&[Condition::Feature(0), Condition::Feature(2)]),
986 }],
987 },
988 },
989 Command {
990 id: 0x03,
991 name: "RemoveZone",
992 to_server: true,
993 response: None,
994 access: Access::invoke(Privilege::Manage),
995 conform: Conform {
996 clauses: &[Clause {
997 verdict: Conformance::Mandatory,
998 when: Condition::Feature(2),
999 }],
1000 },
1001 },
1002 Command {
1003 id: 0x04,
1004 name: "CreateOrUpdateTrigger",
1005 to_server: true,
1006 response: None,
1007 access: Access::invoke(Privilege::Manage),
1008 conform: Conform::MANDATORY,
1009 },
1010 Command {
1011 id: 0x05,
1012 name: "RemoveTrigger",
1013 to_server: true,
1014 response: None,
1015 access: Access::invoke(Privilege::Manage),
1016 conform: Conform::MANDATORY,
1017 },
1018];
1019
1020pub const EVENTS: &[Event] = &[
1022 Event {
1023 id: 0x00,
1024 name: "ZoneTriggered",
1025 priority: EventPriority::Info,
1026 access: Access::read_only(Privilege::View),
1027 conform: Conform::MANDATORY,
1028 },
1029 Event {
1030 id: 0x01,
1031 name: "ZoneStopped",
1032 priority: EventPriority::Info,
1033 access: Access::read_only(Privilege::View),
1034 conform: Conform::MANDATORY,
1035 },
1036];
1037
1038pub const CLUSTER: Cluster = Cluster {
1040 id: ID,
1041 name: "Zone Management",
1042 revision: REVISION,
1043 pics: "ZONEMGMT",
1044 derived_from: None,
1045 features: FEATURES,
1046 attributes: ATTRIBUTES,
1047 commands: COMMANDS,
1048 events: EVENTS,
1049};