mijiaAPI 1.3.8__tar.gz → 1.3.9__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {mijiaapi-1.3.8 → mijiaapi-1.3.9}/PKG-INFO +3 -20
- {mijiaapi-1.3.8 → mijiaapi-1.3.9}/README.md +2 -19
- {mijiaapi-1.3.8 → mijiaapi-1.3.9}/mijiaAPI/login.py +201 -164
- {mijiaapi-1.3.8 → mijiaapi-1.3.9}/mijiaAPI/urls.py +7 -6
- {mijiaapi-1.3.8 → mijiaapi-1.3.9}/pyproject.toml +2 -2
- {mijiaapi-1.3.8 → mijiaapi-1.3.9}/LICENSE +0 -0
- {mijiaapi-1.3.8 → mijiaapi-1.3.9}/mijiaAPI/__init__.py +0 -0
- {mijiaapi-1.3.8 → mijiaapi-1.3.9}/mijiaAPI/apis.py +0 -0
- {mijiaapi-1.3.8 → mijiaapi-1.3.9}/mijiaAPI/code.py +0 -0
- {mijiaapi-1.3.8 → mijiaapi-1.3.9}/mijiaAPI/devices.py +0 -0
- {mijiaapi-1.3.8 → mijiaapi-1.3.9}/mijiaAPI/utils.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: mijiaAPI
|
|
3
|
-
Version: 1.3.
|
|
3
|
+
Version: 1.3.9
|
|
4
4
|
Summary: A Python API for Xiaomi Mijia
|
|
5
5
|
License: GPLv3
|
|
6
6
|
Author: Do1e
|
|
@@ -43,25 +43,6 @@ pip install mijiaAPI
|
|
|
43
43
|
* `login(username: str, password: str) -> dict`:账号密码登录,返回上述信息。**注意,目前这一方法大概率遇到手机验证码,请尽可能使用`QRlogin`。**
|
|
44
44
|
* `QRlogin() -> dict`:扫描二维码登录,返回上述信息(会在支持tty的终端打印二维码,若打印识别可查看当前文件夹下的`qr.png`)
|
|
45
45
|
|
|
46
|
-
**手动登录方法**
|
|
47
|
-
|
|
48
|
-
可以使用浏览器,手动获取`userId`, `ssecurity`, `deviceId`, `serviceToken`。当然我还是更推荐大家使用扫码登录,但大家也可以根据下述步骤了解如何获取这些信息。
|
|
49
|
-
|
|
50
|
-
打开浏览器访问 https://account.xiaomi.com/pass/serviceLogin?sid=xiaomiio&_json=true ,会得到下述信息,复制location中的url到新的界面打开:
|
|
51
|
-
|
|
52
|
-
```text
|
|
53
|
-
&&&START&&&{"serviceParam":"{\"checkSafePhone\":false,\"checkSafeAddress\":false,\"lsrp_score\":0.0}","qs":"%3Fsid%3Dxiaomiio%26_json%3Dtrue","code":70016,"description":"登录验证失败","securityStatus":0,"_sign":"0psXfr43eNI0IX6q9Suk3qWbRqU=","sid":"xiaomiio","result":"error","captchaUrl":null,"callback":"https://sts.api.io.mi.com/sts","location":"https://account.xiaomi.com/fe/service/login?_json=true&sid=xiaomiio&qs=%253Fsid%253Dxiaomiio%2526_json%253Dtrue&callback=.........","pwd":0,"child":0,"desc":"登录验证失败"}
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
打开后会进入小米的登录界面(如果直接显示了`ok`,是因为保存了之前的cookie,建议使用无痕窗口重新开始上述步骤),此时需要先按下 `F12` 打开开发者工具,切换到`Network`选项卡,之后可以输入账号密码或者扫码登录。完成后页面会显示一个`ok`。
|
|
57
|
-
|
|
58
|
-
此时在网络选项卡中按下`Ctrl+F`,搜索上述所需的`userId`, `ssecurity`, `deviceId`, `serviceToken`即可。
|
|
59
|
-
|
|
60
|
-
或者筛选请求:
|
|
61
|
-
1. `https://sts.api.io.mi.com/sts`,其中的`set-cookie`中包含`userId`和`serviceToken`(`=`到`;`前止)。
|
|
62
|
-
2. `https://account.xiaomi.com/pass/serviceLoginAuth2/end`,其中的`extension-pragma`中包含`ssecurity`(`:"`到`"`前止)。
|
|
63
|
-
3. `https://account.xiaomi.com/identity/authStart`,其中的`cookie`中包含`deviceId`(`=`到`;`前止)。
|
|
64
|
-
|
|
65
46
|
|
|
66
47
|
### API
|
|
67
48
|
|
|
@@ -82,6 +63,8 @@ pip install mijiaAPI
|
|
|
82
63
|
|
|
83
64
|
### 针对设备的封装
|
|
84
65
|
|
|
66
|
+
最简单的使用方法是直接使用自然语言调用小爱音箱,参见[demos/test_device_wifispeaker.py](demos/test_device_wifispeaker.py)
|
|
67
|
+
|
|
85
68
|
`mijiaDevices`:使用`mijiaAPI`和设备属性字典初始化,以便更方便地调用设备属性
|
|
86
69
|
* `__init__(api: mijiaAPI, dev_info: dict. did: str = None, sleep_time: float = 0.5)`:初始化,`dev_info`为设备属性,参考[demos/dev_info_example](demos/dev_info_example),`sleep_time`为每次调用设备属性的间隔时间(注:设置属性后立刻获取属性会不符合预期,需要延迟一段时间)
|
|
87
70
|
* `set(name: str, did: str, value: Union[bool, int]) -> Union[bool, int]`:设置设备属性
|
|
@@ -19,25 +19,6 @@ pip install mijiaAPI
|
|
|
19
19
|
* `login(username: str, password: str) -> dict`:账号密码登录,返回上述信息。**注意,目前这一方法大概率遇到手机验证码,请尽可能使用`QRlogin`。**
|
|
20
20
|
* `QRlogin() -> dict`:扫描二维码登录,返回上述信息(会在支持tty的终端打印二维码,若打印识别可查看当前文件夹下的`qr.png`)
|
|
21
21
|
|
|
22
|
-
**手动登录方法**
|
|
23
|
-
|
|
24
|
-
可以使用浏览器,手动获取`userId`, `ssecurity`, `deviceId`, `serviceToken`。当然我还是更推荐大家使用扫码登录,但大家也可以根据下述步骤了解如何获取这些信息。
|
|
25
|
-
|
|
26
|
-
打开浏览器访问 https://account.xiaomi.com/pass/serviceLogin?sid=xiaomiio&_json=true ,会得到下述信息,复制location中的url到新的界面打开:
|
|
27
|
-
|
|
28
|
-
```text
|
|
29
|
-
&&&START&&&{"serviceParam":"{\"checkSafePhone\":false,\"checkSafeAddress\":false,\"lsrp_score\":0.0}","qs":"%3Fsid%3Dxiaomiio%26_json%3Dtrue","code":70016,"description":"登录验证失败","securityStatus":0,"_sign":"0psXfr43eNI0IX6q9Suk3qWbRqU=","sid":"xiaomiio","result":"error","captchaUrl":null,"callback":"https://sts.api.io.mi.com/sts","location":"https://account.xiaomi.com/fe/service/login?_json=true&sid=xiaomiio&qs=%253Fsid%253Dxiaomiio%2526_json%253Dtrue&callback=.........","pwd":0,"child":0,"desc":"登录验证失败"}
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
打开后会进入小米的登录界面(如果直接显示了`ok`,是因为保存了之前的cookie,建议使用无痕窗口重新开始上述步骤),此时需要先按下 `F12` 打开开发者工具,切换到`Network`选项卡,之后可以输入账号密码或者扫码登录。完成后页面会显示一个`ok`。
|
|
33
|
-
|
|
34
|
-
此时在网络选项卡中按下`Ctrl+F`,搜索上述所需的`userId`, `ssecurity`, `deviceId`, `serviceToken`即可。
|
|
35
|
-
|
|
36
|
-
或者筛选请求:
|
|
37
|
-
1. `https://sts.api.io.mi.com/sts`,其中的`set-cookie`中包含`userId`和`serviceToken`(`=`到`;`前止)。
|
|
38
|
-
2. `https://account.xiaomi.com/pass/serviceLoginAuth2/end`,其中的`extension-pragma`中包含`ssecurity`(`:"`到`"`前止)。
|
|
39
|
-
3. `https://account.xiaomi.com/identity/authStart`,其中的`cookie`中包含`deviceId`(`=`到`;`前止)。
|
|
40
|
-
|
|
41
22
|
|
|
42
23
|
### API
|
|
43
24
|
|
|
@@ -58,6 +39,8 @@ pip install mijiaAPI
|
|
|
58
39
|
|
|
59
40
|
### 针对设备的封装
|
|
60
41
|
|
|
42
|
+
最简单的使用方法是直接使用自然语言调用小爱音箱,参见[demos/test_device_wifispeaker.py](demos/test_device_wifispeaker.py)
|
|
43
|
+
|
|
61
44
|
`mijiaDevices`:使用`mijiaAPI`和设备属性字典初始化,以便更方便地调用设备属性
|
|
62
45
|
* `__init__(api: mijiaAPI, dev_info: dict. did: str = None, sleep_time: float = 0.5)`:初始化,`dev_info`为设备属性,参考[demos/dev_info_example](demos/dev_info_example),`sleep_time`为每次调用设备属性的间隔时间(注:设置属性后立刻获取属性会不符合预期,需要延迟一段时间)
|
|
63
46
|
* `set(name: str, did: str, value: Union[bool, int]) -> Union[bool, int]`:设置设备属性
|
|
@@ -1,164 +1,201 @@
|
|
|
1
|
-
import hashlib
|
|
2
|
-
import json
|
|
3
|
-
import os
|
|
4
|
-
import random
|
|
5
|
-
import string
|
|
6
|
-
import sys
|
|
7
|
-
import time
|
|
8
|
-
from urllib import parse
|
|
9
|
-
|
|
10
|
-
from qrcode import QRCode
|
|
11
|
-
import requests
|
|
12
|
-
|
|
13
|
-
from .urls import msgURL, loginURL, qrURL
|
|
14
|
-
from .utils import defaultUA
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
self.
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
self.
|
|
27
|
-
self.
|
|
28
|
-
self.
|
|
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
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
'
|
|
153
|
-
'
|
|
154
|
-
'
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
1
|
+
import hashlib
|
|
2
|
+
import json
|
|
3
|
+
import os
|
|
4
|
+
import random
|
|
5
|
+
import string
|
|
6
|
+
import sys
|
|
7
|
+
import time
|
|
8
|
+
from urllib import parse
|
|
9
|
+
|
|
10
|
+
from qrcode import QRCode
|
|
11
|
+
import requests
|
|
12
|
+
|
|
13
|
+
from .urls import msgURL, loginURL, qrURL, accountURL
|
|
14
|
+
from .utils import defaultUA
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class LoginError(Exception):
|
|
18
|
+
def __init__(self, code: int, message: str):
|
|
19
|
+
self.code = code
|
|
20
|
+
self.message = message
|
|
21
|
+
super().__init__(f'Error code: {code}, message: {message}')
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class mijiaLogin(object):
|
|
25
|
+
def __init__(self, save_auth=True, save_path='jsons/auth.json'):
|
|
26
|
+
self.auth_data = None
|
|
27
|
+
self.save_auth = save_auth
|
|
28
|
+
self.save_path = save_path
|
|
29
|
+
|
|
30
|
+
self.deviceId = ''.join(random.sample(string.digits + string.ascii_letters, 16))
|
|
31
|
+
self.session = requests.Session()
|
|
32
|
+
self.session.headers.update({
|
|
33
|
+
'User-Agent': defaultUA,
|
|
34
|
+
'Accept': '*/*',
|
|
35
|
+
'Accept-Encoding': 'gzip, deflate, br, zstd',
|
|
36
|
+
'Accept-Language': 'zh-CN,zh;q=0.9',
|
|
37
|
+
'Cookie': f'deviceId={self.deviceId}; sdkVersion=3.4.1'
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
def _get_index(self) -> dict[str, str]:
|
|
41
|
+
ret = self.session.get(msgURL)
|
|
42
|
+
if ret.status_code != 200:
|
|
43
|
+
raise LoginError(ret.status_code, f'Failed to get index page, {ret.text}')
|
|
44
|
+
ret_data = json.loads(ret.text[11:])
|
|
45
|
+
data = {'deviceId': self.deviceId}
|
|
46
|
+
data.update({
|
|
47
|
+
k: v for k, v in ret_data.items()
|
|
48
|
+
if k in ['qs', '_sign', 'callback', 'location']
|
|
49
|
+
})
|
|
50
|
+
return data
|
|
51
|
+
|
|
52
|
+
def _get_account(self, user_id: str) -> dict[str, str]:
|
|
53
|
+
ret = self.session.get(accountURL + str(user_id))
|
|
54
|
+
if ret.status_code != 200:
|
|
55
|
+
raise LoginError(ret.status_code, f'Failed to get account page, {ret.text}')
|
|
56
|
+
ret_data = json.loads(ret.text[11:])['data']
|
|
57
|
+
data = {
|
|
58
|
+
k: v for k, v in ret_data.items()
|
|
59
|
+
if k in ['account', 'gender', 'nickName', 'icon']
|
|
60
|
+
}
|
|
61
|
+
return data
|
|
62
|
+
|
|
63
|
+
def _save_auth(self) -> None:
|
|
64
|
+
if self.save_auth and self.auth_data is not None:
|
|
65
|
+
if not os.path.isabs(self.save_path):
|
|
66
|
+
self.save_path = os.path.abspath(self.save_path)
|
|
67
|
+
with open(self.save_path, 'w') as f:
|
|
68
|
+
json.dump(self.auth_data, f, indent=2)
|
|
69
|
+
print(f'Auth data saved to [{self.save_path}]')
|
|
70
|
+
else:
|
|
71
|
+
print('Auth data not saved')
|
|
72
|
+
|
|
73
|
+
def login(self, username: str, password: str) -> dict:
|
|
74
|
+
"""login with username and password
|
|
75
|
+
mijiaLogin.login(username: str, password: str) -> dict
|
|
76
|
+
-------
|
|
77
|
+
@param
|
|
78
|
+
username: str, xiaomi account username(email/phone number/xiaomi id)
|
|
79
|
+
password: str, xiaomi account password
|
|
80
|
+
-------
|
|
81
|
+
@return
|
|
82
|
+
dict, data for authorization, including userId, ssecurity, deviceId, serviceToken
|
|
83
|
+
"""
|
|
84
|
+
warning_msg = 'WARNING: there is a high probability of verification code with account and password. Please try other login methods'
|
|
85
|
+
if sys.stdout.isatty():
|
|
86
|
+
print(f'\033[33;1m{warning_msg}\033[0m')
|
|
87
|
+
else:
|
|
88
|
+
print(warning_msg)
|
|
89
|
+
data = self._get_index()
|
|
90
|
+
post_data = {
|
|
91
|
+
'qs': data['qs'],
|
|
92
|
+
'_sign': data['_sign'],
|
|
93
|
+
'callback': data['callback'],
|
|
94
|
+
'sid': 'xiaomiio',
|
|
95
|
+
'_json': 'true',
|
|
96
|
+
'user': username,
|
|
97
|
+
'hash': (hashlib.md5(password.encode()).hexdigest().upper() + '0' * 32)[:32],
|
|
98
|
+
}
|
|
99
|
+
ret = self.session.post(loginURL, data=post_data)
|
|
100
|
+
if ret.status_code != 200:
|
|
101
|
+
raise LoginError(ret.status_code, f'Failed to post login page, {ret.text}')
|
|
102
|
+
ret_data = json.loads(ret.text[11:])
|
|
103
|
+
if ret_data['code'] != 0:
|
|
104
|
+
raise LoginError(ret_data['code'], ret_data['desc'])
|
|
105
|
+
if 'location' not in ret_data:
|
|
106
|
+
raise LoginError(-1, 'Failed to get location')
|
|
107
|
+
if 'notificationUrl' in ret_data:
|
|
108
|
+
raise LoginError(-1, 'Verification code required, please try other login methods')
|
|
109
|
+
auth_data = {
|
|
110
|
+
'userId': ret_data['userId'],
|
|
111
|
+
'ssecurity': ret_data['ssecurity'],
|
|
112
|
+
'deviceId': data['deviceId'],
|
|
113
|
+
}
|
|
114
|
+
ret = self.session.get(ret_data['location'])
|
|
115
|
+
if ret.status_code != 200:
|
|
116
|
+
raise LoginError(ret.status_code, f'Failed to get location, {ret.text}')
|
|
117
|
+
cookies = self.session.cookies.get_dict()
|
|
118
|
+
auth_data['serviceToken'] = cookies['serviceToken']
|
|
119
|
+
self.auth_data = auth_data
|
|
120
|
+
self.auth_data.update(self._get_account(auth_data['userId']))
|
|
121
|
+
|
|
122
|
+
if self.save_auth:
|
|
123
|
+
self._save_auth()
|
|
124
|
+
return auth_data
|
|
125
|
+
|
|
126
|
+
@staticmethod
|
|
127
|
+
def _print_qr(loginurl: str, box_size: int = 10) -> None:
|
|
128
|
+
print('Scan the QR code below with Mi Home app')
|
|
129
|
+
qr = QRCode(border=1, box_size=box_size)
|
|
130
|
+
qr.add_data(loginurl)
|
|
131
|
+
qr.make_image().save('qr.png')
|
|
132
|
+
try:
|
|
133
|
+
qr.print_ascii(invert=True, tty=True)
|
|
134
|
+
except OSError:
|
|
135
|
+
qr.print_ascii(invert=True, tty=False)
|
|
136
|
+
print('If the QR code can not be scanned, please change the font of the terminal, such as "Maple Mono", "Fira Code", etc.')
|
|
137
|
+
print('Or just use the qr.png file in the current directory.')
|
|
138
|
+
|
|
139
|
+
def QRlogin(self) -> dict:
|
|
140
|
+
"""login with QR code
|
|
141
|
+
mijiaLogin.QRlogin() -> dict
|
|
142
|
+
-------
|
|
143
|
+
@return
|
|
144
|
+
dict, data for authorization, including userId, ssecurity, deviceId, serviceToken
|
|
145
|
+
"""
|
|
146
|
+
data = self._get_index()
|
|
147
|
+
location = data['location']
|
|
148
|
+
location_parsed = parse.parse_qs(parse.urlparse(location).query)
|
|
149
|
+
params = {
|
|
150
|
+
'_qrsize': 240,
|
|
151
|
+
'qs': data['qs'],
|
|
152
|
+
'bizDeviceType': '',
|
|
153
|
+
'callback': data['callback'],
|
|
154
|
+
'_json': 'true',
|
|
155
|
+
'theme': '',
|
|
156
|
+
'sid': 'xiaomiio',
|
|
157
|
+
'needTheme': 'false',
|
|
158
|
+
'showActiveX': 'false',
|
|
159
|
+
'serviceParam': location_parsed['serviceParam'][0],
|
|
160
|
+
'_local': 'zh_CN',
|
|
161
|
+
'_sign': data['_sign'],
|
|
162
|
+
'_dc': str(int(time.time() * 1000)),
|
|
163
|
+
}
|
|
164
|
+
url = qrURL + '?' + parse.urlencode(params)
|
|
165
|
+
ret = self.session.get(url)
|
|
166
|
+
if ret.status_code != 200:
|
|
167
|
+
raise LoginError(ret.status_code, f'Failed to get QR code URL, {ret.text}')
|
|
168
|
+
ret_data = json.loads(ret.text[11:])
|
|
169
|
+
if ret_data['code'] != 0:
|
|
170
|
+
raise LoginError(ret_data['code'], ret_data['desc'])
|
|
171
|
+
loginurl = ret_data['loginUrl']
|
|
172
|
+
self._print_qr(loginurl)
|
|
173
|
+
try:
|
|
174
|
+
ret = self.session.get(ret_data['lp'], timeout=60, headers={'Connection': 'keep-alive'})
|
|
175
|
+
except requests.exceptions.Timeout:
|
|
176
|
+
raise LoginError(-1, 'Timeout, please try again')
|
|
177
|
+
if ret.status_code != 200:
|
|
178
|
+
raise LoginError(ret.status_code, f'Failed to wait for login, {ret.text}')
|
|
179
|
+
ret_data = json.loads(ret.text[11:])
|
|
180
|
+
if ret_data['code'] != 0:
|
|
181
|
+
raise LoginError(ret_data['code'], ret_data['desc'])
|
|
182
|
+
auth_data = {
|
|
183
|
+
'userId': ret_data['userId'],
|
|
184
|
+
'ssecurity': ret_data['ssecurity'],
|
|
185
|
+
'deviceId': data['deviceId'],
|
|
186
|
+
}
|
|
187
|
+
ret = self.session.get(ret_data['location'])
|
|
188
|
+
if ret.status_code != 200:
|
|
189
|
+
raise LoginError(ret.status_code, f'Failed to get location, {ret.text}')
|
|
190
|
+
cookies = self.session.cookies.get_dict()
|
|
191
|
+
auth_data['serviceToken'] = cookies['serviceToken']
|
|
192
|
+
self.auth_data = auth_data
|
|
193
|
+
self.auth_data.update(self._get_account(auth_data['userId']))
|
|
194
|
+
|
|
195
|
+
if self.save_auth:
|
|
196
|
+
self._save_auth()
|
|
197
|
+
return auth_data
|
|
198
|
+
|
|
199
|
+
def __del__(self):
|
|
200
|
+
if os.path.exists('qr.png'):
|
|
201
|
+
os.remove('qr.png')
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
sid = 'xiaomiio'
|
|
2
|
-
msgURL = f'https://account.xiaomi.com/pass/serviceLogin?sid={sid}&_json=true'
|
|
3
|
-
loginURL = 'https://account.xiaomi.com/pass/serviceLoginAuth2'
|
|
4
|
-
qrURL = 'https://account.xiaomi.com/longPolling/loginUrl'
|
|
5
|
-
apiURL = 'https://api.io.mi.com/app'
|
|
6
|
-
deviceURL = 'https://home.miot-spec.com/spec/'
|
|
1
|
+
sid = 'xiaomiio'
|
|
2
|
+
msgURL = f'https://account.xiaomi.com/pass/serviceLogin?sid={sid}&_json=true'
|
|
3
|
+
loginURL = 'https://account.xiaomi.com/pass/serviceLoginAuth2'
|
|
4
|
+
qrURL = 'https://account.xiaomi.com/longPolling/loginUrl'
|
|
5
|
+
apiURL = 'https://api.io.mi.com/app'
|
|
6
|
+
deviceURL = 'https://home.miot-spec.com/spec/'
|
|
7
|
+
accountURL = 'https://account.xiaomi.com/pass2/profile/home?bizFlag=&userId='
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "mijiaAPI"
|
|
3
|
-
version = "1.3.
|
|
3
|
+
version = "1.3.9"
|
|
4
4
|
description = "A Python API for Xiaomi Mijia"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
requires-python = ">=3.9,<4.0"
|
|
@@ -12,7 +12,7 @@ dependencies = [
|
|
|
12
12
|
|
|
13
13
|
[tool.poetry]
|
|
14
14
|
name = "mijiaAPI"
|
|
15
|
-
version = "1.3.
|
|
15
|
+
version = "1.3.9"
|
|
16
16
|
description = "A Python API for Xiaomi Mijia"
|
|
17
17
|
authors = ["Do1e <dpj.email@qq.com>"]
|
|
18
18
|
license = "GPLv3"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|