Skip to main content
The Plant struct represents a solar power installation in the Growatt system. It contains basic information about a plant including its ID, name, location, and power capacity.

Structure

#[derive(Debug, Serialize, Deserialize)]
pub struct Plant {
    #[serde(rename = "id")]
    pub plant_id: String,
    #[serde(rename = "name", alias = "plantName")]
    pub plant_name: String,
    #[serde(rename = "plantAddress", default)]
    pub plant_address: Option<String>,
    #[serde(rename = "plantPower", default)]
    pub plant_watts: Option<f64>,
    #[serde(rename = "isShare", default)]
    pub is_share: Option<bool>,
}
This struct is defined in src/lib.rs:36-47 and uses serde for serialization/deserialization with the Growatt API.

Fields

plant_id
String
required
Unique identifier for the plant. Serialized as "id" in the API.
plant_name
String
required
Display name of the plant. Serialized as "name" in the API, with an alias for "plantName".
plant_address
Option<String>
Physical address or location of the plant. Serialized as "plantAddress" in the API. This field is optional and may be None.
plant_watts
Option<f64>
Power capacity in watts. Serialized as "plantPower" in the API. This field is optional and may be None.
is_share
Option<bool>
Indicates whether the plant is shared with other users. Serialized as "isShare" in the API. This field is optional and may be None.

PlantList

The PlantList is a wrapper struct containing a vector of plants:
#[derive(Debug, Serialize, Deserialize)]
pub struct PlantList(pub Vec<Plant>);
This is the return type for the get_plants() method.

Usage Example

use growatt::Growatt;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut client = Growatt::new();
    client.login("username", "password").await?;
    
    // Get all plants
    let plants = client.get_plants().await?;
    
    // Iterate through plants
    for plant in plants.0 {
        println!("Plant ID: {}", plant.plant_id);
        println!("Plant Name: {}", plant.plant_name);
        
        // Handle optional fields
        if let Some(address) = plant.plant_address {
            println!("Address: {}", address);
        }
        
        if let Some(power) = plant.plant_watts {
            println!("Power: {} W", power);
        }
        
        if let Some(is_shared) = plant.is_share {
            println!("Shared: {}", is_shared);
        }
    }
    
    Ok(())
}

Serde Attributes

The struct uses several serde attributes for proper API compatibility:
  • rename: Maps Rust field names to JSON keys (e.g., plant_id"id")
  • alias: Allows alternative JSON keys during deserialization (e.g., "plantName" as an alias for "name")
  • default: Uses default values for missing optional fields during deserialization

Build docs developers (and LLMs) love