1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
use crate::utils::request::deserialize_bool;
use serde::{Deserialize, Serialize};

// ------------------------
// Structs for the Govee API
// ------------------------

#[derive(Debug, Deserialize, Serialize)]
pub struct ApiResponseGoveeDeviceState {
    code: i16,
    message: String,
    pub data: Option<GoveeDataDeviceStatus>,
}

#[derive(Debug, Deserialize, Serialize)]
pub struct GoveeDataDeviceStatus {
    pub device: String,
    pub model: String,
    pub properties: Vec<GoveeDeviceProperty>,
}

#[derive(Debug, Deserialize, Serialize, PartialEq)]
pub enum GoveeDeviceProperty {
    #[serde(rename = "online")]
    #[serde(deserialize_with = "deserialize_bool")]
    // Online can be a boolean or a string
    Online(bool),
    #[serde(rename = "powerState")]
    PowerState(String),
    #[serde(rename = "brightness")]
    Brightness(i16),
    #[serde(rename = "color")]
    Color(Color),
    #[serde(rename = "colorTem")]
    ColorTem(i16),
    #[serde(rename = "colorTemInKelvin")]
    ColorTemInKelvin(i16),
}

#[derive(Debug, Deserialize, Serialize, PartialEq)]
pub struct Color {
    r: u8,
    g: u8,
    b: u8,
}

#[derive(Debug, Deserialize, Serialize)]
pub struct ApiResponseGoveeDevices {
    code: i16,
    message: String,
    pub data: Option<GoveeData>,
}

#[derive(Debug, Deserialize, Serialize)]
pub struct ApiResponseGoveeAppliances {
    code: i16,
    message: String,
    pub data: Option<GoveeData>,
}

#[derive(Debug, Deserialize, Serialize)]
pub struct GoveeData {
    pub devices: Vec<GoveeDevice>,
}

#[derive(Debug, Deserialize, Serialize)]
#[allow(non_snake_case)]
pub struct GoveeDevice {
    pub device: String,
    pub model: String,
    pub deviceName: String,
    pub controllable: bool,
    pub retrievable: bool,
    pub supportCmds: Vec<String>,
    pub properties: Properties,
}

#[derive(Debug, Deserialize, Serialize)]
#[allow(non_snake_case)]
pub struct Properties {
    pub colorTem: ColorTem,
}

#[derive(Debug, Deserialize, Serialize)]
pub struct ColorTem {
    pub range: ColorTemRange,
}

#[derive(Debug, Deserialize, Serialize)]
pub struct ColorTemRange {
    pub min: i16,
    pub max: i16,
}

#[derive(Serialize)]
pub struct PayloadBody {
    pub device: String,
    pub model: String,
    pub cmd: GoveeCommand,
}

#[derive(Serialize, Deserialize)]
pub struct GoveeCommand {
    pub name: String,
    pub value: String,
}