Can use cURL to request fronius production
This commit is contained in:
@ -9,6 +9,8 @@ pub enum ConsumptionError {
|
||||
NonExistentFile,
|
||||
#[error("The file that should contain the consumption has an invalid content!")]
|
||||
FileInvalidContent(#[source] ParseIntError),
|
||||
#[error("Failed to execute cURL request!")]
|
||||
CurlReqFailed,
|
||||
}
|
||||
|
||||
pub type EnergyConsumption = i32;
|
||||
@ -63,9 +65,21 @@ pub async fn get_curr_consumption() -> anyhow::Result<EnergyConsumption> {
|
||||
.map_err(ConsumptionError::FileInvalidContent)?)
|
||||
}
|
||||
|
||||
ConsumptionBackend::Fronius { origin } => {
|
||||
let url = format!("{origin}/solar_api/v1/GetPowerFlowRealtimeData.fcgi");
|
||||
let response = reqwest::get(url).await?.json::<FroniusResponse>().await?;
|
||||
ConsumptionBackend::Fronius { fronius_orig, curl } => {
|
||||
let url = format!("{fronius_orig}/solar_api/v1/GetPowerFlowRealtimeData.fcgi");
|
||||
|
||||
let response = match curl {
|
||||
false => reqwest::get(url).await?.json::<FroniusResponse>().await?,
|
||||
true => {
|
||||
let res = std::process::Command::new("curl").arg(url).output()?;
|
||||
|
||||
if !res.status.success() {
|
||||
return Err(ConsumptionError::CurlReqFailed.into());
|
||||
}
|
||||
|
||||
serde_json::from_slice::<FroniusResponse>(&res.stdout)?
|
||||
}
|
||||
};
|
||||
|
||||
Ok(response.body.data.site.grid_production as i32)
|
||||
}
|
||||
|
Reference in New Issue
Block a user