-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.py
39 lines (28 loc) · 1.06 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
import json
from nhc_hobby_api import NHC
with open('./config.json') as f:
config = json.load(f)
nhc = NHC(hostname=config['nhc']['hostname'])\
.connect(
username=config['nhc']['auth']['username'],
password=config['nhc']['auth']['password']
)\
.wait_until_init_done()
print("Example 1. List devices")
for dev in nhc.devices():
print(dev)
print("\nExample 1. Controlling a device (you will have to update the UUID)")
device = nhc.get_device('0395174f-f595-4267-b65a-8f5d92e63847') # lamp action
# device = nhc.get_device('2666b2d9-0f53-4ece-a16c-108e958cda97') # smart plug
device.control(status='on')
print("\nExample 2. Fetching the NHC version")
print(f"NHC Version in use: {nhc.system_information.sw_versions.nhc_version}\n")
print("Example 3. Show devices in each location")
for location in nhc.locations():
print(location)
for device in location.get_devices():
print(f"- {device}")
print(f" properties: {device.property_definitions}")
# wait to see other events occur
while True:
pass