forked from mac-zhou/midea-msmart
-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from mill1000/msmart-ng
Merge msmart-ng development.
- Loading branch information
Showing
28 changed files
with
2,516 additions
and
2,305 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,85 @@ | ||
import asyncio | ||
import logging | ||
import time | ||
|
||
from msmart.device import air_conditioning as ac | ||
from msmart.device.base import device | ||
|
||
logging.basicConfig(level=logging.DEBUG) | ||
|
||
# first take device's ip and id, port is generally 6444 | ||
# pip3 install msmart; midea-discover | ||
device = ac('YOUR_AC_IP', int('YOUR_AC_ID'), 6444) | ||
# If the device is using protocol 3 (aka 8370) | ||
# you must authenticate with device's k1 and token. | ||
# adb logcat | grep doKeyAgree | ||
device.authenticate('YOUR_AC_K1', 'YOUR_AC_TOKEN') | ||
# Refresh the object with the actual state by querying it | ||
device.get_capabilities() | ||
device.refresh() | ||
print({ | ||
'id': device.id, | ||
'name': device.ip, | ||
'power_state': device.power_state, | ||
'prompt_tone': device.prompt_tone, | ||
'target_temperature': device.target_temperature, | ||
'operational_mode': device.operational_mode, | ||
'fan_speed': device.fan_speed, | ||
'swing_mode': device.swing_mode, | ||
'eco_mode': device.eco_mode, | ||
'turbo_mode': device.turbo_mode, | ||
'fahrenheit': device.fahrenheit, | ||
'indoor_temperature': device.indoor_temperature, | ||
'outdoor_temperature': device.outdoor_temperature | ||
}) | ||
|
||
# Set the state of the device and | ||
device.prompt_tone = True | ||
device.power_state = True | ||
device.prompt_tone = False | ||
device.target_temperature = 25 | ||
device.operational_mode = ac.operational_mode_enum.cool | ||
time.sleep(1) | ||
# commit the changes with apply() | ||
device.apply() | ||
print({ | ||
'id': device.id, | ||
'name': device.ip, | ||
'power_state': device.power_state, | ||
'prompt_tone': device.prompt_tone, | ||
'target_temperature': device.target_temperature, | ||
'operational_mode': device.operational_mode, | ||
'fan_speed': device.fan_speed, | ||
'swing_mode': device.swing_mode, | ||
'eco_mode': device.eco_mode, | ||
'turbo_mode': device.turbo_mode, | ||
'indoor_temperature': device.indoor_temperature, | ||
'outdoor_temperature': device.outdoor_temperature | ||
}) | ||
|
||
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_mode': device.eco_mode, | ||
'turbo_mode': device.turbo_mode, | ||
'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_mode': device.eco_mode, | ||
'turbo_mode': device.turbo_mode, | ||
'fahrenheit': device.fahrenheit, | ||
'indoor_temperature': device.indoor_temperature, | ||
'outdoor_temperature': device.outdoor_temperature | ||
}) | ||
|
||
if __name__ == "__main__": | ||
asyncio.run(main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.