wled_json_api_library/structures/cfg/
cfg_timers.rs

1use serde;
2use serde::{Serialize, Deserialize};
3use crate::structures::none_function;
4use serde_aux_ext::field_attributes::deserialize_option_bool_from_anything;
5
6
7#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
8#[serde(rename_all = "camelCase")]
9pub struct Timers {
10
11    /// Countdown
12    #[serde(skip_serializing_if = "Option::is_none")]
13    #[serde(default = "none_function")]
14    pub cntdwn: Option<Cntdwn>,
15
16    /// Countdown mode; Clock will count down towards date
17    #[serde(skip_serializing_if = "Option::is_none")]
18    #[serde(default = "none_function")]
19    pub ins: Option<Vec<Ins>>,
20}
21
22#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
23#[serde(rename_all = "camelCase")]
24pub struct Cntdwn {
25
26    /// The time that the countdown is counting down towards.
27    #[serde(skip_serializing_if = "Option::is_none")]
28    #[serde(default = "none_function")]
29    pub goal: Option<Goal>,
30
31    /// Macro (presumably this is executed on when countdown reaches goal
32    #[serde(skip_serializing_if = "Option::is_none")]
33    #[serde(default = "none_function")]
34    #[serde(rename = "macro")]
35    pub macro_field: Option<u8>,
36}
37
38/// You can figure this one out, its a date time
39#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
40#[serde(rename_all = "camelCase")]
41pub struct Goal {
42    #[serde(rename = "0")]
43    pub year: u8,
44    #[serde(rename = "1")]
45    pub month: u8,
46    #[serde(rename = "2")]
47    pub day: u8,
48    #[serde(rename = "3")]
49    pub hour: u8,
50    #[serde(rename = "4")]
51    pub minute: u8,
52    #[serde(rename = "5")]
53    pub second: u8,
54}
55
56#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
57#[serde(rename_all = "camelCase")]
58pub struct Ins {
59    /// enabled?
60    #[serde(deserialize_with = "deserialize_option_bool_from_anything")]
61    #[serde(skip_serializing_if = "Option::is_none")]
62    #[serde(default = "none_function")]
63    pub en: Option<bool>,
64
65    /// hour, I don't think this one needs much explaining
66    #[serde(skip_serializing_if = "Option::is_none")]
67    #[serde(default = "none_function")]
68    pub hour: Option<u8>,
69
70    /// minute, I don't think this one needs much explaining
71    #[serde(skip_serializing_if = "Option::is_none")]
72    #[serde(default = "none_function")]
73    pub min: Option<i8>,
74
75    /// Macro to execute when triggered
76    #[serde(skip_serializing_if = "Option::is_none")]
77    #[serde(default = "none_function")]
78    #[serde(rename = "macro")]
79    pub macro_field: Option<u8>,
80
81    /// Day and month that this timer turns on every year
82    #[serde(skip_serializing_if = "Option::is_none")]
83    #[serde(default = "none_function")]
84    pub start: Option<MonthDay>,
85
86    /// Day and month that this timer turns off every year
87    #[serde(skip_serializing_if = "Option::is_none")]
88    #[serde(default = "none_function")]
89    pub end: Option<MonthDay>,
90}
91
92#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
93#[serde(rename_all = "camelCase")]
94pub struct MonthDay {
95
96    /// the month (actually 4 bits, but cope)
97    #[serde(skip_serializing_if = "Option::is_none")]
98    #[serde(default = "none_function")]
99    pub mon: Option<u8>,
100
101    /// Day and month that this timer turns off every year
102    #[serde(skip_serializing_if = "Option::is_none")]
103    #[serde(default = "none_function")]
104    pub day: Option<u8>,
105}