1- """Example application."""
1+ """
2+ Example application.
3+ Demonstrates usage of the SoliscloudAPI class to interact with the Soliscloud
4+ API. It also shows how to use the Helpers class for common tasks.
5+ Fill in your own API key and secret in config.json before running.
6+ """
7+
28import asyncio
39import logging
410import json
511
612from aiohttp import ClientSession
713
8- from soliscloud_api import SoliscloudAPI
9- from soliscloud_api .helpers import Helpers
14+ from soliscloud_api import SoliscloudAPI , SoliscloudError , \
15+ SoliscloudHttpError , SoliscloudTimeoutError , SoliscloudApiError , \
16+ Helpers
1017
1118
1219logging .basicConfig (level = logging .DEBUG )
@@ -29,52 +36,54 @@ async def main():
2936 soliscloud = SoliscloudAPI (
3037 'https://soliscloud.com:13333' , websession )
3138
32- # Retrieves list of Stations, a.k.a. plants,
33- # containing the inverters.
39+ # Retrieve list of Stations, a.k.a. plants
3440 station_list = await soliscloud .user_station_list (
35- api_key , api_secret , page_no = 1 , page_size = 100 )
36- # Australian accounts require nmi, uncomment if required.
37- # (NOT TESTED!)
38- # station_list = await soliscloud.user_station_list(
39- # api_key, api_secret, page_no=1,
40- # page_size=100, nmi_code=api_nmi)
41+ api_key , api_secret , page_no = 1 , page_size = 100 ,
42+ # Australian accounts require nmi, uncomment if required.
43+ # (NOT TESTED!)
44+ # nmi_code=api_nmi
45+ )
4146 station_list_json = json .dumps (station_list , indent = 2 )
42- # Use helper class as alternative
47+ # Use helper class as alternative to directly retrieve station id's
4348 station_ids = await Helpers .get_station_ids (
4449 soliscloud , api_key , api_secret )
4550
46- # Get inverters for all stations
51+ # Get inverter data for all stations
4752 inverter_list = await soliscloud .inverter_list (
48- api_key , api_secret , page_no = 1 , page_size = 100 )
49- # Australian accounts require nmi, uncomment if required.
50- # (NOT TESTED!)
51- # inverter_list = await soliscloud.inverter_list(
52- # api_key, api_secret, page_no=1,
53- # page_size=100, nmi_code=api_nmi)
53+ api_key , api_secret , page_no = 1 , page_size = 100 ,
54+ # Australian accounts require nmi, uncomment if required.
55+ # (NOT TESTED!)
56+ # nmi_code=api_nmi
57+ )
5458 inverter_list_json = json .dumps (inverter_list , indent = 2 )
55- # Use helper class as alternative
56- inverter_ids = await Helpers .get_inverter_ids (
57- soliscloud , api_key , api_secret )
59+ # Use helper class to retrieve all inverter id's
60+ inverter_ids = Helpers .get_inverter_ids_from_response (
61+ inverter_list )
5862
59- inverter_detail = await soliscloud .inverter_detail (
60- api_key , api_secret , inverter_id = inverter_ids [0 ])
61- inverter_detail_json = json .dumps (inverter_detail , indent = 2 )
63+ # Get detailed data for all inverters
64+ idl = await soliscloud .inverter_detail_list (api_key , api_secret )
65+ idl_json = json .dumps (idl , indent = 2 )
66+
67+ # Use serial number of first inverter to get details
68+ # (should be same as first in inverter_list)
69+ inverter_x = await soliscloud .inverter_detail (
70+ api_key , api_secret , inverter_sn = inverter_list [0 ]['sn' ])
71+ inverter_detail_json = json .dumps (inverter_x , indent = 2 )
6272
6373 # Get data collectors for all stations
6474 collector_list = await soliscloud .collector_list (
65- api_key , api_secret , page_no = 1 , page_size = 100 )
66- # Australian accounts require nmi, uncomment if required.
67- # (NOT TESTED!)
68- # collector_list = await soliscloud.collector_list(
69- # api_key, api_secret, page_no=1,
70- # page_size=100, nmi_code=api_nmi)
75+ api_key , api_secret , page_no = 1 , page_size = 100 ,
76+ # Australian accounts require nmi, uncomment if required.
77+ # (NOT TESTED!)
78+ # nmi_code=api_nmi
79+ )
7180 collector_list_json = json .dumps (collector_list , indent = 2 )
7281
7382 except (
74- SoliscloudAPI . SolisCloudError ,
75- SoliscloudAPI . HttpError ,
76- SoliscloudAPI . TimeoutError ,
77- SoliscloudAPI . ApiError ,
83+ SoliscloudError ,
84+ SoliscloudHttpError ,
85+ SoliscloudTimeoutError ,
86+ SoliscloudApiError ,
7887 ) as error :
7988 print (f"Error: { error } " )
8089 else :
@@ -88,14 +97,32 @@ async def main():
8897 print (f"{ inverter_list_json } " )
8998
9099 print ("InverterDetails call success:" )
91- print (f"{ inverter_detail_json } " )
100+ print (inverter_detail_json )
101+ for key in ['iA' , 'uA' , 'pA' , 'iB' , 'uB' , 'pB' , 'iC' , 'uC' , 'pC' ]:
102+ print (f"{ key } : { inverter_x [key ]} " )
92103
93104 print ("Helper call success:" )
94105 print (f"{ inverter_ids } " )
95106
96107 print ("CollectorList call success:" )
97108 print (f"{ collector_list_json } " )
98109
110+ print ("InverterDetailList call success:" )
111+ print (idl_json )
112+ for key in [
113+ 'iAc1' ,
114+ 'uAc1' ,
115+ 'pA' ,
116+ 'iB' ,
117+ 'uB' ,
118+ 'pB' ,
119+ 'iC' ,
120+ 'uC' ,
121+ 'pC' ,
122+ 'apparentPower'
123+ ]:
124+ print (f"{ key } : { idl [0 ][key ]} " )
125+
99126loop = asyncio .new_event_loop ()
100127loop .run_until_complete (main ())
101128loop .close ()
0 commit comments