Skip to main content

matter_kit/clusters/generated/
media_input.rs

1// Generated by `cargo xtask` from the CSA data model 1.6. Do not edit.
2//
3// Media Input — cluster 0x0507.
4//
5// Regenerate with `cargo xtask clusters --dm <checkout>/data_model/1.6`; `cargo xtask check`
6// is the CI gate that keeps this file honest. The XML itself is not vendored here — it
7// carries the CSA's own copyright notice and is not redistributable.
8
9//! Media Input (cluster `0x0507`, revision 1).
10//!
11//! 6 identifiers, 1 feature bits, and the specification's own conformance for
12//! every element. `CLUSTER` is the whole table.
13
14#![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
26/// The cluster id.
27pub const ID: ClusterId = 0x0507;
28
29/// The highest revision the specification's history defines — what `ClusterRevision`
30/// must report (Core §7.13.1).
31pub const REVISION: u16 = 1;
32
33/// The PICS code, which a certification declaration names the cluster by.
34pub const PICS: &str = "MEDIAINPUT";
35
36/// The `FeatureMap` bits (Core §7.13.2).
37///
38/// A feature has conformance of its own: a device may not claim one the
39/// specification forbids it alongside another.
40pub mod feature {
41    /// Supports updates to the input names
42    ///
43    /// Code `NU`, bit 0.
44    pub const NAME_UPDATES: u32 = 1 << 0;
45}
46
47/// Every feature bit, with its conformance.
48pub const FEATURES: &[Feature] = &[Feature {
49    bit: 0,
50    code: "NU",
51    name: "NameUpdates",
52    conform: Conform::OPTIONAL,
53}];
54
55/// The attribute ids.
56pub mod attribute {
57    use crate::im::AttributeId;
58
59    /// `InputList`.
60    pub const INPUT_LIST: AttributeId = 0x00;
61    /// `CurrentInput`.
62    pub const CURRENT_INPUT: AttributeId = 0x01;
63}
64
65/// The command ids.
66pub mod command {
67    use crate::im::CommandId;
68
69    /// `SelectInput`.
70    pub const SELECT_INPUT: CommandId = 0x00;
71    /// `ShowInputStatus`.
72    pub const SHOW_INPUT_STATUS: CommandId = 0x01;
73    /// `HideInputStatus`.
74    pub const HIDE_INPUT_STATUS: CommandId = 0x02;
75    /// `RenameInput`.
76    pub const RENAME_INPUT: CommandId = 0x03;
77}
78
79/// `InputTypeEnum`.
80#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
81#[repr(u8)]
82pub enum InputTypeEnum {
83    /// Indicates content not coming from a physical input.
84    Internal = 0,
85    /// `Aux`.
86    Aux = 1,
87    /// `Coax`.
88    Coax = 2,
89    /// `Composite`.
90    Composite = 3,
91    /// `HDMI`.
92    HDMI = 4,
93    /// `Input`.
94    Input = 5,
95    /// `Line`.
96    Line = 6,
97    /// `Optical`.
98    Optical = 7,
99    /// `Video`.
100    Video = 8,
101    /// `SCART`.
102    SCART = 9,
103    /// `USB`.
104    USB = 10,
105    /// `Other`.
106    Other = 11,
107}
108
109impl InputTypeEnum {
110    /// Reads a wire value, or `None` for one this revision does not define.
111    #[must_use]
112    pub const fn from_value(value: u8) -> Option<Self> {
113        match value {
114            0 => Some(Self::Internal),
115            1 => Some(Self::Aux),
116            2 => Some(Self::Coax),
117            3 => Some(Self::Composite),
118            4 => Some(Self::HDMI),
119            5 => Some(Self::Input),
120            6 => Some(Self::Line),
121            7 => Some(Self::Optical),
122            8 => Some(Self::Video),
123            9 => Some(Self::SCART),
124            10 => Some(Self::USB),
125            11 => Some(Self::Other),
126            _ => None,
127        }
128    }
129
130    /// Its wire value.
131    #[must_use]
132    pub const fn value(self) -> u8 {
133        self as u8
134    }
135}
136
137impl ToTlv for InputTypeEnum {
138    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
139        self.value().to_tlv(w, tag)
140    }
141}
142
143impl<'a> FromTlv<'a> for InputTypeEnum {
144    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
145        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
146        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
147    }
148}
149
150/// `InputInfoStruct`.
151#[derive(Debug, Clone, Copy, PartialEq)]
152pub struct InputInfoStruct<'a> {
153    /// `Index`, field 0.
154    pub index: u8,
155    /// `InputType`, field 1.
156    pub input_type: InputTypeEnum,
157    /// `Name`, field 2.
158    pub name: &'a str,
159    /// `Description`, field 3.
160    pub description: &'a str,
161}
162
163impl<'a> ToTlv for InputInfoStruct<'a> {
164    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
165        w.start_structure(tag)?;
166        self.index.to_tlv(w, Tag::Context(0))?;
167        self.input_type.to_tlv(w, Tag::Context(1))?;
168        self.name.to_tlv(w, Tag::Context(2))?;
169        self.description.to_tlv(w, Tag::Context(3))?;
170        w.end_container()
171    }
172}
173
174impl<'a> FromTlv<'a> for InputInfoStruct<'a> {
175    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
176        if element.value.container() != Some(ContainerKind::Structure) {
177            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
178        }
179        let mut index = None;
180        let mut input_type = None;
181        let mut name = None;
182        let mut description = None;
183        loop {
184            let Some(field) = reader.next_element()? else {
185                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
186            };
187            if field.value == Value::EndOfContainer {
188                break;
189            }
190            match field.tag.context() {
191                Some(0) => index = Some(<u8>::from_tlv(reader, &field)?),
192                Some(1) => input_type = Some(<InputTypeEnum>::from_tlv(reader, &field)?),
193                Some(2) => name = Some(<&'a str>::from_tlv(reader, &field)?),
194                Some(3) => description = Some(<&'a str>::from_tlv(reader, &field)?),
195                // A field this revision does not define. §7.19.2: a receiver
196                // ignores what it does not know rather than refusing the whole
197                // structure, which is what lets a newer peer talk to an older one.
198                _ => reader.skip_value(&field)?,
199            }
200        }
201        Ok(Self {
202            index: index.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
203            input_type: input_type.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
204            name: name.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
205            description: description.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
206        })
207    }
208}
209
210/// The fields of `SelectInput` (command `0x00`).
211#[derive(Debug, Clone, Copy, PartialEq)]
212pub struct SelectInputFields {
213    /// `Index`, field 0.
214    pub index: u8,
215}
216
217impl ToTlv for SelectInputFields {
218    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
219        w.start_structure(tag)?;
220        self.index.to_tlv(w, Tag::Context(0))?;
221        w.end_container()
222    }
223}
224
225impl<'a> FromTlv<'a> for SelectInputFields {
226    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
227        if element.value.container() != Some(ContainerKind::Structure) {
228            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
229        }
230        let mut index = None;
231        loop {
232            let Some(field) = reader.next_element()? else {
233                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
234            };
235            if field.value == Value::EndOfContainer {
236                break;
237            }
238            match field.tag.context() {
239                Some(0) => index = Some(<u8>::from_tlv(reader, &field)?),
240                // A field this revision does not define. §7.19.2: a receiver
241                // ignores what it does not know rather than refusing the whole
242                // structure, which is what lets a newer peer talk to an older one.
243                _ => reader.skip_value(&field)?,
244            }
245        }
246        Ok(Self {
247            index: index.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
248        })
249    }
250}
251
252/// The fields of `RenameInput` (command `0x03`).
253#[derive(Debug, Clone, Copy, PartialEq)]
254pub struct RenameInputFields<'a> {
255    /// `Index`, field 0.
256    pub index: u8,
257    /// `Name`, field 1.
258    pub name: &'a str,
259}
260
261impl<'a> ToTlv for RenameInputFields<'a> {
262    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
263        w.start_structure(tag)?;
264        self.index.to_tlv(w, Tag::Context(0))?;
265        self.name.to_tlv(w, Tag::Context(1))?;
266        w.end_container()
267    }
268}
269
270impl<'a> FromTlv<'a> for RenameInputFields<'a> {
271    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
272        if element.value.container() != Some(ContainerKind::Structure) {
273            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
274        }
275        let mut index = None;
276        let mut name = None;
277        loop {
278            let Some(field) = reader.next_element()? else {
279                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
280            };
281            if field.value == Value::EndOfContainer {
282                break;
283            }
284            match field.tag.context() {
285                Some(0) => index = Some(<u8>::from_tlv(reader, &field)?),
286                Some(1) => name = Some(<&'a str>::from_tlv(reader, &field)?),
287                // A field this revision does not define. §7.19.2: a receiver
288                // ignores what it does not know rather than refusing the whole
289                // structure, which is what lets a newer peer talk to an older one.
290                _ => reader.skip_value(&field)?,
291            }
292        }
293        Ok(Self {
294            index: index.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
295            name: name.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
296        })
297    }
298}
299
300/// Every attribute the specification defines, with its conformance.
301pub const ATTRIBUTES: &[Attribute] = &[
302    Attribute {
303        id: 0x0000,
304        name: "InputList",
305        kind: "list[InputInfoStruct]",
306        access: Access::read_only(Privilege::View),
307        qualities: AttributeQualities::empty(),
308        reporting: Reporting::OnChange,
309        conform: Conform::MANDATORY,
310    },
311    Attribute {
312        id: 0x0001,
313        name: "CurrentInput",
314        kind: "uint8",
315        access: Access::read_only(Privilege::View),
316        qualities: AttributeQualities::empty(),
317        reporting: Reporting::OnChange,
318        conform: Conform::MANDATORY,
319    },
320];
321
322/// Every command, with its conformance.
323pub const COMMANDS: &[Command] = &[
324    Command {
325        id: 0x00,
326        name: "SelectInput",
327        to_server: true,
328        response: None,
329        access: Access::invoke(Privilege::Operate),
330        conform: Conform::MANDATORY,
331    },
332    Command {
333        id: 0x01,
334        name: "ShowInputStatus",
335        to_server: true,
336        response: None,
337        access: Access::invoke(Privilege::Operate),
338        conform: Conform::MANDATORY,
339    },
340    Command {
341        id: 0x02,
342        name: "HideInputStatus",
343        to_server: true,
344        response: None,
345        access: Access::invoke(Privilege::Operate),
346        conform: Conform::MANDATORY,
347    },
348    Command {
349        id: 0x03,
350        name: "RenameInput",
351        to_server: true,
352        response: None,
353        access: Access::invoke(Privilege::Manage),
354        conform: Conform {
355            clauses: &[Clause {
356                verdict: Conformance::Mandatory,
357                when: Condition::Feature(0),
358            }],
359        },
360    },
361];
362
363/// Every event, with its conformance.
364pub const EVENTS: &[Event] = &[];
365
366/// The whole cluster, as the specification defines it.
367pub const CLUSTER: Cluster = Cluster {
368    id: ID,
369    name: "Media Input",
370    revision: REVISION,
371    pics: "MEDIAINPUT",
372    derived_from: None,
373    features: FEATURES,
374    attributes: ATTRIBUTES,
375    commands: COMMANDS,
376    events: EVENTS,
377};