Skip to main content

Overview

Retrieves weekly battery charging and discharging statistics for a specific MIX inverter at a plant. This method provides insights into battery performance over a weekly period.

Method Signature

pub async fn get_weekly_battery_stats(
    &mut self,
    plant_id: &str,
    mix_sn: &str
) -> Result<serde_json::Value>

Parameters

plant_id
&str
required
The unique identifier of the plant containing the MIX inverter.
mix_sn
&str
required
The serial number of the MIX inverter device.

Returns

Returns a Result<serde_json::Value> containing the weekly battery statistics data on success, or a GrowattError on failure.

Errors

This method may return the following errors:
  • GrowattError::InvalidResponse - If the response is empty or null (typically indicates the user is not logged in)
  • GrowattError::NetworkError - If there is a network communication error
  • GrowattError::AuthenticationError - If the session has expired or authentication failed

Example

use growatt_rs::GrowattApi;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut api = GrowattApi::new()?;
    
    // Login first
    api.login("username", "password").await?;
    
    // Get weekly battery stats
    let plant_id = "123456";
    let mix_sn = "ABC123DEF456";
    
    let stats = api.get_weekly_battery_stats(plant_id, mix_sn).await?;
    
    println!("Weekly battery stats: {:?}", stats);
    
    Ok(())
}

Response Structure

The response contains weekly battery statistics including charging and discharging data. The exact structure depends on the Growatt API response format.
This method automatically checks if you are logged in before making the request. If the session has expired, you will need to call login() again.

Build docs developers (and LLMs) love