wled_json_api_library/structures/cfg/
mod.rs

1use serde;
2use serde::{Serialize, Deserialize};
3use crate::errors::WledJsonApiError;
4use crate::structures::cfg::cfg_ap::Ap;
5use crate::structures::cfg::cfg_def::Def;
6use crate::structures::cfg::cfg_dmx::Dmx;
7use crate::structures::cfg::cfg_eth::Eth;
8use crate::structures::cfg::cfg_hw::Hw;
9use crate::structures::cfg::cfg_id::Id;
10use crate::structures::cfg::cfg_if2::If2;
11use crate::structures::cfg::cfg_light::Light;
12use crate::structures::cfg::cfg_nw::Nw;
13use crate::structures::cfg::cfg_ol::Ol;
14use crate::structures::cfg::cfg_ota::Ota;
15use crate::structures::cfg::cfg_remote::Remote;
16use crate::structures::cfg::cfg_timers::Timers;
17use crate::structures::cfg::cfg_wifi::Wifi;
18use crate::structures::none_function;
19
20
21
22
23pub mod cfg_id;
24pub mod cfg_nw;
25pub mod cfg_ap;
26pub mod cfg_eth;
27pub mod cfg_wifi;
28pub mod cfg_hw;
29pub mod cfg_light;
30pub mod cfg_def;
31pub mod cfg_if2;
32pub mod cfg_remote;
33pub mod cfg_ol;
34pub mod cfg_timers;
35pub mod cfg_ota;
36pub mod cfg_dmx;
37
38
39#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
40#[serde(rename_all = "camelCase")]
41pub struct Cfg {
42    /// Version of WLED ("1.0.2", for example is [1, 0, 2]) but WLED source only uses 2 indices :/
43    #[serde(skip_serializing_if = "Option::is_none")]
44    #[serde(default = "none_function")]
45    pub rev: Option<Vec<u32>>,
46
47    /// Version ID; version code in format yymmddb (b = daily build) (macro called "VERSION" in wled source)
48    #[serde(skip_serializing_if = "Option::is_none")]
49    #[serde(default = "none_function")]
50    pub vid: Option<u64>,
51
52    /// identifying information
53    #[serde(skip_serializing_if = "Option::is_none")]
54    #[serde(default = "none_function")]
55    pub id: Option<Id>,
56
57    /// client mode network info
58    #[serde(skip_serializing_if = "Option::is_none")]
59    #[serde(default = "none_function")]
60    pub nw: Option<Nw>,
61
62    /// ethernet info, not included in builds with use Ethernet build flag
63    #[serde(skip_serializing_if = "Option::is_none")]
64    #[serde(default = "none_function")]
65    pub eth: Option<Eth>,
66
67    /// Access point info
68    #[serde(skip_serializing_if = "Option::is_none")]
69    #[serde(default = "none_function")]
70    pub ap: Option<Ap>,
71
72    /// literally just "sleep" whatever the fuck it meansa
73    #[serde(skip_serializing_if = "Option::is_none")]
74    #[serde(default = "none_function")]
75    pub wifi: Option<Wifi>,
76
77    /// hardware info
78    #[serde(skip_serializing_if = "Option::is_none")]
79    #[serde(default = "none_function")]
80    pub hw: Option<Hw>,
81
82    /// light info
83    #[serde(skip_serializing_if = "Option::is_none")]
84    #[serde(default = "none_function")]
85    pub light: Option<Light>,
86
87    /// defaults
88    #[serde(skip_serializing_if = "Option::is_none")]
89    #[serde(default = "none_function")]
90    pub def: Option<Def>,
91
92    /// Iterface info
93    #[serde(skip_serializing_if = "Option::is_none")]
94    #[serde(default = "none_function")]
95    #[serde(rename = "if")]
96    pub if_field: Option<If2>,
97
98    /// Remote info
99    #[serde(skip_serializing_if = "Option::is_none")]
100    #[serde(default = "none_function")]
101    pub remote: Option<Remote>,
102
103    /// Analog clock stuff
104    #[serde(skip_serializing_if = "Option::is_none")]
105    #[serde(default = "none_function")]
106    pub ol: Option<Ol>,
107
108    /// timer settings
109    #[serde(skip_serializing_if = "Option::is_none")]
110    #[serde(default = "none_function")]
111    pub timers: Option<Timers>,
112
113    /// Over the air update settings
114    #[serde(skip_serializing_if = "Option::is_none")]
115    #[serde(default = "none_function")]
116    pub ota: Option<Ota>,
117
118    /// Dmx setting. build-dependant
119    #[serde(skip_serializing_if = "Option::is_none")]
120    #[serde(default = "none_function")]
121    pub dmx: Option<Dmx>,
122
123    /// usermod settings. this depends on the mod, so I wont even touch this.
124    #[serde(skip_serializing_if = "Option::is_none")]
125    #[serde(default = "none_function")]
126    pub um: Option<serde_json::Value>,
127}
128
129
130impl TryFrom<&str> for Cfg{
131    type Error = WledJsonApiError;
132    fn try_from(str_in: &str) -> Result<Cfg, WledJsonApiError> {
133        serde_json::from_str(str_in).map_err(|e| {WledJsonApiError::SerdeError(e)})
134    }
135}
136
137impl TryInto<String> for &Cfg{
138    type Error = WledJsonApiError;
139    fn try_into(self) -> Result<String, WledJsonApiError> {
140        serde_json::to_string(self).map_err(|e| {WledJsonApiError::SerdeError(e)})
141    }
142}