-
Notifications
You must be signed in to change notification settings - Fork 3
/
miio_wrapper.py
99 lines (82 loc) · 2.49 KB
/
miio_wrapper.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# import miio
import miio
import time
import os
target = miio.airconditioningcompanionMCN.AirConditioningCompanionMcn02(
ip = os.environ.get('MCN02_IP'),
token = os.environ.get('MCN02_TOKEN'),
debug = 1,
model = 'lumi.acpartner.mcn02'
)
def miio_get_temp():
return target.raw_command("get_prop",["tar_temp"])[0]
def miio_set_temp(tempvalue):
target.raw_command("set_tar_temp",[int(tempvalue)])
# def miio_get_statu():
# return target.status()
# def miio_get_power():
# if target.raw_command("get_prop",["power"])[0] == "on":
# return 1
# else:
# return 0
def miio_set_power(active):
if active:
target.on()
else:
target.off()
def miio_get_mode():
result = target.raw_command("get_prop",["mode"])[0]
if result == "cool":
return 2
if result == "heat":
return 1
# return 0
def miio_set_mode(number):
if number == 2:
target.raw_command("set_mode",["cool"])
if number == 1:
target.raw_command("set_mode",["heat"])
# def miio_get_fanspeed():
# result = target.raw_command("get_prop",["fan_level"])[0]
# if result == "auto_fan" or result == "large_fan":
# return 100
# if result == "medium_fan":
# return 66
# if result == "small_fan":
# return 33
# def miio_set_fanspeed(number):
# if number == 100:
# target.raw_command("set_fan_level",["large_fan"])
# else:
# if number < 50:
# target.raw_command("set_fan_level",["small_fan"])
# else:
# target.raw_command("set_fan_level",["medium_fan"])
# def miio_get_swing():
# if target.raw_command("get_prop",["ver_swing"])[0] == "on":
# return 1
# else:
# return 0
# def miio_set_swing(active):
# if active:
# target.raw_command("set_ver_swing",["on"])
# else:
# target.raw_command("set_ver_swing",["off"])
def miio_get_load():
return target.raw_command("get_prop",["load_power"])[0]
# https://github.com/ikalchev/HAP-python/blob/dev/pyhap/resources/characteristics.json#L319
def miio_get_mode_new():
result = target.raw_command("get_prop",["power","mode"])
if result[0] == "off":
return 0
else:
if result[1] == "cool":
return 2
else:
return 1
if __name__ == '__main__':
# print(miio_get_statu().is_on)
# print(miio_get_temp())
# print(miio_get_statu().mode == OperationMode.Cool)
print(miio_get_power())
print(miio_get_load())