-
Notifications
You must be signed in to change notification settings - Fork 1
/
how_to.py
38 lines (30 loc) · 1.27 KB
/
how_to.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import pyhfs
import os
import logging
from datetime import datetime, timezone
def how_to(user: str, password: str):
'''
Demonstrates how to log in FusionSolar, query plants list and hourly data.
'''
try:
with pyhfs.ClientSession(user=user, password=password) as client:
plants = client.get_plant_list()
print('Plants list:\n' + str(plants))
# Extract list of plant codes
plants_code = [plant['plantCode'] for plant in plants]
# Query latest hourly data for all plants
hourly = client.get_plant_hourly_data(
plants_code, datetime.now(timezone.utc))
print('Hourly KPIs:\n' + str(hourly))
except pyhfs.LoginFailed:
logging.error(
'Login failed. Verify user and password of Northbound API account.')
except pyhfs.FrequencyLimit:
logging.error('FusionSolar interface access frequency is too high.')
except pyhfs.Permission:
logging.error(
'Missing permission to access FusionSolar Northbound interface.')
if __name__ == '__main__':
user = os.environ.get('FUSIONSOLAR_USER', 'unknown_user')
password = os.environ.get('FUSIONSOLAR_PASSWORD', 'unknown_password')
how_to(user=user, password=password)