forked from dingusdk/dukaonesdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.py
75 lines (62 loc) · 1.98 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
"""
Create a file called ".deviceid" in the current folder.
This file should contain the duka smartfan wifi device id.
You can see the duka smartfan wifi device id in the duka app.
"""
import sys
import time
from duka_smartfan_sdk.device import Device
from duka_smartfan_sdk.dukaclient import DukaClient
def onchange(device: Device):
"""Callback function when device changes"""
print(
f"ip: {device.ip_address},"
f" device id: {device.device_id},"
f" is_active: {device.is_active},"
f" fan_speed: {device.fan_speed},"
f" humidity: {device.humidity},"
f" temperature: {device.temperature},"
)
def newdevice_callback(deviceid: str):
print("New device id: " + deviceid)
def main():
"""Main example"""
client: DukaClient = DukaClient()
client.search_devices(newdevice_callback)
time.sleep(5)
# read the device id
with open(".deviceid", "r") as file:
device_id = file.readline().replace("\n", "")
# initialize the client and add the device
device: Device = client.validate_device(device_id)
if device is None:
print("Device does not respond")
exit(1)
device = client.add_device(device_id, password="", onchange=onchange)
print("Device added")
print(f"Firmware version: {device.firmware_version}")
print(f"Firmware date: {device.firmware_date}")
print(f"Unit type: {device.unit_type}")
while True:
print(
"Press one key and enter. "
"1 for boost on, "
"2 for boost off, "
"3 for boost toggle, "
"q for quit"
)
char = sys.stdin.read(2)[0]
if char == "q":
break
if char == "1":
client.turn_boost_on(device)
if char == "2":
client.turn_boost_off(device)
if char == "3":
client.toggle_boost(device)
print("Closing")
client.close()
print("Done")
exit(0)
if __name__ == "__main__":
main()