wled_json_api_library/structures/
nodes.rs

1use serde;
2use serde::{Serialize, Deserialize};
3use crate::errors::WledJsonApiError;
4use crate::structures::none_function;
5
6
7#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
8#[serde(rename_all = "camelCase")]
9pub struct Nodes {
10    pub nodes: Vec<Node>,
11}
12
13
14impl TryFrom<&str> for Nodes{
15    type Error = WledJsonApiError;
16    fn try_from(str_in: &str) -> Result<Nodes, WledJsonApiError> {
17        serde_json::from_str(str_in).map_err(|e| {WledJsonApiError::SerdeError(e)})
18    }
19}
20
21#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
22#[serde(rename_all = "camelCase")]
23pub struct Node {
24    /// Not a trick question, really just the name of the corresponding node
25    #[serde(skip_serializing_if = "Option::is_none")]
26    #[serde(default = "none_function")]
27    pub name: Option<String>,
28
29    /// 'a waste of space as we only have 5 types'
30    ///     - the WLED source code
31    ///
32    /// #define NODE_TYPE_ID_UNDEFINED        0
33    /// #define NODE_TYPE_ID_ESP8266         82 // should be 1
34    /// #define NODE_TYPE_ID_ESP32           32 // should be 2
35    /// #define NODE_TYPE_ID_ESP32S2         33 // etc
36    /// #define NODE_TYPE_ID_ESP32S3         34
37    /// #define NODE_TYPE_ID_ESP32C3         35
38    ///
39    ///
40    /// Considering the above, this field may be changed by the time you are using this
41    #[serde(skip_serializing_if = "Option::is_none")]
42    #[serde(default = "none_function")]
43    #[serde(rename = "type")]
44    pub type_field: Option<u8>,
45
46    /// Not a trick question, really just IP address
47    #[serde(skip_serializing_if = "Option::is_none")]
48    #[serde(default = "none_function")]
49    pub ip: Option<String>,
50
51    /// We have our top 4 engineers on the case, we'll know aht this is in about 3 years
52    #[serde(skip_serializing_if = "Option::is_none")]
53    #[serde(default = "none_function")]
54    pub age: Option<u8>,
55
56    /// We have our top 4 engineers on the case, we'll know aht this is in about 3 years
57    #[serde(skip_serializing_if = "Option::is_none")]
58    #[serde(default = "none_function")]
59    pub vid: Option<u32>,
60}