enphase_local/
home.rs

1// Copyright 2024 the octopower authors.
2// This project is dual-licensed under Apache 2.0 and MIT terms.
3// See LICENSE-APACHE and LICENSE-MIT for details.
4
5//! Types returned by the home API.
6
7use chrono::{DateTime, NaiveTime, Utc, serde::ts_seconds};
8use serde::{Deserialize, Serialize};
9use std::net::IpAddr;
10
11#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
12pub struct Home {
13    /// When the software was built.
14    #[serde(with = "ts_seconds")]
15    pub software_build_epoch: DateTime<Utc>,
16    /// The local timezone configured for the gateway.
17    pub timezone: String,
18    /// The current date according to the gateway.
19    pub current_date: String,
20    /// The current time according to the gateway.
21    pub current_time: NaiveTime,
22    /// Information about the network interfaces of the gatewway.
23    pub network: Network,
24    /// The type of tariff configured.
25    pub tariff: String,
26    /// Information about communications with devices.
27    pub comm: CommunicationSummary,
28    /// Information about wireless connections.
29    pub wireless_connection: Vec<WirelessConnection>,
30}
31
32#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
33pub struct Network {
34    pub web_comm: bool,
35    pub ever_reported_to_enlighten: bool,
36    #[serde(with = "ts_seconds")]
37    pub last_enlighten_report_time: DateTime<Utc>,
38    pub primary_interface: String,
39    pub interfaces: Vec<Interface>,
40}
41
42#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
43pub struct Interface {
44    #[serde(rename = "type")]
45    pub type_: InterfaceType,
46    pub mac: String,
47    pub dhcp: bool,
48    pub ip: IpAddr,
49    pub signal_strength: u8,
50    pub signal_strength_max: u8,
51    pub carrier: bool,
52    pub supported: Option<bool>,
53    pub present: Option<bool>,
54    pub configured: Option<bool>,
55    pub status: Option<String>,
56}
57
58#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
59#[serde(rename_all = "lowercase")]
60pub enum InterfaceType {
61    Ethernet,
62    Wifi,
63}
64
65#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
66pub struct CommunicationSummary {
67    /// The number of devices communicating.
68    pub num: u8,
69    /// The signal level.
70    pub level: u8,
71    /// Information about Power Conditioning Units.
72    pub pcu: CommunicationStatus,
73    /// Information about AC Batteries.
74    pub acb: CommunicationStatus,
75    /// Information about Network System Relay Breakers.
76    pub nsrb: CommunicationStatus,
77    /// Information about Electrical Sub-panels.
78    pub esub: CommunicationStatus,
79    /// Information about IQ Batteries (aka. Encharge Storage).
80    pub encharge: Vec<EnchargeCommunicationStatus>,
81}
82
83#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
84pub struct CommunicationStatus {
85    /// The number of devices communicating.
86    pub num: u8,
87    /// The signal level.
88    pub level: u8,
89}
90
91#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
92pub struct EnchargeCommunicationStatus {
93    /// The number of devices communicating.
94    pub num: u8,
95    /// The signal level.
96    pub level: u8,
97    /// The 2.4 GHz signal level.
98    pub level_24g: u8,
99    /// The sub-GHz signal level.
100    pub level_subg: u8,
101}
102
103#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
104pub struct WirelessConnection {
105    /// The current signal strength.
106    pub signal_strength: u8,
107    /// The maximum signal strength recorded.
108    pub signal_strength_max: u8,
109    /// The type of wireless connection.
110    #[serde(rename = "type")]
111    pub type_: WirelessConnectionType,
112    /// Whether the connection is connected.
113    pub connected: bool,
114}
115
116#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
117pub enum WirelessConnectionType {
118    #[serde(rename = "BLE")]
119    Ble,
120}