uhppote_rs/types/
device_config.rs

1use std::net::Ipv4Addr;
2
3use chrono::NaiveDate;
4
5use crate::messages::GetConfigResponse;
6
7/// Configuration of a [`Device`]
8#[derive(Debug)]
9pub struct DeviceConfig {
10    pub id: u32,
11    pub address: Ipv4Addr,
12    pub subnet: Ipv4Addr,
13    pub gateway: Ipv4Addr,
14    pub mac: String,
15    pub version: String,
16    pub date: NaiveDate,
17}
18
19impl TryFrom<GetConfigResponse> for DeviceConfig {
20    type Error = anyhow::Error;
21
22    fn try_from(response: GetConfigResponse) -> Result<Self, Self::Error> {
23        Ok(DeviceConfig {
24            id: response.device_id,
25            address: response.ip_address,
26            subnet: response.subnet,
27            gateway: response.gateway,
28            mac: response.mac.to_string(),
29            version: response.version.to_string(),
30            date: response.date.try_into()?,
31        })
32    }
33}