forked from mac-zhou/midea-msmart
-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
example.py
85 lines (69 loc) · 2.52 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
76
77
78
79
80
81
82
83
84
85
import asyncio
import logging
from msmart.device import AirConditioner as AC
from msmart.discover import Discover
logging.basicConfig(level=logging.INFO)
DEVICE_IP = "YOUR_DEVICE_IP"
DEVICE_PORT = 6444
DEVICE_ID = "YOUR_AC_ID"
# For V3 devices
DEVICE_TOKEN = None # "YOUR_DEVICE_TOKEN"
DEVICE_KEY = None # "YOUR_DEVICE_KEY"
async def main():
# There are 2 ways to connect
# Discover.discover_single can automatically construct a device from IP or hostname
# - V3 devices will be automatically authenticated
# - The Midea cloud will be accessed for V3 devices to fetch the token and key
# device = await Discover.discover_single(DEVICE_IP)
# Manually construct the device
# - See midea-discover to read ID, token and key
device = AC(ip=DEVICE_IP, port=6444, device_id=int(DEVICE_ID))
if DEVICE_TOKEN and DEVICE_KEY:
await device.authenticate(DEVICE_TOKEN, DEVICE_KEY)
# Get device capabilities
await device.get_capabilities()
# Refresh the state
await device.refresh()
print({
'id': device.id,
'ip': device.ip,
"online": device.online,
"supported": device.supported,
'power_state': device.power_state,
'beep': device.beep,
'target_temperature': device.target_temperature,
'operational_mode': device.operational_mode,
'fan_speed': device.fan_speed,
'swing_mode': device.swing_mode,
'eco': device.eco,
'turbo': device.turbo,
'fahrenheit': device.fahrenheit,
'indoor_temperature': device.indoor_temperature,
'outdoor_temperature': device.outdoor_temperature
})
await asyncio.sleep(1)
# Change some device properties and apply them
device.power_state = True
device.beep = False
device.target_temperature = 25
device.operational_mode = AC.OperationalMode.COOL
await device.apply()
print({
'id': device.id,
'ip': device.ip,
"online": device.online,
"supported": device.supported,
'power_state': device.power_state,
'beep': device.beep,
'target_temperature': device.target_temperature,
'operational_mode': device.operational_mode,
'fan_speed': device.fan_speed,
'swing_mode': device.swing_mode,
'eco': device.eco,
'turbo': device.turbo,
'fahrenheit': device.fahrenheit,
'indoor_temperature': device.indoor_temperature,
'outdoor_temperature': device.outdoor_temperature
})
if __name__ == "__main__":
asyncio.run(main())