Skip to main content

Method Signature

pub async fn get_devices_by_plant_list(
    &mut self, 
    plant_id: &str, 
    curr_page: Option<i32>
) -> Result<serde_json::Value>
Retrieves a paginated list of all devices associated with a specific plant. This method provides comprehensive device information with pagination support for plants with many devices.

Parameters

plant_id
&str
required
The unique identifier of the plant to retrieve devices from
curr_page
Option<i32>
default:"1"
The page number to retrieve. If None is provided, defaults to page 1.

Returns

Type: Result<serde_json::Value> Returns a JSON value containing paginated device information. The response typically includes:
  • Array of device objects with detailed information
  • Device serial numbers, types, and status
  • Performance metrics and statistics
  • Pagination metadata (total pages, total count)

Errors

This method can return the following errors:
  • GrowattError::NotLoggedIn - User is not authenticated
  • GrowattError::RequestError - HTTP request failed
  • GrowattError::InvalidResponse - Empty response or invalid structure
  • GrowattError::JsonError - Failed to parse JSON response

Example

use growatt_api::Growatt;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut client = Growatt::new();
    
    // Login first
    client.login("username", "password").await?;
    
    let plant_id = "123456";
    
    // Get first page of devices (default)
    let devices_page1 = client.get_devices_by_plant_list(plant_id, None).await?;
    println!("Page 1: {}", devices_page1);
    
    // Get second page explicitly
    let devices_page2 = client.get_devices_by_plant_list(plant_id, Some(2)).await?;
    println!("Page 2: {}", devices_page2);
    
    Ok(())
}

Example: Iterate Through All Pages

use growatt_api::Growatt;
use serde_json::Value;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut client = Growatt::new();
    client.login("username", "password").await?;
    
    let plant_id = "123456";
    let mut page = 1;
    let mut all_devices = Vec::new();
    
    loop {
        let response = client.get_devices_by_plant_list(plant_id, Some(page)).await?;
        
        // Extract devices from response (adjust based on actual structure)
        if let Some(devices) = response.get("devices").and_then(|v| v.as_array()) {
            if devices.is_empty() {
                break; // No more devices
            }
            all_devices.extend_from_slice(devices);
            page += 1;
        } else {
            break;
        }
    }
    
    println!("Total devices: {}", all_devices.len());
    Ok(())
}

API Endpoint

POST /panel/getDevicesByPlantList Form Parameters:
  • plantId - The plant identifier
  • currPage - Current page number (string representation)

Notes

This method automatically handles session management. If the session has expired, it will attempt to re-authenticate using stored credentials before making the request.
Pagination Support: This method accepts an optional page number parameter. When retrieving devices from plants with many devices, iterate through pages until an empty result is returned. The page parameter defaults to 1 if not specified.
The curr_page parameter is converted to a string internally before being sent to the API, as the Growatt API expects string values in form parameters.

Build docs developers (and LLMs) love