Skip to content

Commit 26328c6

Browse files
committed
fix: Make more stuff optional. 0.4.1
1 parent 164e794 commit 26328c6

File tree

7 files changed

+48
-30
lines changed

7 files changed

+48
-30
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rustifi"
3-
version = "0.4.0"
3+
version = "0.4.1"
44
edition = "2024"
55
authors = ["Judah Fuller <[email protected]>"]
66
description = "Open source rust library to interface with Ubiquiti's Unifi Controller."

src/device/mod.rs

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ mod models;
22

33
use crate::responses::stat::devices::RawDevice;
44
use crate::types::{
5-
ConfigNet, InterfaceUserStats, SystemStats, Temperature, Uplink, UserStats, Version, IP,
5+
ConfigNet, IP, InterfaceUserStats, SystemStats, Temperature, Uplink, UserStats, Version,
66
};
77
use chrono::prelude::*;
88
use models::DeviceType;
@@ -75,21 +75,28 @@ impl From<RawDevice> for Device {
7575
name: raw.name,
7676
config_network: ConfigNet::from(raw.config_network),
7777
ip: IP::from(raw.ip),
78-
connected_at: DateTime::from_timestamp(raw.connected_at, 0).expect("Invalid timestamp"),
79-
provisioned_at: DateTime::from_timestamp(raw.provisioned_at, 0)
80-
.expect("Invalid timestamp"),
81-
disconnected_at: DateTime::from_timestamp(raw.disconnected_at, 0)
82-
.expect("Invalid timestamp"),
83-
startup_time: DateTime::from_timestamp(
84-
raw.startup_timestamp.unwrap_or_default(),
78+
connected_at: DateTime::from_timestamp(
79+
match raw.connected_at {
80+
Some(ts) => ts,
81+
None => 0,
82+
},
8583
0,
8684
)
8785
.expect("Invalid timestamp"),
88-
last_seen: DateTime::from_timestamp(
89-
raw.last_seen.unwrap_or_default(),
86+
provisioned_at: DateTime::from_timestamp(raw.provisioned_at, 0)
87+
.expect("Invalid timestamp"),
88+
disconnected_at: DateTime::from_timestamp(
89+
match raw.disconnected_at {
90+
Some(ts) => ts,
91+
None => 0,
92+
},
9093
0,
9194
)
9295
.expect("Invalid timestamp"),
96+
startup_time: DateTime::from_timestamp(raw.startup_timestamp.unwrap_or_default(), 0)
97+
.expect("Invalid timestamp"),
98+
last_seen: DateTime::from_timestamp(raw.last_seen.unwrap_or_default(), 0)
99+
.expect("Invalid timestamp"),
93100
serial: match raw.serial {
94101
Some(s) => s,
95102
None => "".to_string(),

src/device/models/access_points/mod.rs

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ mod models;
22

33
use crate::responses::stat::devices::RawDevice;
44
use crate::types::{
5-
Antenna, ConfigNet, InterfaceUserStats, Port, Radio, SystemStats, Temperature, Uplink,
6-
UserStats, Version, IP,
5+
Antenna, ConfigNet, IP, InterfaceUserStats, Port, Radio, SystemStats, Temperature, Uplink,
6+
UserStats, Version,
77
};
88
use chrono::prelude::*;
99

@@ -81,21 +81,28 @@ impl From<RawDevice> for AccessPoint {
8181
name: raw.name,
8282
config_network: ConfigNet::from(raw.config_network),
8383
ip: IP::from(raw.ip),
84-
connected_at: DateTime::from_timestamp(raw.connected_at, 0).expect("Invalid timestamp"),
85-
provisioned_at: DateTime::from_timestamp(raw.provisioned_at, 0)
86-
.expect("Invalid timestamp"),
87-
disconnected_at: DateTime::from_timestamp(raw.disconnected_at, 0)
88-
.expect("Invalid timestamp"),
89-
startup_time: DateTime::from_timestamp(
90-
raw.startup_timestamp.unwrap_or_default(),
84+
connected_at: DateTime::from_timestamp(
85+
match raw.connected_at {
86+
Some(ts) => ts,
87+
None => 0,
88+
},
9189
0,
9290
)
9391
.expect("Invalid timestamp"),
94-
last_seen: DateTime::from_timestamp(
95-
raw.last_seen.unwrap_or_default(),
92+
provisioned_at: DateTime::from_timestamp(raw.provisioned_at, 0)
93+
.expect("Invalid timestamp"),
94+
disconnected_at: DateTime::from_timestamp(
95+
match raw.disconnected_at {
96+
Some(ts) => ts,
97+
None => 0,
98+
},
9699
0,
97100
)
98101
.expect("Invalid timestamp"),
102+
startup_time: DateTime::from_timestamp(raw.startup_timestamp.unwrap_or_default(), 0)
103+
.expect("Invalid timestamp"),
104+
last_seen: DateTime::from_timestamp(raw.last_seen.unwrap_or_default(), 0)
105+
.expect("Invalid timestamp"),
99106
serial: match raw.serial {
100107
Some(s) => s,
101108
None => "".to_string(),

src/responses/stat/devices.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ pub struct RawDevice {
5454
pub mgmt_network_id: Option<String>,
5555
pub gateway_mac: Option<String>,
5656
pub external_id: Option<String>,
57-
pub connected_at: i64,
57+
pub connected_at: Option<i64>,
5858
pub two_phase_adopt: Option<bool>,
5959
#[serde(default)]
6060
pub port_overrides: Option<Vec<PortOverride>>,
@@ -74,7 +74,7 @@ pub struct RawDevice {
7474
pub last_uplink: LastUplink,
7575
pub led_override: Option<String>,
7676
pub ether_lighting: Option<EtherLighting>,
77-
pub disconnected_at: i64,
77+
pub disconnected_at: Option<i64>,
7878
pub architecture: Option<String>,
7979
pub x_aes_gcm: Option<bool>,
8080
pub has_fan: Option<bool>,
@@ -455,7 +455,7 @@ pub struct RadioTable {
455455
pub channel: Value,
456456
pub antenna_gain: u16,
457457
pub builtin_antenna: bool,
458-
pub vwire_enabled: bool,
458+
pub vwire_enabled: Option<bool>,
459459
pub hard_noise_floor_enabled: Option<bool>,
460460
pub sens_level_enabled: Option<bool>,
461461
pub max_txpower: u16,

src/site/mod.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,13 @@ impl Site {
4141
Ok(response) => {
4242
let mut aps: Vec<AccessPoint> = Vec::new();
4343
let mut switches: Vec<Device> = Vec::new();
44-
let response = match response.json::<DeviceListResponse>().await {
44+
let resp_text = response.text().await.unwrap();
45+
let response = match serde_json::from_str::<DeviceListResponse>(&resp_text) {
4546
Ok(response) => response,
46-
Err(e) => return Err(Box::new(e)),
47+
Err(e) => {
48+
println!("Error parsing JSON: {}", e);
49+
return Err(Box::new(e));
50+
}
4751
};
4852
for device in response.data {
4953
if device.adopted {

src/types/radio.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ mod tests {
155155
name: "radio0".to_string(),
156156
nss: 2,
157157
tx_power_mode: "high".to_string(),
158-
vwire_enabled: false,
158+
vwire_enabled: Some(false),
159159
hard_noise_floor_enabled: Some(false),
160160
sens_level_enabled: Some(false),
161161
radio: "".to_string(),
@@ -216,7 +216,7 @@ mod tests {
216216
name: "".to_string(),
217217
nss: 0,
218218
tx_power_mode: "invalid".to_string(),
219-
vwire_enabled: false,
219+
vwire_enabled: Some(false),
220220
hard_noise_floor_enabled: None,
221221
sens_level_enabled: None,
222222
radio: "".to_string(),

0 commit comments

Comments
 (0)