enphase_local/
inventory.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 inventory API.
6
7use crate::timestamp_string;
8use chrono::{DateTime, Utc};
9use serde::{Deserialize, Serialize};
10use serde_repr::{Deserialize_repr, Serialize_repr};
11
12/// The inventory of all devices.
13#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
14pub struct Inventory(pub Vec<InventoryGroup>);
15
16/// A group of devices of a particular type in the inventory.
17#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
18pub struct InventoryGroup {
19    #[serde(rename = "type")]
20    pub type_: DeviceType,
21    pub devices: Vec<Device>,
22}
23
24#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
25#[serde(rename_all = "UPPERCASE")]
26pub enum DeviceType {
27    /// Power Conditioning Unit, aka. microinverter.
28    Pcu,
29    /// AC Battery.
30    Acb,
31    /// Network System Relay Breaker, aka. IQ Relay.
32    Nsrb,
33    /// Electrical sub-panel, aka. IQ System Controller.
34    Esub,
35}
36
37/// The state of a device in the inventory.
38#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
39pub struct Device {
40    /// The part number of the device.
41    pub part_num: String,
42    /// When the device was installed.
43    #[serde(with = "timestamp_string")]
44    pub installed: DateTime<Utc>,
45    /// The serial number of the device.
46    pub serial_num: String,
47    /// The device's current statuses.
48    pub device_status: Vec<DeviceStatus>,
49    /// When the device last reported to the gateway.
50    #[serde(with = "timestamp_string")]
51    pub last_rpt_date: DateTime<Utc>,
52    /// The administrative state of the device.
53    pub admin_state: AdminState,
54    /// The type of device.
55    pub dev_type: u8,
56    /// When the device was added to the gateway.
57    #[serde(with = "timestamp_string")]
58    pub created_date: DateTime<Utc>,
59    /// When the device's firmware was loaded.
60    #[serde(with = "timestamp_string")]
61    pub img_load_date: DateTime<Utc>,
62    /// The device's firmware product number.
63    pub img_pnum_running: String,
64    pub ptpn: String,
65    /// The channel Enphase ID.
66    pub chaneid: u64,
67    pub device_control: Vec<DeviceControl>,
68    /// Whether the device is producing electricity.
69    pub producing: bool,
70    /// Whether the device is communicating with the gateway.
71    pub communicating: bool,
72    /// Whether the device is provisioned.
73    pub provisioned: bool,
74    /// Whether the device is operating.
75    pub operating: bool,
76    pub phase: String,
77}
78
79/// The status flags of a device.
80#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
81pub enum DeviceStatus {
82    #[serde(rename = "envoy.global.ok")]
83    Ok,
84    #[serde(rename = "envoy.cond_flags.pcu_chan.dcvoltagetoolow")]
85    DcVoltageTooLow,
86    #[serde(rename = "envoy.cond_flags.pcu_ctrl.dc-pwr-low")]
87    DcPowerLow,
88    #[serde(rename = "envoy.cond_flags.obs_strs.failure")]
89    Failure,
90}
91
92/// The administrative state of a device.
93#[derive(Clone, Copy, Debug, Deserialize_repr, Eq, PartialEq, Serialize_repr)]
94#[repr(u8)]
95pub enum AdminState {
96    Discovered = 1,
97    Verified = 2,
98    Deleted = 3,
99}
100
101#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
102pub struct DeviceControl {
103    /// Whether the device has a Ground Fault Interrupt error state
104    pub gficlearset: bool,
105}