Skip to main content

huawei_client/
api_requests.rs

1use serde::{Deserialize, Serialize};
2use serde_repr::{Deserialize_repr, Serialize_repr};
3use std::any::{TypeId};
4use strum::{Display, EnumString};
5use crate::api_responses::{GetDevRealKpiDataInverterItem, GetDevRealKpiDataPowerSensorItem};
6
7#[derive(Serialize, Deserialize, Debug)]
8#[serde(rename_all = "camelCase")]
9pub struct LoginRequest {
10    pub user_name: String,
11    pub system_code: String,
12}
13
14impl LoginRequest {
15    pub fn new(user_name: &str, system_code: &str) -> Self {
16        Self {
17            user_name: user_name.to_string(),
18            system_code: system_code.to_string(),
19        }
20    }
21}
22
23#[derive(Serialize, Deserialize, Debug)]
24#[serde(rename_all = "camelCase")]
25pub struct GetStationRealKpiDataRequest {
26    pub station_codes: String,
27}
28
29#[derive(EnumString, Display, Serialize_repr, Deserialize_repr, PartialEq, Debug, Clone)]
30#[repr(u8)]
31pub enum DeviceType {
32    StringInverter = 1,
33    SmartLogger = 2,
34    TRANSFORMER = 8,
35    EMI = 9,
36    ProtocolConverter = 13,
37    GeneralDevice = 16,
38    GridMeter = 17,
39    PID = 22,
40    PinnetDataLogger = 37,
41    ResidentialInverter = 38,
42    Battery = 39,
43    BackupBox = 40,
44    PLC = 45,
45    Optimizer = 46,
46    PowerSensor = 47,
47    Dongle = 62,
48    DistributedSmartLogger = 63,
49    SafetyBox = 70,
50}
51
52impl DeviceType {
53    pub fn get_data_item_type(&self) -> TypeId {
54        match self {
55            DeviceType::ResidentialInverter => TypeId::of::<GetDevRealKpiDataInverterItem>(),
56            DeviceType::PowerSensor => TypeId::of::<GetDevRealKpiDataPowerSensorItem>(),
57            _ => todo!(),
58        }
59    }
60}
61
62#[derive(Serialize, Deserialize, Debug)]
63#[serde(rename_all = "camelCase")]
64pub struct GetDevRealKpiRequest {
65    pub dev_ids: String,
66    pub dev_type_id: DeviceType,
67}
68
69#[derive(Serialize, Deserialize, Debug)]
70#[serde(rename_all = "camelCase")]
71pub struct GetDevListRequest {
72    pub station_codes: String,
73}