Skip to content

Commit ae1f0cc

Browse files
committed
undoc_api: most fields of OneClickIotRuleDevice are Optional
This should resolve a failure to parse the json response when most fields are null'd out. Turns out that we don't need the device field to activate a one-click, so we skip that part of the struct that we're extracting. refs: #352
1 parent a891357 commit ae1f0cc

File tree

3 files changed

+130
-54
lines changed

3 files changed

+130
-54
lines changed

src/__k9_snapshots__/undoc_api/undoc_api_test_get_one_click.snap

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,29 @@ OneClickResponse {
5050
iot_rules: [
5151
OneClickIotRule {
5252
device_obj: OneClickIotRuleDevice {
53-
name: "Study Floor Lamp 1",
54-
device: "xx:34:11",
55-
sku: "H6072",
53+
name: Some(
54+
"Study Floor Lamp 1",
55+
),
56+
device: Some(
57+
"xx:34:11",
58+
),
59+
sku: Some(
60+
"H6072",
61+
),
5662
topic: REDACTED,
57-
ble_address: "",
58-
ble_name: "Govee_H6072_3411",
63+
ble_address: Some(
64+
"",
65+
),
66+
ble_name: Some(
67+
"Govee_H6072_3411",
68+
),
5969
device_splicing_status: 0,
6070
feast_id: 0,
6171
feast_name: "",
6272
feast_type: 0,
63-
goods_type: 30,
73+
goods_type: Some(
74+
30,
75+
),
6476
ic: Some(
6577
66,
6678
),
@@ -71,19 +83,33 @@ OneClickResponse {
7183
0,
7284
),
7385
is_feast: false,
74-
pact_type: 2,
75-
pact_code: 1,
86+
pact_type: Some(
87+
2,
88+
),
89+
pact_code: Some(
90+
1,
91+
),
7692
settings: None,
77-
spec: "",
93+
spec: Some(
94+
"",
95+
),
7896
sub_device: "",
7997
sub_device_num: 0,
8098
sub_devices: Some(
8199
Object {},
82100
),
83-
version_hard: "3.02.00",
84-
version_soft: "2.04.05",
85-
wifi_soft_version: "1.02.11",
86-
wifi_hard_version: "1.00.10",
101+
version_hard: Some(
102+
"3.02.00",
103+
),
104+
version_soft: Some(
105+
"2.04.05",
106+
),
107+
wifi_soft_version: Some(
108+
"1.02.11",
109+
),
110+
wifi_hard_version: Some(
111+
"1.00.10",
112+
),
87113
},
88114
rule: [
89115
OneClickIotRuleEntry {

src/__k9_snapshots__/undoc_api/undoc_api_test_issue36.snap

Lines changed: 78 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,29 @@ OneClickResponse {
5050
iot_rules: [
5151
OneClickIotRule {
5252
device_obj: OneClickIotRuleDevice {
53-
name: "TV Backlight",
54-
device: "XX:XX:XX",
55-
sku: "H6199",
53+
name: Some(
54+
"TV Backlight",
55+
),
56+
device: Some(
57+
"XX:XX:XX",
58+
),
59+
sku: Some(
60+
"H6199",
61+
),
5662
topic: REDACTED,
57-
ble_address: "XX:XX:XX",
58-
ble_name: "ihoment_H6199_3468",
63+
ble_address: Some(
64+
"XX:XX:XX",
65+
),
66+
ble_name: Some(
67+
"ihoment_H6199_3468",
68+
),
5969
device_splicing_status: 0,
6070
feast_id: 0,
6171
feast_name: "",
6272
feast_type: 0,
63-
goods_type: 24,
73+
goods_type: Some(
74+
24,
75+
),
6476
ic: Some(
6577
50,
6678
),
@@ -71,19 +83,33 @@ OneClickResponse {
7183
0,
7284
),
7385
is_feast: false,
74-
pact_type: 1,
75-
pact_code: 1,
86+
pact_type: Some(
87+
1,
88+
),
89+
pact_code: Some(
90+
1,
91+
),
7692
settings: None,
77-
spec: "",
93+
spec: Some(
94+
"",
95+
),
7896
sub_device: "",
7997
sub_device_num: 0,
8098
sub_devices: Some(
8199
Object {},
82100
),
83-
version_hard: "1.00.01",
84-
version_soft: "1.07.02",
85-
wifi_soft_version: "1.00.29",
86-
wifi_hard_version: "1.00.01",
101+
version_hard: Some(
102+
"1.00.01",
103+
),
104+
version_soft: Some(
105+
"1.07.02",
106+
),
107+
wifi_soft_version: Some(
108+
"1.00.29",
109+
),
110+
wifi_hard_version: Some(
111+
"1.00.01",
112+
),
87113
},
88114
rule: [
89115
OneClickIotRuleEntry {
@@ -130,17 +156,29 @@ OneClickResponse {
130156
iot_rules: [
131157
OneClickIotRule {
132158
device_obj: OneClickIotRuleDevice {
133-
name: "TV Backlight",
134-
device: "XX:XX:XX",
135-
sku: "H6199",
159+
name: Some(
160+
"TV Backlight",
161+
),
162+
device: Some(
163+
"XX:XX:XX",
164+
),
165+
sku: Some(
166+
"H6199",
167+
),
136168
topic: REDACTED,
137-
ble_address: "XX:XX:XX",
138-
ble_name: "ihoment_H6199_3468",
169+
ble_address: Some(
170+
"XX:XX:XX",
171+
),
172+
ble_name: Some(
173+
"ihoment_H6199_3468",
174+
),
139175
device_splicing_status: 0,
140176
feast_id: 0,
141177
feast_name: "",
142178
feast_type: 0,
143-
goods_type: 24,
179+
goods_type: Some(
180+
24,
181+
),
144182
ic: Some(
145183
50,
146184
),
@@ -151,19 +189,33 @@ OneClickResponse {
151189
0,
152190
),
153191
is_feast: false,
154-
pact_type: 1,
155-
pact_code: 1,
192+
pact_type: Some(
193+
1,
194+
),
195+
pact_code: Some(
196+
1,
197+
),
156198
settings: None,
157-
spec: "",
199+
spec: Some(
200+
"",
201+
),
158202
sub_device: "",
159203
sub_device_num: 0,
160204
sub_devices: Some(
161205
Object {},
162206
),
163-
version_hard: "1.00.01",
164-
version_soft: "1.07.02",
165-
wifi_soft_version: "1.00.29",
166-
wifi_hard_version: "1.00.01",
207+
version_hard: Some(
208+
"1.00.01",
209+
),
210+
version_soft: Some(
211+
"1.07.02",
212+
),
213+
wifi_soft_version: Some(
214+
"1.00.29",
215+
),
216+
wifi_hard_version: Some(
217+
"1.00.01",
218+
),
167219
},
168220
rule: [
169221
OneClickIotRuleEntry {

src/undoc_api.rs

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,6 @@ impl GoveeUndocumentedApi {
467467
let msgs = rule.rule.into_iter().map(|r| r.iot_msg).collect();
468468
entries.push(ParsedOneClickEntry {
469469
topic: rule.device_obj.topic,
470-
device: rule.device_obj.device,
471470
msgs,
472471
});
473472
}
@@ -488,7 +487,6 @@ pub struct ParsedOneClick {
488487
#[derive(Debug, Clone, Serialize, Deserialize)]
489488
pub struct ParsedOneClickEntry {
490489
pub topic: Redacted<String>,
491-
pub device: String,
492490
pub msgs: Vec<JsonValue>,
493491
}
494492

@@ -671,39 +669,39 @@ pub struct OneClickIotRuleEntryCmd {
671669
#[serde(rename_all = "camelCase")]
672670
#[cfg_attr(debug_assertions, serde(deny_unknown_fields))]
673671
pub struct OneClickIotRuleDevice {
674-
pub name: String,
675-
pub device: String,
676-
pub sku: String,
672+
pub name: Option<String>,
673+
pub device: Option<String>,
674+
pub sku: Option<String>,
677675

678676
pub topic: Redacted<String>,
679677

680-
pub ble_address: String,
681-
pub ble_name: String,
678+
pub ble_address: Option<String>,
679+
pub ble_name: Option<String>,
682680
pub device_splicing_status: u32,
683681
pub feast_id: u64,
684682
pub feast_name: String,
685683
pub feast_type: u64,
686-
pub goods_type: u64,
684+
pub goods_type: Option<u64>,
687685
pub ic: Option<u32>,
688686
#[serde(rename = "ic_sub_1")]
689687
pub ic_sub_1: Option<u32>,
690688
#[serde(rename = "ic_sub_2")]
691689
pub ic_sub_2: Option<u32>,
692690
#[serde(deserialize_with = "boolean_int")]
693691
pub is_feast: bool,
694-
pub pact_type: u32,
695-
pub pact_code: u32,
692+
pub pact_type: Option<u32>,
693+
pub pact_code: Option<u32>,
696694

697695
pub settings: Option<JsonValue>,
698-
pub spec: String,
696+
pub spec: Option<String>,
699697
pub sub_device: String,
700698
pub sub_device_num: u64,
701699
pub sub_devices: Option<JsonValue>,
702700

703-
pub version_hard: String,
704-
pub version_soft: String,
705-
pub wifi_soft_version: String,
706-
pub wifi_hard_version: String,
701+
pub version_hard: Option<String>,
702+
pub version_soft: Option<String>,
703+
pub wifi_soft_version: Option<String>,
704+
pub wifi_hard_version: Option<String>,
707705
}
708706

709707
#[derive(Deserialize, Serialize, Debug, Clone)]

0 commit comments

Comments
 (0)