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 = 0x003B;
28
29pub const REVISION: u16 = 2;
32
33pub const PICS: &str = "SWTCH";
35
36pub mod feature {
41 pub const LATCHING_SWITCH: u32 = 1 << 0;
45 pub const MOMENTARY_SWITCH: u32 = 1 << 1;
49 pub const MOMENTARY_SWITCH_RELEASE: u32 = 1 << 2;
53 pub const MOMENTARY_SWITCH_LONG_PRESS: u32 = 1 << 3;
57 pub const MOMENTARY_SWITCH_MULTI_PRESS: u32 = 1 << 4;
61 pub const ACTION_SWITCH: u32 = 1 << 5;
65}
66
67pub const FEATURES: &[Feature] = &[
69 Feature {
70 bit: 0,
71 code: "LS",
72 name: "LatchingSwitch",
73 conform: Conform::OPTIONAL,
74 },
75 Feature {
76 bit: 1,
77 code: "MS",
78 name: "MomentarySwitch",
79 conform: Conform::OPTIONAL,
80 },
81 Feature {
82 bit: 2,
83 code: "MSR",
84 name: "MomentarySwitchRelease",
85 conform: Conform {
86 clauses: &[Clause {
87 verdict: Conformance::Optional,
88 when: Condition::All(&[
89 Condition::Feature(1),
90 Condition::Not(&Condition::Feature(5)),
91 ]),
92 }],
93 },
94 },
95 Feature {
96 bit: 3,
97 code: "MSL",
98 name: "MomentarySwitchLongPress",
99 conform: Conform {
100 clauses: &[Clause {
101 verdict: Conformance::Optional,
102 when: Condition::All(&[
103 Condition::Feature(1),
104 Condition::Any(&[Condition::Feature(2), Condition::Feature(5)]),
105 ]),
106 }],
107 },
108 },
109 Feature {
110 bit: 4,
111 code: "MSM",
112 name: "MomentarySwitchMultiPress",
113 conform: Conform {
114 clauses: &[
115 Clause {
116 verdict: Conformance::Mandatory,
117 when: Condition::Feature(5),
118 },
119 Clause {
120 verdict: Conformance::Optional,
121 when: Condition::All(&[Condition::Feature(1), Condition::Feature(2)]),
122 },
123 ],
124 },
125 },
126 Feature {
127 bit: 5,
128 code: "AS",
129 name: "ActionSwitch",
130 conform: Conform {
131 clauses: &[Clause {
132 verdict: Conformance::Optional,
133 when: Condition::Feature(1),
134 }],
135 },
136 },
137];
138
139pub mod attribute {
141 use crate::im::AttributeId;
142
143 pub const NUMBER_OF_POSITIONS: AttributeId = 0x00;
145 pub const CURRENT_POSITION: AttributeId = 0x01;
147 pub const MULTI_PRESS_MAX: AttributeId = 0x02;
149}
150
151pub mod event {
153 use crate::im::EventId;
154
155 pub const SWITCH_LATCHED: EventId = 0x00;
157 pub const INITIAL_PRESS: EventId = 0x01;
159 pub const LONG_PRESS: EventId = 0x02;
161 pub const SHORT_RELEASE: EventId = 0x03;
163 pub const LONG_RELEASE: EventId = 0x04;
165 pub const MULTI_PRESS_ONGOING: EventId = 0x05;
167 pub const MULTI_PRESS_COMPLETE: EventId = 0x06;
169}
170
171pub const ATTRIBUTES: &[Attribute] = &[
173 Attribute {
174 id: 0x0000,
175 name: "NumberOfPositions",
176 kind: "uint8",
177 access: Access::read_only(Privilege::View),
178 qualities: AttributeQualities::FIXED,
179 reporting: Reporting::OnChange,
180 conform: Conform::MANDATORY,
181 },
182 Attribute {
183 id: 0x0001,
184 name: "CurrentPosition",
185 kind: "uint8",
186 access: Access::read_only(Privilege::View),
187 qualities: AttributeQualities::NON_VOLATILE,
188 reporting: Reporting::OnChange,
189 conform: Conform::MANDATORY,
190 },
191 Attribute {
192 id: 0x0002,
193 name: "MultiPressMax",
194 kind: "uint8",
195 access: Access::read_only(Privilege::View),
196 qualities: AttributeQualities::FIXED,
197 reporting: Reporting::OnChange,
198 conform: Conform {
199 clauses: &[Clause {
200 verdict: Conformance::Mandatory,
201 when: Condition::Feature(4),
202 }],
203 },
204 },
205];
206
207pub const COMMANDS: &[Command] = &[];
209
210pub const EVENTS: &[Event] = &[
212 Event {
213 id: 0x00,
214 name: "SwitchLatched",
215 priority: EventPriority::Info,
216 access: Access::read_only(Privilege::View),
217 conform: Conform {
218 clauses: &[Clause {
219 verdict: Conformance::Mandatory,
220 when: Condition::Feature(0),
221 }],
222 },
223 },
224 Event {
225 id: 0x01,
226 name: "InitialPress",
227 priority: EventPriority::Info,
228 access: Access::read_only(Privilege::View),
229 conform: Conform {
230 clauses: &[Clause {
231 verdict: Conformance::Mandatory,
232 when: Condition::Feature(1),
233 }],
234 },
235 },
236 Event {
237 id: 0x02,
238 name: "LongPress",
239 priority: EventPriority::Info,
240 access: Access::read_only(Privilege::View),
241 conform: Conform {
242 clauses: &[Clause {
243 verdict: Conformance::Mandatory,
244 when: Condition::Feature(3),
245 }],
246 },
247 },
248 Event {
249 id: 0x03,
250 name: "ShortRelease",
251 priority: EventPriority::Info,
252 access: Access::read_only(Privilege::View),
253 conform: Conform {
254 clauses: &[Clause {
255 verdict: Conformance::Mandatory,
256 when: Condition::Feature(2),
257 }],
258 },
259 },
260 Event {
261 id: 0x04,
262 name: "LongRelease",
263 priority: EventPriority::Info,
264 access: Access::read_only(Privilege::View),
265 conform: Conform {
266 clauses: &[Clause {
267 verdict: Conformance::Mandatory,
268 when: Condition::Feature(3),
269 }],
270 },
271 },
272 Event {
273 id: 0x05,
274 name: "MultiPressOngoing",
275 priority: EventPriority::Info,
276 access: Access::read_only(Privilege::View),
277 conform: Conform {
278 clauses: &[Clause {
279 verdict: Conformance::Mandatory,
280 when: Condition::All(&[
281 Condition::Feature(4),
282 Condition::Not(&Condition::Feature(5)),
283 ]),
284 }],
285 },
286 },
287 Event {
288 id: 0x06,
289 name: "MultiPressComplete",
290 priority: EventPriority::Info,
291 access: Access::read_only(Privilege::View),
292 conform: Conform {
293 clauses: &[Clause {
294 verdict: Conformance::Mandatory,
295 when: Condition::Feature(4),
296 }],
297 },
298 },
299];
300
301pub const CLUSTER: Cluster = Cluster {
303 id: ID,
304 name: "Switch",
305 revision: REVISION,
306 pics: "SWTCH",
307 derived_from: None,
308 features: FEATURES,
309 attributes: ATTRIBUTES,
310 commands: COMMANDS,
311 events: EVENTS,
312};