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 = 0x0507;
28
29pub const REVISION: u16 = 1;
32
33pub const PICS: &str = "MEDIAINPUT";
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 INPUT_LIST: AttributeId = 0x00;
61 pub const CURRENT_INPUT: AttributeId = 0x01;
63}
64
65pub mod command {
67 use crate::im::CommandId;
68
69 pub const SELECT_INPUT: CommandId = 0x00;
71 pub const SHOW_INPUT_STATUS: CommandId = 0x01;
73 pub const HIDE_INPUT_STATUS: CommandId = 0x02;
75 pub const RENAME_INPUT: CommandId = 0x03;
77}
78
79#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
81#[repr(u8)]
82pub enum InputTypeEnum {
83 Internal = 0,
85 Aux = 1,
87 Coax = 2,
89 Composite = 3,
91 HDMI = 4,
93 Input = 5,
95 Line = 6,
97 Optical = 7,
99 Video = 8,
101 SCART = 9,
103 USB = 10,
105 Other = 11,
107}
108
109impl InputTypeEnum {
110 #[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 #[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#[derive(Debug, Clone, Copy, PartialEq)]
152pub struct InputInfoStruct<'a> {
153 pub index: u8,
155 pub input_type: InputTypeEnum,
157 pub name: &'a str,
159 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 _ => 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#[derive(Debug, Clone, Copy, PartialEq)]
212pub struct SelectInputFields {
213 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 _ => 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#[derive(Debug, Clone, Copy, PartialEq)]
254pub struct RenameInputFields<'a> {
255 pub index: u8,
257 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 _ => 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
300pub 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
322pub 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
363pub const EVENTS: &[Event] = &[];
365
366pub 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};