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
///! TODO: doc
use serde::{Deserialize, Serialize};
use std::fmt::{Debug, Display};

mod serde_datetime;

#[derive(Debug, Serialize, Deserialize, PartialEq)]
pub struct SystemStatus {
    firmware: FirmwareSystemStatus,
    hardware: HardwareSystemStatus,
    time: TimeSystemStatus,
}

#[derive(Debug, Serialize, Deserialize, PartialEq)]
pub struct FirmwareSystemStatus {
    /// firmware version
    version: semver::Version,

    updates: FirmwareUpdatesSystemStatus,
}

#[derive(Debug, Serialize, Deserialize, PartialEq)]
pub struct FirmwareUpdatesSystemStatus {
    /// whether automatic updates are enabled
    enabled: bool,
}

#[derive(Debug, Serialize, Deserialize, PartialEq)]
pub struct HardwareSystemStatus {
    /// hardware version
    version: semver::Version,

    /// unique serial number identifying this device
    serial_number: SerialNumber,
}
#[derive(Debug, Serialize, Deserialize, PartialEq)]
pub struct TimeSystemStatus {
    /// milliseconds elapsed since device last booted
    milliseconds_since_boot: u64,

    /// seconds elapsed since device last booted
    seconds_since_boot: u64,

    /// current system time of the device
    #[serde(with = "serde_datetime", rename = "epoch_time")]
    current_time: chrono::DateTime<chrono::Utc>,
}

#[derive(Serialize, Deserialize, PartialEq)]
pub struct SerialNumber(String);
impl Display for SerialNumber {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}", self.0)
    }
}
impl Debug for SerialNumber {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}", self)
    }
}