mijiaAPI 4.2.0__tar.gz → 4.3.0__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,108 +1,108 @@
1
- Metadata-Version: 2.4
2
- Name: mijiaAPI
3
- Version: 4.2.0
4
- Summary: A Python API for Xiaomi Mijia
5
- Author-email: Do1e <i@do1e.cn>
6
- License-Expression: GPL-3.0-or-later
7
- Project-URL: Homepage, https://mijia-api.do1e.com/
8
- Project-URL: Repository, https://github.com/Do1e/mijia-api
9
- Classifier: Programming Language :: Python :: 3
10
- Classifier: Operating System :: OS Independent
11
- Requires-Python: <4.0,>=3.10
12
- Description-Content-Type: text/markdown
13
- License-File: LICENSE
14
- Requires-Dist: fastmcp>=3.4.2
15
- Requires-Dist: pillow>=11.3.0
16
- Requires-Dist: pycryptodome>=3.23.0
17
- Requires-Dist: qrcode>=8.2
18
- Requires-Dist: requests>=2.32.5
19
- Requires-Dist: tzlocal>=5.3.1
20
- Dynamic: license-file
21
-
22
- # mijiaAPI
23
-
24
- 米家 API,可以使用代码、CLI、MCP 直接控制米家设备。
25
-
26
- > 🎉 **v4.0.0 版本已支持 MCP**,详见 [MCP 使用文档](https://mijia-api.do1e.com/usage/mcp)
27
- > 🎉 **v4.1.0 版本已支持 Agent Skill**,详见 [Agent Skill 使用文档](https://mijia-api.do1e.com/usage/skill)
28
-
29
- [![GitHub](https://img.shields.io/badge/GitHub-Do1e%2Fmijia--api-blue)](https://github.com/Do1e/mijia-api)
30
- [![PyPI](https://img.shields.io/badge/PyPI-mijiaAPI-blue)](https://pypi.org/project/mijiaAPI/)
31
- [![License: GPL-3.0](https://img.shields.io/badge/License-GPL--3.0-green.svg)](https://opensource.org/licenses/GPL-3.0)
32
-
33
- 📖 **完整文档请见 [mijia-api.do1e.com](https://mijia-api.do1e.com)**
34
-
35
- [常见问题](https://mijia-api.do1e.com/faq) | [更新日志](https://mijia-api.do1e.com/changelog)
36
-
37
- ## 安装
38
-
39
- > 要求 Python >= 3.10
40
-
41
- ```bash
42
- pip install mijiaAPI
43
- # Or `uv add mijiaAPI` for uv users
44
- ```
45
-
46
- 其他安装方式(源码安装、AUR)请参考[文档](https://mijia-api.do1e.com/guide/installation)。
47
-
48
- ## 快速开始
49
-
50
- ```python
51
- from mijiaAPI import mijiaAPI, mijiaDevice
52
-
53
- # 初始化并扫码登录(认证文件默认保存在 ~/.config/mijia-api/auth.json)
54
- api = mijiaAPI()
55
- api.login()
56
-
57
- # 通过设备名称控制设备(推荐)
58
- device = mijiaDevice(api, dev_name="我的台灯")
59
- device.on = True # 打开设备
60
- device.brightness = 60 # 设置亮度为 60%
61
-
62
- # 查看设备支持的所有属性和动作
63
- print(device)
64
- ```
65
-
66
- CLI 用法:
67
-
68
- ```bash
69
- mijiaAPI login # 扫码登录
70
- mijiaAPI -l # 列出所有设备
71
- mijiaAPI set --dev_name "台灯" --prop_name "brightness" --value 60
72
- ```
73
-
74
- MCP 用法:
75
-
76
- 执行 `uvx mijiaAPI login -p /path/to/auth.json` 登录后,在 MCP 客户端配置中添加以下内容即可接入米家:
77
-
78
- ```json
79
- {
80
- "mcpServers": {
81
- "mijia-api": {
82
- "command": "uvx",
83
- "args": ["mijiaAPI", "mcp", "-p", "/path/to/auth.json"]
84
- }
85
- }
86
- }
87
- ```
88
-
89
- 更多用法(API 基础调用、MCP Server、CLI 完整参数、最佳实践等)请查阅[完整文档](https://mijia-api.do1e.com)。
90
-
91
- ## 致谢
92
-
93
- * [janzlan/mijia-api](https://gitee.com/janzlan/mijia-api/tree/master)
94
- * [米家 APP 网络请求的抓包、加解密与构造的代码笔记](https://imkero.net/posts/mihome-app-api/)
95
- * [al-one/hass-xiaomi-miot](https://github.com/al-one/hass-xiaomi-miot)
96
-
97
- ## 开源许可
98
-
99
- 本项目采用 [GPL-3.0](LICENSE) 开源许可证。
100
-
101
- **请注意:GPL-3.0 是具有“强传染性”的开源许可证。**
102
- 如果您在您的项目中使用、修改或分发本项目的代码(包括作为库依赖),您的整个项目也**必须**以 GPL-3.0 或兼容许可证开源发布。
103
-
104
- ## 免责声明
105
-
106
- * 本项目仅供学习交流使用,不得用于商业用途,如有侵权请联系删除
107
- * 用户使用本项目所产生的任何后果,需自行承担风险
108
- * 开发者不对使用本项目产生的任何直接或间接损失负责
1
+ Metadata-Version: 2.4
2
+ Name: mijiaAPI
3
+ Version: 4.3.0
4
+ Summary: A Python API for Xiaomi Mijia
5
+ Author-email: Do1e <i@do1e.cn>
6
+ License-Expression: GPL-3.0-or-later
7
+ Project-URL: Homepage, https://mijia-api.do1e.com/
8
+ Project-URL: Repository, https://github.com/Do1e/mijia-api
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: <4.0,>=3.10
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+ Requires-Dist: fastmcp>=3.4.2
15
+ Requires-Dist: pillow>=11.3.0
16
+ Requires-Dist: pycryptodome>=3.23.0
17
+ Requires-Dist: qrcode>=8.2
18
+ Requires-Dist: requests>=2.32.5
19
+ Requires-Dist: tzlocal>=5.3.1
20
+ Dynamic: license-file
21
+
22
+ # mijiaAPI
23
+
24
+ 米家 API,可以使用代码、CLI、MCP 直接控制米家设备。
25
+
26
+ > 🎉 **v4.0.0 版本已支持 MCP**,详见 [MCP 使用文档](https://mijia-api.do1e.com/usage/mcp)
27
+ > 🎉 **v4.1.0 版本已支持 Agent Skill**,详见 [Agent Skill 使用文档](https://mijia-api.do1e.com/usage/skill)
28
+
29
+ [![GitHub](https://img.shields.io/badge/GitHub-Do1e%2Fmijia--api-blue)](https://github.com/Do1e/mijia-api)
30
+ [![PyPI](https://img.shields.io/badge/PyPI-mijiaAPI-blue)](https://pypi.org/project/mijiaAPI/)
31
+ [![License: GPL-3.0](https://img.shields.io/badge/License-GPL--3.0-green.svg)](https://opensource.org/licenses/GPL-3.0)
32
+
33
+ 📖 **完整文档请见 [mijia-api.do1e.com](https://mijia-api.do1e.com)**
34
+
35
+ [常见问题](https://mijia-api.do1e.com/faq) | [更新日志](https://mijia-api.do1e.com/changelog)
36
+
37
+ ## 安装
38
+
39
+ > 要求 Python >= 3.10
40
+
41
+ ```bash
42
+ pip install mijiaAPI
43
+ # Or `uv add mijiaAPI` for uv users
44
+ ```
45
+
46
+ 其他安装方式(源码安装、AUR)请参考[文档](https://mijia-api.do1e.com/guide/installation)。
47
+
48
+ ## 快速开始
49
+
50
+ ```python
51
+ from mijiaAPI import mijiaAPI, mijiaDevice
52
+
53
+ # 初始化并扫码登录(认证文件默认保存在 ~/.config/mijia-api/auth.json)
54
+ api = mijiaAPI()
55
+ api.login()
56
+
57
+ # 通过设备名称控制设备(推荐)
58
+ device = mijiaDevice(api, dev_name="我的台灯")
59
+ device.on = True # 打开设备
60
+ device.brightness = 60 # 设置亮度为 60%
61
+
62
+ # 查看设备支持的所有属性和动作
63
+ print(device)
64
+ ```
65
+
66
+ CLI 用法:
67
+
68
+ ```bash
69
+ mijiaAPI login # 扫码登录
70
+ mijiaAPI -l # 列出所有设备
71
+ mijiaAPI set --dev_name "台灯" --prop_name "brightness" --value 60
72
+ ```
73
+
74
+ MCP 用法:
75
+
76
+ 执行 `uvx mijiaAPI login -p /path/to/auth.json` 登录后,在 MCP 客户端配置中添加以下内容即可接入米家:
77
+
78
+ ```json
79
+ {
80
+ "mcpServers": {
81
+ "mijia-api": {
82
+ "command": "uvx",
83
+ "args": ["mijiaAPI", "mcp", "-p", "/path/to/auth.json"]
84
+ }
85
+ }
86
+ }
87
+ ```
88
+
89
+ 更多用法(API 基础调用、MCP Server、CLI 完整参数、最佳实践等)请查阅[完整文档](https://mijia-api.do1e.com)。
90
+
91
+ ## 致谢
92
+
93
+ * [janzlan/mijia-api](https://gitee.com/janzlan/mijia-api/tree/master)
94
+ * [米家 APP 网络请求的抓包、加解密与构造的代码笔记](https://imkero.net/posts/mihome-app-api/)
95
+ * [al-one/hass-xiaomi-miot](https://github.com/al-one/hass-xiaomi-miot)
96
+
97
+ ## 开源许可
98
+
99
+ 本项目采用 [GPL-3.0](LICENSE) 开源许可证。
100
+
101
+ **请注意:GPL-3.0 是具有“强传染性”的开源许可证。**
102
+ 如果您在您的项目中使用、修改或分发本项目的代码(包括作为库依赖),您的整个项目也**必须**以 GPL-3.0 或兼容许可证开源发布。
103
+
104
+ ## 免责声明
105
+
106
+ * 本项目仅供学习交流使用,不得用于商业用途,如有侵权请联系删除
107
+ * 用户使用本项目所产生的任何后果,需自行承担风险
108
+ * 开发者不对使用本项目产生的任何直接或间接损失负责
@@ -112,8 +112,33 @@ def parse_args(args):
112
112
  )
113
113
  run.add_argument(
114
114
  '--quiet',
115
- action='store_true',
116
- help="小爱音箱静默执行",
115
+ action=argparse.BooleanOptionalAction,
116
+ default=True,
117
+ help="小爱音箱静默执行(默认开启;使用 --no-quiet 播报回复)",
118
+ )
119
+
120
+ play = subparsers.add_parser(
121
+ 'play',
122
+ help="通过小爱音箱播放指定文本",
123
+ )
124
+ play.set_defaults(func='play')
125
+ play.add_argument(
126
+ '-p', '--auth_path',
127
+ type=Path,
128
+ default=Path.home() / ".config" / "mijia-api" / "auth.json",
129
+ help="认证文件保存路径,默认保存在 ~/.config/mijia-api/auth.json",
130
+ )
131
+ play.add_argument(
132
+ 'text',
133
+ type=str,
134
+ help="要通过小爱音箱播放的文本",
135
+ metavar='TEXT',
136
+ )
137
+ play.add_argument(
138
+ '--wifispeaker_name',
139
+ type=str,
140
+ help="指定小爱音箱名称,默认是获取到的第一个小爱音箱",
141
+ default=None,
117
142
  )
118
143
 
119
144
  mcp_cmd = subparsers.add_parser(
@@ -507,7 +532,7 @@ def main(args):
507
532
  run_action(api, args)
508
533
  if args.func == 'statistics':
509
534
  get_statistics(api, args)
510
- if args.func == 'run':
535
+ if args.func in ('run', 'play'):
511
536
  if device_mapping is None:
512
537
  device_mapping = get_devices_list(api, verbose=False)
513
538
  if args.wifispeaker_name is None:
@@ -520,7 +545,10 @@ def main(args):
520
545
  raise ValueError("未找到小爱音箱设备")
521
546
  else:
522
547
  wifispeaker = mijiaDevice(api, dev_name=args.wifispeaker_name)
523
- wifispeaker.run_action('execute-text-directive', _in=[args.prompt, 1 if args.quiet else 0])
548
+ if args.func == 'run':
549
+ wifispeaker.run_action('execute-text-directive', _in=[args.prompt, 1 if args.quiet else 0])
550
+ else:
551
+ wifispeaker.run_action('play-text', _in=[args.text])
524
552
 
525
553
  def cli():
526
554
  main(sys.argv[1:])
@@ -314,7 +314,7 @@ def get_device_info(device_model: str, cache_path: Optional[Union[str, Path]] =
314
314
  product = content["props"]["product"]
315
315
  name = product["name"]
316
316
  model = product["model"]
317
- i18n_zh = content["props"]["i18n"]["zh_cn"]
317
+ i18n_zh = content["props"].get("i18n", {}).get("zh_cn", {})
318
318
  result = {
319
319
  "version": device_info_version,
320
320
  "name": name,
@@ -1,4 +1,4 @@
1
- # https://github.com/kekeandzeyu/ha_xiaomi_home/blob/main/custom_components/xiaomi_home/miot/i18n/zh-Hans.json
1
+ # https://github.com/XiaoMi/ha_xiaomi_home/blob/main/custom_components/xiaomi_home/miot/i18n/zh-Hans.json
2
2
  ERROR_CODE = {
3
3
  "-10000": "未知错误",
4
4
  "-10001": "服务不可用",
@@ -305,42 +305,54 @@ def get_statistics(
305
305
  return json.dumps(ret, ensure_ascii=False)
306
306
 
307
307
 
308
+ def _find_speaker(api: mijiaAPI, speaker_name: Optional[str]) -> Optional[dict]:
309
+ devices = api.get_devices_list()
310
+ if speaker_name is not None:
311
+ return next((d for d in devices if d["name"] == speaker_name), None)
312
+ return next((d for d in devices if "xiaomi.wifispeaker" in d["model"]), None)
313
+
314
+
308
315
  @mcp.tool
309
316
  def run_speaker_command(
310
317
  prompt: str,
311
318
  speaker_name: Optional[str] = None,
312
- quiet: bool = False,
319
+ quiet: bool = True,
313
320
  ) -> str:
314
321
  """通过小爱音箱执行自然语言指令。
315
322
 
316
323
  参数:
317
324
  prompt: 自然语言指令,如 "打开卧室台灯"、"把亮度调到50%"。
318
325
  speaker_name: 可选,指定小爱音箱名称,默认使用获取到的第一个小爱音箱。
319
- quiet: 是否静默执行(不语音播报),默认 False
326
+ quiet: 是否静默执行(不语音播报),默认 True
320
327
 
321
328
  返回执行结果。
322
329
  """
323
330
  api = _get_api()
324
331
  _refresh_if_needed(api)
325
- devices = api.get_devices_list()
326
- if speaker_name is None:
327
- match = None
328
- for device in devices:
329
- if "xiaomi.wifispeaker" in device["model"]:
330
- match = device
331
- break
332
- if match is None:
333
- return "未找到小爱音箱设备"
334
- else:
335
- matches = [d for d in devices if d["name"] == speaker_name]
336
- if not matches:
337
- return f"未找到名为 {speaker_name} 的小爱音箱"
338
- match = matches[0]
332
+ match = _find_speaker(api, speaker_name)
333
+ if match is None:
334
+ return "未找到小爱音箱设备" if speaker_name is None else f"未找到名为 {speaker_name} 的小爱音箱"
339
335
  speaker = mijiaDevice(api, did=match["did"])
340
336
  speaker.run_action("execute-text-directive", _in=[prompt, 1 if quiet else 0])
341
337
  return f"已通过 {match['name']} 执行: {prompt}"
342
338
 
343
339
 
340
+ @mcp.tool
341
+ def speaker_play(
342
+ text: str,
343
+ speaker_name: Optional[str] = None,
344
+ ) -> str:
345
+ """通过小爱音箱朗读指定文本(play-text),不是执行设备控制指令。"""
346
+ api = _get_api()
347
+ _refresh_if_needed(api)
348
+ match = _find_speaker(api, speaker_name)
349
+ if match is None:
350
+ return "未找到小爱音箱设备" if speaker_name is None else f"未找到名为 {speaker_name} 的小爱音箱"
351
+ speaker = mijiaDevice(api, did=match["did"])
352
+ speaker.run_action("play-text", _in=[text])
353
+ return f"已通过 {match['name']} 播放: {text}"
354
+
355
+
344
356
  def _login_worker(api: mijiaAPI, login_data: dict) -> None:
345
357
  try:
346
358
  api._complete_qr_login(login_data)
@@ -0,0 +1 @@
1
+ version = "4.3.0"
@@ -1,4 +1,4 @@
1
- [egg_info]
2
- tag_build =
3
- tag_date = 0
4
-
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -1 +0,0 @@
1
- version = "4.2.0"
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
File without changes