-
Notifications
You must be signed in to change notification settings - Fork 493
Expand file tree
/
Copy pathtest_lifaair
More file actions
44 lines (36 loc) · 1.26 KB
/
test_lifaair
File metadata and controls
44 lines (36 loc) · 1.26 KB
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
import time
import broadlink
from broadlink.purifier import lifaair, FanMode
def print_state(state: dict):
temperature = state["temperature"]
humidity = state["humidity"]
print("-> Temperature=%s Humidity=%s CO2=%4dppm TVOC=%4dug/m3 PM2.5=%2dug/m3 FanSpeed=%d (%s)" % (
"%2.1fC" % temperature if temperature is not None else "-----",
"%2d%%" %humidity if humidity is not None else "---",
state["co2"],
state["tvoc"],
state["pm2_5"],
state["fan_speed"],
state["fan_mode"]))
print("Searching for lifaair devices... ")
dev: lifaair = next(dev for dev in broadlink.discover() if isinstance(dev, lifaair))
print("Found %s" % dev)
print("Authenticating... ", end="")
dev.auth()
print("OK (id=%d, key=%s)" % (dev.id, dev.aes.algorithm.key.hex()))
print("Getting firmware version... ", end="")
print(dev.get_fwversion())
print("Getting state...")
print_state(dev.get_state())
for mode in FanMode:
print("Setting fan mode to %s" % mode)
print_state(dev.set_fan_mode(mode))
time.sleep(5)
for speed in (0, 60, 121):
print("Setting fan speed to %d" % speed)
print_state(dev.set_fan_speed(speed))
time.sleep(5)
print("Monitoring state...")
while True:
print_state(dev.get_state())
time.sleep(1)