You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
92 lines
3.0 KiB
92 lines
3.0 KiB
from sungrow_api import get_device_list, login, call_api, get_power_station_list, get_device_list, get_device_realtime_data, ensure_success, pretty_print
|
|
from sungrow_state import save_state
|
|
|
|
def main():
|
|
print("Logging in...")
|
|
token = login()
|
|
print("Token:", token[:12], "...")
|
|
|
|
# 1) Get plant list
|
|
plant_list = get_power_station_list(token, debug=True)
|
|
print("Plant List Response:")
|
|
pretty_print(plant_list)
|
|
|
|
# Validate before accessing
|
|
ensure_success(plant_list)
|
|
|
|
# 2) Extract ps_id
|
|
ps_id = plant_list["result_data"]["pageList"][0]["ps_id"]
|
|
print("Using ps_id:", ps_id)
|
|
|
|
|
|
# 3) Query device list
|
|
device_list = get_device_list(
|
|
token=token,
|
|
ps_id=ps_id,
|
|
cur_page=1,
|
|
size=20,
|
|
is_virtual_unit="0", # 0 physical devices, 1 virtual
|
|
#device_type_list=[1, 3, 11], # inverter, grid point, plant
|
|
#rel_state="1", # only claimed devices
|
|
is_get_firmware_version="1", # 1: include firmware info
|
|
debug=True
|
|
)
|
|
|
|
# 4) Query device list on plant level
|
|
device_list = get_device_list(
|
|
token=token,
|
|
ps_id=ps_id,
|
|
cur_page=1,
|
|
size=20,
|
|
is_virtual_unit="1", # 0 physical devices, 1 virtual
|
|
#device_type_list=[1, 3, 11], # inverter, grid point, plant
|
|
#rel_state="1", # only claimed devices
|
|
is_get_firmware_version="0", # 1: include firmware info
|
|
debug=True
|
|
)
|
|
|
|
# Extract relevant data from the first device in the list (assuming it's the plant-level virtual device)
|
|
device_info = device_list["result_data"]["pageList"][0]
|
|
|
|
ps_key = device_info["ps_key"]
|
|
device_name = device_info["device_name"]
|
|
|
|
# Save them persistently
|
|
save_state(ps_key=ps_key, device_name=device_name)
|
|
|
|
|
|
# 4) Query realtime data on plant level
|
|
realtime = get_device_realtime_data(
|
|
token=token,
|
|
point_id_list = [
|
|
"83022", # Daily Yield of Plant "64800.0" ok
|
|
"83033", # Plant Power "0.0"
|
|
#"83006", # Meter Daily Yield
|
|
#"83011", # Meter E-daily Consumption
|
|
#"83052", # Load Power
|
|
"83072", # Feed-in Energy Today "25400.0" ok
|
|
"83252", # Battery Level (SOC) "0.557" ok
|
|
#"83129", # Battery SOC
|
|
"83009", # Inverter Daily Yield "33400.0" ok, nur Inverter "WR Slave"
|
|
"83097", # Daily Direct Energy Consumption "5900.0" ??
|
|
"83118", # Daily Load Consumption "39400.0" ok
|
|
"83119" # Daily Feed-in Energy (PV) "18900.0" ??
|
|
],
|
|
device_type=11,
|
|
ps_key_list=["5425899_11_0_0"],
|
|
debug=True
|
|
)
|
|
|
|
|
|
|
|
|
|
print("Device List Response:")
|
|
pretty_print(device_list)
|
|
|
|
|
|
#print("Response:")
|
|
#print(data)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|
|
|