Skip to content

Commit 007a9ec

Browse files
committed
Add example
1 parent ebe2760 commit 007a9ec

1 file changed

Lines changed: 54 additions & 0 deletions

File tree

example.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
"""Sample script to use the Python API client for the Elmax Cloud service."""
2+
import asyncio
3+
import pprint
4+
5+
from elmax import Elmax
6+
7+
USERNAME = "username"
8+
PASSWORD = "password"
9+
PIN = "12345678"
10+
11+
12+
async def main():
13+
"""The main part of the example script."""
14+
15+
client = Elmax(username=USERNAME, password=PASSWORD)
16+
await client.connect()
17+
print("Is authenticated?", client.authorized)
18+
19+
devices = await client.list_devices()
20+
21+
print("Available devices:")
22+
pprint.pprint(devices)
23+
24+
print()
25+
# Get all units
26+
units = {}
27+
for unit in devices:
28+
if unit["online"]:
29+
print("Device online?", bool(unit["online"]))
30+
print("Device ID:", unit["hash"])
31+
print("Availables units:")
32+
units = await client.get_units(unit["hash"], PIN)
33+
34+
print("Zones:")
35+
pprint.pprint(client.zones)
36+
print("Outputs:")
37+
pprint.pprint(client.outputs)
38+
print("Areas:")
39+
pprint.pprint(client.areas)
40+
41+
print()
42+
# Get the state of an entity
43+
entity = client.zones[2]
44+
print("Entity:", entity["nome"])
45+
state = await client.get_status(entity["endpointId"])
46+
print("State?", state["esclusa"])
47+
entity = client.zones[5]
48+
print("Entity:", entity["nome"])
49+
state = await client.get_status(entity["endpointId"])
50+
print("State?", state["esclusa"])
51+
52+
53+
loop = asyncio.get_event_loop()
54+
loop.run_until_complete(main())

0 commit comments

Comments
 (0)