1#![allow(
5 clippy::all,
6 clippy::pedantic,
7 dead_code,
8 unreachable_pub,
9 unused_imports
10)]
11
12use crate::datatypes::SemanticTagStruct;
13use crate::error::ClusterError;
14use crate::types::Nullable;
15use matter_codec::{ContainerKind, Element, Tag, TlvReader, TlvWriter, Value};
16
17pub const CLUSTER_ID: u32 = 0x0003;
19pub const CLUSTER_REVISION: u16 = 6;
21
22pub mod command_id {
24 pub const IDENTIFY: u32 = 0x00;
26 pub const TRIGGER_EFFECT: u32 = 0x40;
28}
29
30pub mod attribute_id {
32 pub const IDENTIFY_TIME: u32 = 0x0000;
34 pub const IDENTIFY_TYPE: u32 = 0x0001;
36}
37
38#[derive(Copy, Clone, Debug, PartialEq, Eq)]
40pub enum EffectIdentifierEnum {
41 Blink,
43 Breathe,
45 Okay,
47 ChannelChange,
49 FinishEffect,
51 StopEffect,
53 Unknown(u8),
55}
56
57impl EffectIdentifierEnum {
58 #[must_use]
60 pub fn from_raw(v: u8) -> Self {
61 match v {
62 0 => Self::Blink,
63 1 => Self::Breathe,
64 2 => Self::Okay,
65 11 => Self::ChannelChange,
66 254 => Self::FinishEffect,
67 255 => Self::StopEffect,
68 other => Self::Unknown(other),
69 }
70 }
71 #[must_use]
73 pub fn to_raw(self) -> u8 {
74 match self {
75 Self::Blink => 0,
76 Self::Breathe => 1,
77 Self::Okay => 2,
78 Self::ChannelChange => 11,
79 Self::FinishEffect => 254,
80 Self::StopEffect => 255,
81 Self::Unknown(v) => v,
82 }
83 }
84}
85
86#[derive(Copy, Clone, Debug, PartialEq, Eq)]
88pub enum EffectVariantEnum {
89 Default,
91 Unknown(u8),
93}
94
95impl EffectVariantEnum {
96 #[must_use]
98 pub fn from_raw(v: u8) -> Self {
99 match v {
100 0 => Self::Default,
101 other => Self::Unknown(other),
102 }
103 }
104 #[must_use]
106 pub fn to_raw(self) -> u8 {
107 match self {
108 Self::Default => 0,
109 Self::Unknown(v) => v,
110 }
111 }
112}
113
114#[derive(Copy, Clone, Debug, PartialEq, Eq)]
116pub enum IdentifyTypeEnum {
117 None,
119 LightOutput,
121 VisibleIndicator,
123 AudibleBeep,
125 Display,
127 Actuator,
129 Unknown(u8),
131}
132
133impl IdentifyTypeEnum {
134 #[must_use]
136 pub fn from_raw(v: u8) -> Self {
137 match v {
138 0 => Self::None,
139 1 => Self::LightOutput,
140 2 => Self::VisibleIndicator,
141 3 => Self::AudibleBeep,
142 4 => Self::Display,
143 5 => Self::Actuator,
144 other => Self::Unknown(other),
145 }
146 }
147 #[must_use]
149 pub fn to_raw(self) -> u8 {
150 match self {
151 Self::None => 0,
152 Self::LightOutput => 1,
153 Self::VisibleIndicator => 2,
154 Self::AudibleBeep => 3,
155 Self::Display => 4,
156 Self::Actuator => 5,
157 Self::Unknown(v) => v,
158 }
159 }
160}
161
162pub fn decode_identify_time(tlv: &[u8]) -> Result<u16, ClusterError> {
167 let mut r = TlvReader::new(tlv);
168 match r.next()? {
169 Some(Element::Scalar {
170 value: Value::Uint(v),
171 ..
172 }) => Ok(u16::try_from(v).map_err(|_| ClusterError::InvalidLength("IdentifyTime"))?),
173 _ => Err(ClusterError::UnexpectedType {
174 context: "IdentifyTime",
175 }),
176 }
177}
178
179#[must_use]
181#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_identify_time(value: u16) -> Vec<u8> {
183 let mut buf = Vec::new();
184 let mut w = TlvWriter::new(&mut buf);
185 w.put_uint(Tag::Anonymous, u64::from(value))
186 .expect("infallible: vec writer");
187 buf
188}
189
190pub fn decode_identify_type(tlv: &[u8]) -> Result<IdentifyTypeEnum, ClusterError> {
195 let mut r = TlvReader::new(tlv);
196 match r.next()? {
197 Some(Element::Scalar {
198 value: Value::Uint(v),
199 ..
200 }) => Ok(IdentifyTypeEnum::from_raw(
201 u8::try_from(v).map_err(|_| ClusterError::InvalidLength("IdentifyType"))?,
202 )),
203 _ => Err(ClusterError::UnexpectedType {
204 context: "IdentifyType",
205 }),
206 }
207}
208
209#[must_use]
211#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_identify(identify_time: u16) -> Vec<u8> {
213 let mut buf = Vec::new();
214 let mut w = TlvWriter::new(&mut buf);
215 w.start_structure(Tag::Anonymous)
216 .expect("infallible: vec writer");
217 w.put_uint(Tag::Context(0), u64::from(identify_time))
218 .expect("infallible: vec writer");
219 w.end_container().expect("infallible: vec writer");
220 buf
221}
222
223#[must_use]
225#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_trigger_effect(
227 effect_identifier: EffectIdentifierEnum,
228 effect_variant: EffectVariantEnum,
229) -> Vec<u8> {
230 let mut buf = Vec::new();
231 let mut w = TlvWriter::new(&mut buf);
232 w.start_structure(Tag::Anonymous)
233 .expect("infallible: vec writer");
234 w.put_uint(Tag::Context(0), u64::from(effect_identifier.to_raw()))
235 .expect("infallible: vec writer");
236 w.put_uint(Tag::Context(1), u64::from(effect_variant.to_raw()))
237 .expect("infallible: vec writer");
238 w.end_container().expect("infallible: vec writer");
239 buf
240}