mijiaAPI 1.4.1__tar.gz → 1.4.3__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.4.1 → mijiaapi-1.4.3}/PKG-INFO +1 -1
- {mijiaapi-1.4.1 → mijiaapi-1.4.3}/mijiaAPI/__main__.py +6 -6
- {mijiaapi-1.4.1 → mijiaapi-1.4.3}/mijiaAPI/devices.py +23 -5
- {mijiaapi-1.4.1 → mijiaapi-1.4.3}/pyproject.toml +2 -2
- {mijiaapi-1.4.1 → mijiaapi-1.4.3}/LICENSE +0 -0
- {mijiaapi-1.4.1 → mijiaapi-1.4.3}/README.md +0 -0
- {mijiaapi-1.4.1 → mijiaapi-1.4.3}/mijiaAPI/__init__.py +0 -0
- {mijiaapi-1.4.1 → mijiaapi-1.4.3}/mijiaAPI/apis.py +0 -0
- {mijiaapi-1.4.1 → mijiaapi-1.4.3}/mijiaAPI/code.py +0 -0
- {mijiaapi-1.4.1 → mijiaapi-1.4.3}/mijiaAPI/logger.py +0 -0
- {mijiaapi-1.4.1 → mijiaapi-1.4.3}/mijiaAPI/login.py +0 -0
- {mijiaapi-1.4.1 → mijiaapi-1.4.3}/mijiaAPI/urls.py +0 -0
- {mijiaapi-1.4.1 → mijiaapi-1.4.3}/mijiaAPI/utils.py +0 -0
|
@@ -15,8 +15,8 @@ def parse_args(args):
|
|
|
15
15
|
parser.add_argument(
|
|
16
16
|
'-p', '--auth_path',
|
|
17
17
|
type=str,
|
|
18
|
-
default=os.path.join(os.path.expanduser("~"), ".config", "mijia-api-auth.json"),
|
|
19
|
-
help="认证文件保存路径,默认保存在~/.config/mijia-api-auth.json",
|
|
18
|
+
default=os.path.join(os.path.expanduser("~"), ".config/mijia-api", "mijia-api-auth.json"),
|
|
19
|
+
help="认证文件保存路径,默认保存在~/.config/mijia-api/mijia-api-auth.json",
|
|
20
20
|
)
|
|
21
21
|
parser.add_argument(
|
|
22
22
|
'-l', '--list_devices',
|
|
@@ -77,8 +77,8 @@ def parse_args(args):
|
|
|
77
77
|
get.add_argument(
|
|
78
78
|
'-p', '--auth_path',
|
|
79
79
|
type=str,
|
|
80
|
-
default=os.path.join(os.path.expanduser("~"), ".config", "mijia-api-auth.json"),
|
|
81
|
-
help="认证文件保存路径,默认保存在~/.config/mijia-api-auth.json",
|
|
80
|
+
default=os.path.join(os.path.expanduser("~"), ".config/mijia-api", "mijia-api-auth.json"),
|
|
81
|
+
help="认证文件保存路径,默认保存在~/.config/mijia-api/mijia-api-auth.json",
|
|
82
82
|
)
|
|
83
83
|
get.add_argument(
|
|
84
84
|
'--dev_name',
|
|
@@ -101,8 +101,8 @@ def parse_args(args):
|
|
|
101
101
|
set.add_argument(
|
|
102
102
|
'-p', '--auth_path',
|
|
103
103
|
type=str,
|
|
104
|
-
default=os.path.join(os.path.expanduser("~"), ".config", "mijia-api-auth.json"),
|
|
105
|
-
help="认证文件保存路径,默认保存在~/.config/mijia-api-auth.json",
|
|
104
|
+
default=os.path.join(os.path.expanduser("~"), ".config/mijia-api", "mijia-api-auth.json"),
|
|
105
|
+
help="认证文件保存路径,默认保存在~/.config/mijia-api/mijia-api-auth.json",
|
|
106
106
|
)
|
|
107
107
|
set.add_argument(
|
|
108
108
|
'--dev_name',
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
from typing import Union, Optional
|
|
2
2
|
import json
|
|
3
|
+
import os
|
|
3
4
|
import re
|
|
4
5
|
import requests
|
|
5
6
|
from time import sleep
|
|
@@ -169,7 +170,7 @@ class mijiaDevices(object):
|
|
|
169
170
|
raise ValueError(f'Unsupported property: {name}, available properties: {list(self.prop_list.keys())}')
|
|
170
171
|
prop = self.prop_list[name]
|
|
171
172
|
if 'w' not in prop.rw:
|
|
172
|
-
raise ValueError(f'Property {name}
|
|
173
|
+
raise ValueError(f'Property {name} can not be written')
|
|
173
174
|
if prop.value_list:
|
|
174
175
|
if value not in [item['value'] for item in prop.value_list]:
|
|
175
176
|
raise ValueError(f'Invalid value: {value}, should be in {prop.value_list}')
|
|
@@ -273,7 +274,7 @@ class mijiaDevices(object):
|
|
|
273
274
|
raise ValueError(f'Unsupported property: {name}, available properties: {list(self.prop_list.keys())}')
|
|
274
275
|
prop = self.prop_list[name]
|
|
275
276
|
if 'r' not in prop.rw:
|
|
276
|
-
raise ValueError(f'Property {name}
|
|
277
|
+
raise ValueError(f'Property {name} can not be read')
|
|
277
278
|
method = prop.method.copy()
|
|
278
279
|
method['did'] = did
|
|
279
280
|
result = self.api.get_devices_prop([method])[0]
|
|
@@ -370,12 +371,13 @@ class mijiaDevices(object):
|
|
|
370
371
|
return result['code'] == 0
|
|
371
372
|
|
|
372
373
|
|
|
373
|
-
def get_device_info(device_model: str) -> dict:
|
|
374
|
+
def get_device_info(device_model: str, cache_path: Optional[str] = os.path.join(os.path.expanduser("~"), ".config/mijia-api")) -> dict:
|
|
374
375
|
"""
|
|
375
376
|
获取设备信息,用于初始化mijiaDevices对象。
|
|
376
377
|
|
|
377
378
|
Args:
|
|
378
379
|
device_model (str): 设备型号,从get_devices_list获取。
|
|
380
|
+
cache_path (str, optional): 缓存文件路径。默认为~/.config/mijia-api,设置为None则不使用缓存。
|
|
379
381
|
|
|
380
382
|
Returns:
|
|
381
383
|
dict: 设备信息字典。
|
|
@@ -383,6 +385,11 @@ def get_device_info(device_model: str) -> dict:
|
|
|
383
385
|
Raises:
|
|
384
386
|
RuntimeError: 如果获取设备信息失败。
|
|
385
387
|
"""
|
|
388
|
+
if cache_path is not None:
|
|
389
|
+
cache_file = os.path.join(cache_path, f'{device_model}.json')
|
|
390
|
+
if os.path.exists(cache_file):
|
|
391
|
+
with open(cache_file, 'r', encoding='utf-8') as f:
|
|
392
|
+
return json.load(f)
|
|
386
393
|
response = requests.get(deviceURL + device_model)
|
|
387
394
|
if response.status_code != 200:
|
|
388
395
|
raise RuntimeError(f'Failed to get device info')
|
|
@@ -392,9 +399,15 @@ def get_device_info(device_model: str) -> dict:
|
|
|
392
399
|
content = content.group(1)
|
|
393
400
|
content = json.loads(content.replace('"', '"'))
|
|
394
401
|
|
|
402
|
+
if content['props']['product']:
|
|
403
|
+
name = content['props']['product']['name']
|
|
404
|
+
model = content['props']['product']['model']
|
|
405
|
+
else:
|
|
406
|
+
name = content['props']['spec']['name']
|
|
407
|
+
model = device_model
|
|
395
408
|
result = {
|
|
396
|
-
'name':
|
|
397
|
-
'model':
|
|
409
|
+
'name': name,
|
|
410
|
+
'model': model,
|
|
398
411
|
'properties': [],
|
|
399
412
|
'actions': []
|
|
400
413
|
}
|
|
@@ -446,4 +459,9 @@ def get_device_info(device_model: str) -> dict:
|
|
|
446
459
|
'aiid': int(aiid)
|
|
447
460
|
}
|
|
448
461
|
})
|
|
462
|
+
if cache_path is not None:
|
|
463
|
+
cache_file = os.path.join(cache_path, f'{device_model}.json')
|
|
464
|
+
os.makedirs(cache_path, exist_ok=True)
|
|
465
|
+
with open(cache_file, 'w', encoding='utf-8') as f:
|
|
466
|
+
json.dump(result, f, indent=2, ensure_ascii=False)
|
|
449
467
|
return result
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "mijiaAPI"
|
|
3
|
-
version = "1.4.
|
|
3
|
+
version = "1.4.3"
|
|
4
4
|
description = "A Python API for Xiaomi Mijia"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
requires-python = ">=3.9,<4.0"
|
|
@@ -15,7 +15,7 @@ mijiaAPI = "mijiaAPI.__main__:cli"
|
|
|
15
15
|
|
|
16
16
|
[tool.poetry]
|
|
17
17
|
name = "mijiaAPI"
|
|
18
|
-
version = "1.4.
|
|
18
|
+
version = "1.4.3"
|
|
19
19
|
description = "A Python API for Xiaomi Mijia"
|
|
20
20
|
authors = ["Do1e <dpj.email@qq.com>"]
|
|
21
21
|
license = "GPLv3"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|