-
Notifications
You must be signed in to change notification settings - Fork 2
/
example.py
43 lines (33 loc) · 1.83 KB
/
example.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
39
40
41
42
43
import asyncio
from energyflip.energyflip import EnergyFlip
async def main(username: str, password: str):
# Create a new client by supplying username and password
energyflip = EnergyFlip(username, password)
# Authenticate the client by attempting to login
# On success, the user id and authentication are set on the client
await energyflip.authenticate()
print("Auth token: %s" % energyflip._auth_token)
# In order to fetch the current energy consumption,
# we first need to know the id of the customer and
# the sources we can request the current energy consumption of.
# Both the customer id and sources are stored inside the client.
await energyflip.customer_overview()
print("Customer ID: %s" % energyflip._customer_id)
print("Sources: %s" % energyflip._sources)
# Request all actual energy consumption rates of the sources which correspond to the configured
# source_types, by default equal to DEFAULT_SOURCE_TYPES in const.py.
actuals = await energyflip.actuals()
print("Actuals: %s" % actuals)
# current_measurements() is a utility method which combines all steps above and only returns
# the current values for each source, omitting the historical values.
current_measurements = await energyflip.current_measurements()
print("Current measurements: %s" % current_measurements)
# Manually logout the client.
energyflip.invalidate_authentication()
# When authenticated (or when authentication is invalid),
# current_measurements() will automatically try to reauthenticate.
current_measurements = await energyflip.current_measurements()
print("Current measurements after reauthentication: %s" % current_measurements)
if __name__ == '__main__':
loop = asyncio.get_event_loop()
loop.run_until_complete(main("[email protected]", "password"))