Compare commits

..

2 Commits

2 changed files with 62 additions and 3 deletions

View File

@ -55,6 +55,20 @@ impl<'de> Deserialize<'de> for UtcDateTime {
}
}
#[derive(Clone, Copy, Serialize, Deserialize)]
pub struct Current {
pub phase1: f64,
pub phase2: f64,
pub phase3: f64,
}
#[derive(Clone, Copy, Serialize)]
pub struct SetCurrent {
pub time_to_live: Option<i32>,
#[serde(flatten)]
pub current: Current
}
#[derive(Clone, Debug, Deserialize, Eq, Ord, PartialEq, PartialOrd)]
#[serde(rename_all = "camelCase")]
pub struct Charger {
@ -204,6 +218,28 @@ pub struct Site {
pub installer_alias: Option<String>,
}
#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SiteDetails {
#[serde(flatten)]
pub site: Site,
pub circuits: Vec<Circuit>,
}
#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Circuit {
pub id: i64,
pub uuid: String,
pub site_id: i64,
pub circuit_panel_id: i64,
pub panel_name: String,
pub rated_current: f64,
pub fuse: f64,
pub chargers: Vec<Charger>,
pub use_dynamic_master: bool,
}
#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct LoginResponse {
@ -472,6 +508,26 @@ impl Site {
pub fn lifetime_energy(&self, ctx: &mut Context) -> Result<Vec<MeterReading>, ApiError> {
ctx.get(&format!("sites/{}/energy", self.id))
}
pub fn details(&self, ctx: &mut Context) -> Result<SiteDetails, ApiError> {
ctx.get(&format!("sites/{}", self.id))
}
}
impl Circuit {
fn dynamic_current_path(&self) -> String {
format!("sites/{}/circuits/{}/dynamicCurrent",
self.site_id, self.id)
}
pub fn dynamic_current(&self, ctx: &mut Context) -> Result<Current, ApiError> {
ctx.get(&self.dynamic_current_path())
}
pub fn set_dynamic_current(&self, ctx: &mut Context, current: SetCurrent) -> Result<(), ApiError> {
ctx.post(&self.dynamic_current_path(), &current)
}
}
impl Charger {

View File

@ -1,4 +1,4 @@
use serde::{de::IntoDeserializer, Deserialize};
use serde::Deserialize;
use serde_repr::Deserialize_repr;
use std::num::{ParseFloatError, ParseIntError};
use thiserror::Error;
@ -6,7 +6,7 @@ use tracing::info;
use ureq::json;
use crate::{
api::{ChargerOpMode, Context, OutputPhase, UtcDateTime},
api::{ChargerOpMode, Context, UtcDateTime},
signalr::{self, StreamError},
stream::NegotiateError,
};
@ -90,6 +90,7 @@ impl ObservationData {
})
}
/*
fn dynamic_type(&self) -> DataType {
match self {
ObservationData::Boolean(_) => DataType::Boolean,
@ -98,6 +99,7 @@ impl ObservationData {
ObservationData::String(_) => DataType::String,
}
}
*/
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
@ -278,7 +280,8 @@ impl Stream {
loop {
let msg = self.inner.recv()?;
match &msg {
Empty | Ping | InvocationResult { .. } => info!("Skipped message: {msg:?}"),
Ping => continue,
Empty | InvocationResult { .. } => info!("Skipped message: {msg:?}"),
Invocation { target, arguments } if target == "ProductUpdate" => {
if arguments.len() != 1 {
return de(msg);