matter_kit/clusters/generated/
audio_output.rs1#![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 = 0x050B;
28
29pub const REVISION: u16 = 1;
32
33pub const PICS: &str = "AUDIOOUTPUT";
35
36pub mod feature {
41 pub const NAME_UPDATES: u32 = 1 << 0;
45}
46
47pub const FEATURES: &[Feature] = &[Feature {
49 bit: 0,
50 code: "NU",
51 name: "NameUpdates",
52 conform: Conform::OPTIONAL,
53}];
54
55pub mod attribute {
57 use crate::im::AttributeId;
58
59 pub const OUTPUT_LIST: AttributeId = 0x00;
61 pub const CURRENT_OUTPUT: AttributeId = 0x01;
63}
64
65pub mod command {
67 use crate::im::CommandId;
68
69 pub const SELECT_OUTPUT: CommandId = 0x00;
71 pub const RENAME_OUTPUT: CommandId = 0x01;
73}
74
75#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
77#[repr(u8)]
78pub enum OutputTypeEnum {
79 HDMI = 0,
81 BT = 1,
83 Optical = 2,
85 Headphone = 3,
87 Internal = 4,
89 Other = 5,
91}
92
93impl OutputTypeEnum {
94 #[must_use]
96 pub const fn from_value(value: u8) -> Option<Self> {
97 match value {
98 0 => Some(Self::HDMI),
99 1 => Some(Self::BT),
100 2 => Some(Self::Optical),
101 3 => Some(Self::Headphone),
102 4 => Some(Self::Internal),
103 5 => Some(Self::Other),
104 _ => None,
105 }
106 }
107
108 #[must_use]
110 pub const fn value(self) -> u8 {
111 self as u8
112 }
113}
114
115impl ToTlv for OutputTypeEnum {
116 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
117 self.value().to_tlv(w, tag)
118 }
119}
120
121impl<'a> FromTlv<'a> for OutputTypeEnum {
122 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
123 let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
124 Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
125 }
126}
127
128#[derive(Debug, Clone, Copy, PartialEq)]
130pub struct OutputInfoStruct<'a> {
131 pub index: u8,
133 pub output_type: OutputTypeEnum,
135 pub name: &'a str,
137}
138
139impl<'a> ToTlv for OutputInfoStruct<'a> {
140 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
141 w.start_structure(tag)?;
142 self.index.to_tlv(w, Tag::Context(0))?;
143 self.output_type.to_tlv(w, Tag::Context(1))?;
144 self.name.to_tlv(w, Tag::Context(2))?;
145 w.end_container()
146 }
147}
148
149impl<'a> FromTlv<'a> for OutputInfoStruct<'a> {
150 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
151 if element.value.container() != Some(ContainerKind::Structure) {
152 return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
153 }
154 let mut index = None;
155 let mut output_type = None;
156 let mut name = None;
157 loop {
158 let Some(field) = reader.next_element()? else {
159 return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
160 };
161 if field.value == Value::EndOfContainer {
162 break;
163 }
164 match field.tag.context() {
165 Some(0) => index = Some(<u8>::from_tlv(reader, &field)?),
166 Some(1) => output_type = Some(<OutputTypeEnum>::from_tlv(reader, &field)?),
167 Some(2) => name = Some(<&'a str>::from_tlv(reader, &field)?),
168 _ => reader.skip_value(&field)?,
172 }
173 }
174 Ok(Self {
175 index: index.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
176 output_type: output_type.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
177 name: name.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
178 })
179 }
180}
181
182#[derive(Debug, Clone, Copy, PartialEq)]
184pub struct SelectOutputFields {
185 pub index: u8,
187}
188
189impl ToTlv for SelectOutputFields {
190 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
191 w.start_structure(tag)?;
192 self.index.to_tlv(w, Tag::Context(0))?;
193 w.end_container()
194 }
195}
196
197impl<'a> FromTlv<'a> for SelectOutputFields {
198 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
199 if element.value.container() != Some(ContainerKind::Structure) {
200 return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
201 }
202 let mut index = None;
203 loop {
204 let Some(field) = reader.next_element()? else {
205 return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
206 };
207 if field.value == Value::EndOfContainer {
208 break;
209 }
210 match field.tag.context() {
211 Some(0) => index = Some(<u8>::from_tlv(reader, &field)?),
212 _ => reader.skip_value(&field)?,
216 }
217 }
218 Ok(Self {
219 index: index.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
220 })
221 }
222}
223
224#[derive(Debug, Clone, Copy, PartialEq)]
226pub struct RenameOutputFields<'a> {
227 pub index: u8,
229 pub name: &'a str,
231}
232
233impl<'a> ToTlv for RenameOutputFields<'a> {
234 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
235 w.start_structure(tag)?;
236 self.index.to_tlv(w, Tag::Context(0))?;
237 self.name.to_tlv(w, Tag::Context(1))?;
238 w.end_container()
239 }
240}
241
242impl<'a> FromTlv<'a> for RenameOutputFields<'a> {
243 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
244 if element.value.container() != Some(ContainerKind::Structure) {
245 return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
246 }
247 let mut index = None;
248 let mut name = None;
249 loop {
250 let Some(field) = reader.next_element()? else {
251 return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
252 };
253 if field.value == Value::EndOfContainer {
254 break;
255 }
256 match field.tag.context() {
257 Some(0) => index = Some(<u8>::from_tlv(reader, &field)?),
258 Some(1) => name = Some(<&'a str>::from_tlv(reader, &field)?),
259 _ => reader.skip_value(&field)?,
263 }
264 }
265 Ok(Self {
266 index: index.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
267 name: name.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
268 })
269 }
270}
271
272pub const ATTRIBUTES: &[Attribute] = &[
274 Attribute {
275 id: 0x0000,
276 name: "OutputList",
277 kind: "list[OutputInfoStruct]",
278 access: Access::read_only(Privilege::View),
279 qualities: AttributeQualities::empty(),
280 reporting: Reporting::OnChange,
281 conform: Conform::MANDATORY,
282 },
283 Attribute {
284 id: 0x0001,
285 name: "CurrentOutput",
286 kind: "uint8",
287 access: Access::read_only(Privilege::View),
288 qualities: AttributeQualities::empty(),
289 reporting: Reporting::OnChange,
290 conform: Conform::MANDATORY,
291 },
292];
293
294pub const COMMANDS: &[Command] = &[
296 Command {
297 id: 0x00,
298 name: "SelectOutput",
299 to_server: true,
300 response: None,
301 access: Access::invoke(Privilege::Operate),
302 conform: Conform::MANDATORY,
303 },
304 Command {
305 id: 0x01,
306 name: "RenameOutput",
307 to_server: true,
308 response: None,
309 access: Access::invoke(Privilege::Manage),
310 conform: Conform {
311 clauses: &[Clause {
312 verdict: Conformance::Mandatory,
313 when: Condition::Feature(0),
314 }],
315 },
316 },
317];
318
319pub const EVENTS: &[Event] = &[];
321
322pub const CLUSTER: Cluster = Cluster {
324 id: ID,
325 name: "Audio Output",
326 revision: REVISION,
327 pics: "AUDIOOUTPUT",
328 derived_from: None,
329 features: FEATURES,
330 attributes: ATTRIBUTES,
331 commands: COMMANDS,
332 events: EVENTS,
333};