matter_kit/clusters/on_off.rs
1//! On/Off, cluster `0x0006` (Application Cluster §1.5).
2//!
3//! The cluster every Matter demonstration starts with, and the first one in this crate where
4//! the specification defines *behaviour* rather than a table. §1.5.7 is a state machine, and
5//! most of it is not about turning a light on:
6//!
7//! ```text
8//! OnWithTimedOff(X, Y)
9//! ┌──────┐ ──────────────────────────▶ ┌──────────┐
10//! │ Off │ │ Timed On │ OnTime ticks down
11//! └──────┘ ◀────────────────────────── └──────────┘
12//! ▲ OnTime reaches 0 │
13//! │ │ Off
14//! │ ┌─────────────┐ │
15//! └─────────│ Delayed Off │◀──────────────┘
16//! OffWaitTime → 0 └─────────────┘ OffWaitTime guards against
17//! another OnWithTimedOff
18//! ```
19//!
20//! # What the guard is for
21//!
22//! §1.5.6.5 gives the reason `OffWaitTime` exists, and it is a real room rather than a
23//! protocol abstraction: "when leaving a room, the lights are turned off but an occupancy
24//! sensor detects the leaving person and attempts to turn the lights back on". A device that
25//! ignores the guard turns the light back on behind the person who just left, every time.
26//!
27//! # Where the device comes in
28//!
29//! This is a **pattern B1** cluster: the specification owns the state machine and the
30//! application owns the light. [`OnOffHooks`] is that seam — it is told what the cluster
31//! decided, and it makes the hardware agree. Nothing here drives a pin, and nothing in a
32//! device has to reimplement §1.5.7.
33//!
34//! The descriptor is derived from the generated tables ([`OnOff::conforming`]), so a device that
35//! claims `Lighting` serves `StartUpOnOff` and one that does not cannot accidentally
36//! advertise it.
37
38use core::cell::RefCell;
39
40use crate::clusters::generated::on_off as spec_on_off;
41use crate::dm::spec::{Conforming, Optional};
42use crate::dm::{Resolved, ResolvedCommand};
43use crate::im::{ClusterHandler, ClusterId, CommandId, InteractionContext, Status, StatusIb};
44use crate::platform::{Duration, Instant};
45use crate::tlv::{ContainerKind, Tag, TlvReader, TlvWriter, Value};
46
47use super::Cluster;
48
49pub use spec_on_off::attribute::{
50 GLOBAL_SCENE_CONTROL, OFF_WAIT_TIME, ON_OFF, ON_TIME, START_UP_ON_OFF,
51};
52pub use spec_on_off::command::{
53 OFF, OFF_WITH_EFFECT, ON, ON_WITH_RECALL_GLOBAL_SCENE, ON_WITH_TIMED_OFF, TOGGLE,
54};
55pub use spec_on_off::feature;
56pub use spec_on_off::{
57 DelayedAllOffEffectVariantEnum, DyingLightEffectVariantEnum, EffectIdentifierEnum, ID,
58 OnOffControlBitmap, PICS, REVISION, StartUpOnOffEnum,
59};
60
61/// The tick §1.5.7.6.4 counts in: "the server SHALL then update these attributes every 1/10
62/// second".
63///
64/// A device polls [`OnOff::poll`] at least this often while a timer runs; less often and the
65/// light stays on past its time, which is what a user notices.
66pub const TICK: Duration = Duration::from_millis(100);
67
68/// The value §1.5.7.6.4 exempts from counting: "If the values of the OnTime and OffWaitTime
69/// attributes are both not equal to 0xFFFF" — so `0xFFFF` means "stay like this".
70pub const INDEFINITE: u16 = 0xFFFF;
71
72/// What the application does when the cluster decides the light has changed.
73///
74/// The cluster owns §1.5.7's state machine and calls this; the device owns the hardware. A
75/// hook is not asked whether it agrees — the attribute has already changed and a client may
76/// already have been told — so the only correct implementation is one that makes the world
77/// match.
78pub trait OnOffHooks {
79 /// The light is now on, or off.
80 ///
81 /// Called for every transition, however it arose: a command, a timer expiring, a startup
82 /// value being applied. Not called when a command sets the attribute to what it already
83 /// was, because §8.6's reporting would not report that either.
84 fn set(&self, on: bool);
85
86 /// §1.5.7.4's fading effect, if the device has one.
87 ///
88 /// The default ends in the same place as an ordinary Off, which is what the specification
89 /// requires of a device with no fade: the effect is "enhanced ways of fading", and a
90 /// device without any still turns off. `variant` is advisory — "If the server does not
91 /// support the given variant, it SHALL use the default variant."
92 fn off_with_effect(&self, effect: EffectIdentifierEnum, variant: u8) {
93 let _ = (effect, variant);
94 self.set(false);
95 }
96
97 /// §1.5.7.5: recall the global scene the last `OffWithEffect` stored.
98 ///
99 /// "the Scenes Management cluster server on the same endpoint SHALL recall its global
100 /// scene, updating the OnOff attribute accordingly" — so the answer is whatever the scene
101 /// says, and a device with no Scenes Management returns `true`, which is the behaviour of
102 /// a light that simply comes back on.
103 fn recall_global_scene(&self) -> bool {
104 true
105 }
106
107 /// §1.5.7.4: store the current settings as the global scene, before turning off.
108 ///
109 /// Empty by default. A device without Scenes Management has nothing to store, and
110 /// `recall_global_scene` correspondingly has nothing to restore.
111 fn store_global_scene(&self) {}
112}
113
114/// The cluster's state (§1.5.6).
115#[derive(Debug, Clone, Copy, PartialEq, Eq)]
116struct State {
117 on: bool,
118 global_scene_control: bool,
119 on_time: u16,
120 off_wait_time: u16,
121 /// When the next 1/10-second tick is due, while either timer is running.
122 next_tick: Option<Instant>,
123}
124
125/// On/Off, with the device's hooks.
126///
127/// `H` is the application. `feature_map` decides which half of the cluster exists: without
128/// `Lighting` there is no `OnTime`, no `OffWaitTime` and therefore no timed-off state machine
129/// at all, which is exactly what a plain relay wants.
130#[derive(Debug)]
131pub struct OnOff<'a, H: OnOffHooks> {
132 hooks: &'a H,
133 feature_map: u32,
134 state: RefCell<State>,
135 start_up: Option<StartUpOnOffEnum>,
136}
137
138impl<'a, H: OnOffHooks> OnOff<'a, H> {
139 /// A cluster over `hooks`, with these features.
140 ///
141 /// `start_up` is §1.5.6.6's `StartUpOnOff`: `None` means "the previous value", which is
142 /// the fallback the specification gives and the one a device implements by restoring the
143 /// persisted `OnOff` before calling [`OnOff::start`].
144 #[must_use]
145 pub fn new(hooks: &'a H, feature_map: u32, start_up: Option<StartUpOnOffEnum>) -> Self {
146 Self {
147 hooks,
148 feature_map,
149 state: RefCell::new(State {
150 on: false,
151 // §1.5.6.3: TRUE after anything that turns the device on, FALSE after
152 // `OffWithEffect`. A device that has never been told otherwise has not stored
153 // a global scene, so there is nothing for `OnWithRecallGlobalScene` to recall
154 // and the attribute starts TRUE.
155 global_scene_control: true,
156 on_time: 0,
157 off_wait_time: 0,
158 next_tick: None,
159 }),
160 start_up,
161 }
162 }
163
164 /// Whether the cluster supports the Lighting feature's timing attributes.
165 const fn lighting(&self) -> bool {
166 self.feature_map & feature::LIGHTING != 0
167 }
168
169 /// Whether the device refuses to turn on (§1.5.4).
170 const fn off_only(&self) -> bool {
171 self.feature_map & feature::OFF_ONLY != 0
172 }
173
174 /// The descriptor for an instance with these features.
175 ///
176 /// Derived from the specification's own tables, so the element set follows the feature
177 /// map: `StartUpOnOff` and its three companions appear with `Lighting` and cannot appear
178 /// without it.
179 pub fn conforming(
180 feature_map: u32,
181 optional: &Optional<'_>,
182 ) -> crate::error::Result<Conforming<5, 6, 0, 0>> {
183 Conforming::new(&spec_on_off::CLUSTER, feature_map, optional)
184 }
185
186 /// Applies §1.5.6.6's `StartUpOnOff` — what the light does when power returns.
187 ///
188 /// `previous` is the `OnOff` value the device persisted, which is what a null
189 /// `StartUpOnOff` means: "If the value is null, the OnOff attribute is set to its previous
190 /// value."
191 ///
192 /// > This behavior does not apply to reboots associated with OTA. After an OTA restart,
193 /// > the OnOff attribute SHALL return to its value prior to the restart.
194 ///
195 /// So a device restarting for an update passes `None` for `start_up` when constructing, or
196 /// simply does not call this.
197 pub fn start(&self, previous: bool) {
198 let on = match self.start_up {
199 None => previous,
200 Some(StartUpOnOffEnum::Off) => false,
201 Some(StartUpOnOffEnum::On) => true,
202 Some(StartUpOnOffEnum::Toggle) => !previous,
203 };
204 self.set(on);
205 }
206
207 /// Whether the light is on.
208 #[must_use]
209 pub fn is_on(&self) -> bool {
210 self.state.borrow().on
211 }
212
213 /// `OnTime`, in tenths of a second.
214 #[must_use]
215 pub fn on_time(&self) -> u16 {
216 self.state.borrow().on_time
217 }
218
219 /// `OffWaitTime`, in tenths of a second.
220 #[must_use]
221 pub fn off_wait_time(&self) -> u16 {
222 self.state.borrow().off_wait_time
223 }
224
225 /// `GlobalSceneControl` (§1.5.6.3).
226 #[must_use]
227 pub fn global_scene_control(&self) -> bool {
228 self.state.borrow().global_scene_control
229 }
230
231 /// Sets the state and tells the device, if anything changed.
232 fn set(&self, on: bool) {
233 let changed = {
234 let mut state = self.state.borrow_mut();
235 let changed = state.on != on;
236 state.on = on;
237 changed
238 };
239 if changed {
240 self.hooks.set(on);
241 }
242 }
243
244 /// When [`OnOff::poll`] next has something to do.
245 ///
246 /// `None` when neither timer is running, which is the ordinary case — a light that is
247 /// simply on or simply off needs no clock at all, and an intermittently connected device
248 /// can sleep.
249 #[must_use]
250 pub fn wake_at(&self) -> Option<Instant> {
251 self.state.borrow().next_tick
252 }
253
254 /// Runs §1.5.7.6.4's tenth-of-a-second update.
255 ///
256 /// Call it whenever [`OnOff::wake_at`] comes round. It catches up on missed ticks rather
257 /// than counting calls, so a device that polls late — or was asleep — still turns the
258 /// light off at the right *time* rather than the right number of wake-ups later.
259 pub fn poll(&self, now: Instant) {
260 let mut turn_off = false;
261 {
262 let mut state = self.state.borrow_mut();
263 let Some(mut due) = state.next_tick else {
264 return;
265 };
266 // "If the values of the OnTime and OffWaitTime attributes are both not equal to
267 // 0xFFFF" — either being indefinite stops the countdown entirely.
268 if state.on_time == INDEFINITE || state.off_wait_time == INDEFINITE {
269 state.next_tick = None;
270 return;
271 }
272 let mut ticks = 0u32;
273 while now >= due && ticks < MAX_CATCH_UP {
274 ticks = ticks.saturating_add(1);
275 due = due.saturating_add(TICK);
276
277 if state.on && state.on_time > 0 {
278 state.on_time = state.on_time.saturating_sub(1);
279 if state.on_time == 0 {
280 // "the server SHALL set the OffWaitTime and OnOff attributes to 0 and
281 // FALSE, respectively."
282 state.off_wait_time = 0;
283 turn_off = true;
284 state.next_tick = None;
285 break;
286 }
287 } else if !state.on && state.off_wait_time > 0 {
288 state.off_wait_time = state.off_wait_time.saturating_sub(1);
289 if state.off_wait_time == 0 {
290 // "the server SHALL terminate the update."
291 state.next_tick = None;
292 break;
293 }
294 } else {
295 // Neither timer applies in this state; nothing left to count.
296 state.next_tick = None;
297 break;
298 }
299 }
300 if state.next_tick.is_some() {
301 state.next_tick = Some(due);
302 }
303 }
304 if turn_off {
305 self.set(false);
306 }
307 }
308
309 /// Arms the tick if either timer is running and both are finite.
310 fn arm(&self, now: Instant) {
311 let mut state = self.state.borrow_mut();
312 let counting = state.on_time != INDEFINITE
313 && state.off_wait_time != INDEFINITE
314 && (state.on_time > 0 || state.off_wait_time > 0);
315 state.next_tick = counting.then(|| now.saturating_add(TICK));
316 }
317}
318
319/// How many missed ticks one `poll` catches up on.
320///
321/// A minute's worth. A device that has been asleep longer than the timer it set should finish
322/// the transition rather than spin through six hundred iterations to reach the same place, and
323/// the loop's own exit conditions get there in one step once a timer hits zero.
324const MAX_CATCH_UP: u32 = 600;
325
326impl<H: OnOffHooks> OnOff<'_, H> {
327 /// §1.5.7.1's `Off`.
328 fn command_off(&self, now: Instant) {
329 self.set(false);
330 if self.lighting() {
331 // §1.5.7.1: "the server SHALL set the OnTime attribute to 0."
332 self.state.borrow_mut().on_time = 0;
333 self.arm(now);
334 }
335 }
336
337 /// §1.5.7.2's `On`.
338 fn command_on(&self, now: Instant) {
339 self.set(true);
340 if self.lighting() {
341 let mut state = self.state.borrow_mut();
342 state.global_scene_control = true;
343 if state.on_time == 0 {
344 state.off_wait_time = 0;
345 }
346 drop(state);
347 self.arm(now);
348 }
349 }
350
351 /// §1.5.7.3's `Toggle`.
352 fn command_toggle(&self, now: Instant) {
353 if self.is_on() {
354 self.command_off(now);
355 } else {
356 self.command_on(now);
357 }
358 }
359
360 /// §1.5.7.6.4's `OnWithTimedOff`.
361 fn command_on_with_timed_off(&self, control: u8, on_time: u16, off_wait: u16, now: Instant) {
362 let accept_only_when_on = control & OnOffControlBitmap::ACCEPT_ONLY_WHEN_ON.bits() != 0;
363 // "if the AcceptOnlyWhenOn sub-field of the OnOffControl field is set to 1, and the
364 // value of the OnOff attribute is equal to FALSE, the command SHALL be discarded."
365 if accept_only_when_on && !self.is_on() {
366 return;
367 }
368
369 let turn_on = {
370 let mut state = self.state.borrow_mut();
371 // "If the value of the OffWaitTime attribute is greater than zero and the value of
372 // the OnOff attribute is equal to FALSE" — the guard of §1.5.6.5, the one that
373 // stops an occupancy sensor turning the lights back on behind the person who just
374 // left the room.
375 if state.off_wait_time > 0 && !state.on {
376 state.off_wait_time = state.off_wait_time.min(off_wait);
377 false
378 } else {
379 // "set the OnTime attribute to the maximum of the OnTime attribute and the
380 // value specified in the OnTime field" — so a second command extends the
381 // period rather than shortening it.
382 state.on_time = state.on_time.max(on_time);
383 state.off_wait_time = off_wait;
384 true
385 }
386 };
387 if turn_on {
388 self.set(true);
389 }
390 self.arm(now);
391 }
392
393 /// §1.5.7.4's `OffWithEffect`.
394 fn command_off_with_effect(&self, effect: EffectIdentifierEnum, variant: u8, now: Instant) {
395 let store = {
396 let mut state = self.state.borrow_mut();
397 let store = state.global_scene_control;
398 if store {
399 state.global_scene_control = false;
400 }
401 store
402 };
403 if store {
404 // "the server SHALL store its settings in its global scene then set the
405 // GlobalSceneControl attribute to FALSE" — in that order, because the scene must
406 // capture the state the light is *in*, not the state it is about to be in.
407 self.hooks.store_global_scene();
408 }
409 self.hooks.off_with_effect(effect, variant);
410 self.set(false);
411 if self.lighting() {
412 self.state.borrow_mut().on_time = 0;
413 self.arm(now);
414 }
415 }
416
417 /// §1.5.7.5's `OnWithRecallGlobalScene`.
418 fn command_on_with_recall_global_scene(&self, now: Instant) {
419 // "if the GlobalSceneControl attribute is equal to TRUE, the server SHALL discard the
420 // command" — there is no stored scene to recall, because nothing turned the light off
421 // with an effect.
422 if self.global_scene_control() {
423 return;
424 }
425 let on = self.hooks.recall_global_scene();
426 self.set(on);
427 let mut state = self.state.borrow_mut();
428 state.global_scene_control = true;
429 if state.on_time == 0 {
430 state.off_wait_time = 0;
431 }
432 drop(state);
433 self.arm(now);
434 }
435}
436
437/// Reads `OnWithTimedOff`'s three fields (§1.5.7.6).
438fn decode_timed_off(fields: &[u8]) -> Result<(u8, u16, u16), Status> {
439 let mut reader = TlvReader::new_in(fields, ContainerKind::Structure);
440 let element = reader
441 .next_element()
442 .map_err(|_| Status::InvalidAction)?
443 .ok_or(Status::InvalidAction)?;
444 if element.value.container() != Some(ContainerKind::Structure) {
445 return Err(Status::InvalidAction);
446 }
447 let (mut control, mut on_time, mut off_wait) = (None, None, None);
448 loop {
449 let Some(field) = reader.next_element().map_err(|_| Status::InvalidAction)? else {
450 return Err(Status::InvalidAction);
451 };
452 if field.value == Value::EndOfContainer {
453 break;
454 }
455 let value = field.unsigned().map_err(|_| Status::ConstraintError)?;
456 match field.tag.context() {
457 Some(0) => {
458 // "0 to 1": the only bit defined is `AcceptOnlyWhenOn`.
459 let bits = u8::try_from(value).map_err(|_| Status::ConstraintError)?;
460 if OnOffControlBitmap::from_bits(bits).is_none() {
461 return Err(Status::ConstraintError);
462 }
463 control = Some(bits);
464 }
465 Some(1) | Some(2) => {
466 let ticks = u16::try_from(value).map_err(|_| Status::ConstraintError)?;
467 // "max 0xFFFE" on both fields — 0xFFFF is reserved for the *attribute*'s
468 // "indefinite", and a command may not ask for it.
469 if ticks == INDEFINITE {
470 return Err(Status::ConstraintError);
471 }
472 if field.tag.context() == Some(1) {
473 on_time = Some(ticks);
474 } else {
475 off_wait = Some(ticks);
476 }
477 }
478 _ => {
479 reader
480 .skip_value(&field)
481 .map_err(|_| Status::InvalidAction)?;
482 }
483 }
484 }
485 match (control, on_time, off_wait) {
486 (Some(control), Some(on_time), Some(off_wait)) => Ok((control, on_time, off_wait)),
487 _ => Err(Status::InvalidCommand),
488 }
489}
490
491/// Reads `OffWithEffect`'s two fields (§1.5.7.4).
492fn decode_effect(fields: &[u8]) -> Result<(EffectIdentifierEnum, u8), Status> {
493 let mut reader = TlvReader::new_in(fields, ContainerKind::Structure);
494 let element = reader
495 .next_element()
496 .map_err(|_| Status::InvalidAction)?
497 .ok_or(Status::InvalidAction)?;
498 if element.value.container() != Some(ContainerKind::Structure) {
499 return Err(Status::InvalidAction);
500 }
501 let (mut effect, mut variant) = (None, None);
502 loop {
503 let Some(field) = reader.next_element().map_err(|_| Status::InvalidAction)? else {
504 return Err(Status::InvalidAction);
505 };
506 if field.value == Value::EndOfContainer {
507 break;
508 }
509 let value = u8::try_from(field.unsigned().map_err(|_| Status::ConstraintError)?)
510 .map_err(|_| Status::ConstraintError)?;
511 match field.tag.context() {
512 // "This field SHALL contain one of the non-reserved values listed in
513 // EffectIdentifierEnum" — a reserved one is `CONSTRAINT_ERROR`, not a fade the
514 // device invents.
515 Some(0) => {
516 effect =
517 Some(EffectIdentifierEnum::from_value(value).ok_or(Status::ConstraintError)?);
518 }
519 // The variant is *not* checked: "If the server does not support the given variant,
520 // it SHALL use the default variant", so an unknown one is the device's to shrug at.
521 Some(1) => variant = Some(value),
522 _ => {
523 reader
524 .skip_value(&field)
525 .map_err(|_| Status::InvalidAction)?;
526 }
527 }
528 }
529 match (effect, variant) {
530 (Some(effect), Some(variant)) => Ok((effect, variant)),
531 _ => Err(Status::InvalidCommand),
532 }
533}
534
535impl<H: OnOffHooks> ClusterHandler for OnOff<'_, H> {
536 fn read(
537 &self,
538 resolved: &Resolved<'_>,
539 _ctx: &InteractionContext<'_>,
540 w: &mut TlvWriter<'_>,
541 tag: Tag,
542 ) -> Result<(), Status> {
543 let full = |r: crate::error::Result<()>| r.map_err(|_| Status::ResourceExhausted);
544 match resolved.attribute {
545 ON_OFF => full(w.bool(tag, self.is_on())),
546 GLOBAL_SCENE_CONTROL if self.lighting() => {
547 full(w.bool(tag, self.global_scene_control()))
548 }
549 ON_TIME if self.lighting() => full(w.unsigned(tag, u64::from(self.on_time()))),
550 OFF_WAIT_TIME if self.lighting() => {
551 full(w.unsigned(tag, u64::from(self.off_wait_time())))
552 }
553 START_UP_ON_OFF if self.lighting() => match self.start_up {
554 // §1.5.6.6: null means "its previous value", which is a real answer rather
555 // than an absent one.
556 None => full(w.null(tag)),
557 Some(value) => full(w.unsigned(tag, u64::from(value.value()))),
558 },
559 _ => Err(Status::UnsupportedAttribute),
560 }
561 }
562
563 fn write(
564 &self,
565 resolved: &Resolved<'_>,
566 data: &[u8],
567 _op: crate::im::WriteOp,
568 _ctx: &InteractionContext<'_>,
569 ) -> Result<(), Status> {
570 if !self.lighting() {
571 return Err(Status::UnsupportedWrite);
572 }
573 let mut reader = TlvReader::new_in(data, ContainerKind::Structure);
574 let element = reader
575 .next_element()
576 .map_err(|_| Status::InvalidAction)?
577 .ok_or(Status::InvalidAction)?;
578 match resolved.attribute {
579 // §1.5.6.4 and §1.5.6.5: "can be written at any time, but writing a value only has
580 // effect when in the Timed On state" — so the write always lands, and the state
581 // machine decides whether it matters.
582 ON_TIME | OFF_WAIT_TIME => {
583 let value = u16::try_from(element.unsigned().map_err(|_| Status::ConstraintError)?)
584 .map_err(|_| Status::ConstraintError)?;
585 let mut state = self.state.borrow_mut();
586 if resolved.attribute == ON_TIME {
587 state.on_time = value;
588 } else {
589 state.off_wait_time = value;
590 }
591 Ok(())
592 }
593 START_UP_ON_OFF => Err(Status::UnsupportedWrite),
594 _ => Err(Status::UnsupportedWrite),
595 }
596 }
597
598 fn invoke(
599 &self,
600 resolved: &ResolvedCommand<'_>,
601 fields: Option<&[u8]>,
602 ctx: &InteractionContext<'_>,
603 _w: &mut TlvWriter<'_>,
604 _tag: Tag,
605 ) -> Result<Option<CommandId>, StatusIb> {
606 let now = ctx.now;
607 match resolved.command.id {
608 OFF => {
609 self.command_off(now);
610 Ok(None)
611 }
612 // §1.5.7.2.1 and §1.5.7.3.1: "If the OffOnly feature is supported … an
613 // UNSUPPORTED_COMMAND failure status response SHALL be sent." The descriptor
614 // already leaves these out, so this is the second line of defence — and the one
615 // that matters if a device built its descriptor by hand.
616 ON if !self.off_only() => {
617 self.command_on(now);
618 Ok(None)
619 }
620 TOGGLE if !self.off_only() => {
621 self.command_toggle(now);
622 Ok(None)
623 }
624 OFF_WITH_EFFECT if self.lighting() => {
625 let (effect, variant) =
626 decode_effect(fields.ok_or(StatusIb::from(Status::InvalidCommand))?)?;
627 self.command_off_with_effect(effect, variant, now);
628 Ok(None)
629 }
630 ON_WITH_RECALL_GLOBAL_SCENE if self.lighting() => {
631 self.command_on_with_recall_global_scene(now);
632 Ok(None)
633 }
634 ON_WITH_TIMED_OFF if self.lighting() => {
635 let (control, on_time, off_wait) =
636 decode_timed_off(fields.ok_or(StatusIb::from(Status::InvalidCommand))?)?;
637 self.command_on_with_timed_off(control, on_time, off_wait, now);
638 Ok(None)
639 }
640 _ => Err(Status::UnsupportedCommand.into()),
641 }
642 }
643}
644
645/// So a tuple of clusters can dispatch to it by id.
646impl<H: OnOffHooks> Cluster for OnOff<'_, H> {
647 const ID: ClusterId = ID;
648}