Can get consumption on Fronius inverter
This commit is contained in:
		@@ -35,6 +35,13 @@ pub enum ConsumptionBackend {
 | 
			
		||||
        #[clap(short, long, default_value = "/dev/shm/consumption.txt")]
 | 
			
		||||
        path: String,
 | 
			
		||||
    },
 | 
			
		||||
 | 
			
		||||
    /// Fronius inverter consumption
 | 
			
		||||
    Fronius {
 | 
			
		||||
        /// The origin of the domain where the webserver of the Fronius Symo can be reacher
 | 
			
		||||
        #[clap(short, long)]
 | 
			
		||||
        origin: String,
 | 
			
		||||
    },
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// Solar system central backend
 | 
			
		||||
 
 | 
			
		||||
@@ -13,6 +13,30 @@ pub enum ConsumptionError {
 | 
			
		||||
 | 
			
		||||
pub type EnergyConsumption = i32;
 | 
			
		||||
 | 
			
		||||
#[derive(serde::Deserialize)]
 | 
			
		||||
struct FroniusResponse {
 | 
			
		||||
    #[serde(rename = "Body")]
 | 
			
		||||
    body: FroniusResponseBody,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[derive(serde::Deserialize)]
 | 
			
		||||
struct FroniusResponseBody {
 | 
			
		||||
    #[serde(rename = "Data")]
 | 
			
		||||
    data: FroniusResponseBodyData,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[derive(serde::Deserialize)]
 | 
			
		||||
struct FroniusResponseBodyData {
 | 
			
		||||
    #[serde(rename = "Site")]
 | 
			
		||||
    site: FroniusResponseSite,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[derive(serde::Deserialize)]
 | 
			
		||||
struct FroniusResponseSite {
 | 
			
		||||
    #[serde(rename = "P_Grid")]
 | 
			
		||||
    grid_production: f64,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// Get current electrical energy consumption
 | 
			
		||||
pub async fn get_curr_consumption() -> anyhow::Result<EnergyConsumption> {
 | 
			
		||||
    let backend = AppConfig::get()
 | 
			
		||||
@@ -38,5 +62,12 @@ pub async fn get_curr_consumption() -> anyhow::Result<EnergyConsumption> {
 | 
			
		||||
                .parse()
 | 
			
		||||
                .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?;
 | 
			
		||||
 | 
			
		||||
            Ok(response.body.data.site.grid_production as i32)
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user