diff --git a/src/api.rs b/src/api.rs index 04b4998..d63b9f7 100644 --- a/src/api.rs +++ b/src/api.rs @@ -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, + #[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, } +#[derive(Clone, Debug, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct SiteDetails { + #[serde(flatten)] + pub site: Site, + pub circuits: Vec, +} + +#[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, + 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, ApiError> { ctx.get(&format!("sites/{}/energy", self.id)) } + + pub fn details(&self, ctx: &mut Context) -> Result { + 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 { + 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(), ¤t) + } } impl Charger {