mijiaAPI 1.4.1__tar.gz → 1.4.2__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: mijiaAPI
3
- Version: 1.4.1
3
+ Version: 1.4.2
4
4
  Summary: A Python API for Xiaomi Mijia
5
5
  License: GPLv3
6
6
  Author: Do1e
@@ -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
@@ -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')
@@ -446,4 +453,9 @@ def get_device_info(device_model: str) -> dict:
446
453
  'aiid': int(aiid)
447
454
  }
448
455
  })
456
+ if cache_path is not None:
457
+ cache_file = os.path.join(cache_path, f'{device_model}.json')
458
+ os.makedirs(cache_path, exist_ok=True)
459
+ with open(cache_file, 'w', encoding='utf-8') as f:
460
+ json.dump(result, f, indent=2, ensure_ascii=False)
449
461
  return result
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "mijiaAPI"
3
- version = "1.4.1"
3
+ version = "1.4.2"
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.1"
18
+ version = "1.4.2"
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