Can use cURL to request fronius production
This commit is contained in:
@ -39,8 +39,12 @@ pub enum ConsumptionBackend {
|
||||
/// Fronius inverter consumption
|
||||
Fronius {
|
||||
/// The origin of the domain where the webserver of the Fronius Symo can be reached
|
||||
#[clap(short, long, env = "FRONIUS_ORIG")]
|
||||
origin: String,
|
||||
#[clap(short, long, env)]
|
||||
fronius_orig: String,
|
||||
|
||||
/// Use cURL instead of reqwest to perform request
|
||||
#[clap(short, long)]
|
||||
curl: bool,
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -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