mijiaAPI 4.1.1__tar.gz → 4.1.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.
Files changed (29) hide show
  1. mijiaapi-4.1.2/MANIFEST.in +3 -0
  2. {mijiaapi-4.1.1/mijiaAPI.egg-info → mijiaapi-4.1.2}/PKG-INFO +2 -2
  3. {mijiaapi-4.1.1 → mijiaapi-4.1.2}/mijiaAPI/mcp_server.py +11 -1
  4. mijiaapi-4.1.2/mijiaAPI/version.py +1 -0
  5. mijiaapi-4.1.2/mijiaAPI.egg-info/SOURCES.txt +15 -0
  6. {mijiaapi-4.1.1 → mijiaapi-4.1.2}/pyproject.toml +1 -1
  7. mijiaapi-4.1.1/.github/ISSUE_TEMPLATE/bug_report.md +0 -84
  8. mijiaapi-4.1.1/PKG-INFO +0 -108
  9. mijiaapi-4.1.1/demos/test_apis.py +0 -116
  10. mijiaapi-4.1.1/demos/test_get_statistics.py +0 -35
  11. mijiaapi-4.1.1/demos/test_login.py +0 -12
  12. mijiaapi-4.1.1/mijiaAPI/version.py +0 -1
  13. mijiaapi-4.1.1/mijiaAPI.egg-info/SOURCES.txt +0 -24
  14. mijiaapi-4.1.1/mijiaAPI.egg-info/dependency_links.txt +0 -1
  15. mijiaapi-4.1.1/mijiaAPI.egg-info/entry_points.txt +0 -2
  16. mijiaapi-4.1.1/mijiaAPI.egg-info/requires.txt +0 -6
  17. mijiaapi-4.1.1/mijiaAPI.egg-info/top_level.txt +0 -1
  18. {mijiaapi-4.1.1 → mijiaapi-4.1.2}/.gitignore +0 -0
  19. {mijiaapi-4.1.1 → mijiaapi-4.1.2}/LICENSE +0 -0
  20. {mijiaapi-4.1.1 → mijiaapi-4.1.2}/README.md +0 -0
  21. {mijiaapi-4.1.1 → mijiaapi-4.1.2}/mijiaAPI/__init__.py +0 -0
  22. {mijiaapi-4.1.1 → mijiaapi-4.1.2}/mijiaAPI/__main__.py +0 -0
  23. {mijiaapi-4.1.1 → mijiaapi-4.1.2}/mijiaAPI/apis.py +0 -0
  24. {mijiaapi-4.1.1 → mijiaapi-4.1.2}/mijiaAPI/devices.py +0 -0
  25. {mijiaapi-4.1.1 → mijiaapi-4.1.2}/mijiaAPI/errors.py +0 -0
  26. {mijiaapi-4.1.1 → mijiaapi-4.1.2}/mijiaAPI/logger.py +0 -0
  27. {mijiaapi-4.1.1 → mijiaapi-4.1.2}/mijiaAPI/miutils.py +0 -0
  28. {mijiaapi-4.1.1 → mijiaapi-4.1.2}/setup.cfg +0 -0
  29. {mijiaapi-4.1.1 → mijiaapi-4.1.2}/uv.lock +0 -0
@@ -0,0 +1,3 @@
1
+ prune demos
2
+ prune .github
3
+ prune mijiaAPI.egg-info
@@ -1,10 +1,10 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mijiaAPI
3
- Version: 4.1.1
3
+ Version: 4.1.2
4
4
  Summary: A Python API for Xiaomi Mijia
5
5
  Author-email: Do1e <i@do1e.cn>
6
6
  License-Expression: GPL-3.0-or-later
7
- Project-URL: Homepage, https://github.com/Do1e/mijia-api
7
+ Project-URL: Homepage, https://mijia-api.do1e.com/
8
8
  Project-URL: Repository, https://github.com/Do1e/mijia-api
9
9
  Classifier: Programming Language :: Python :: 3
10
10
  Classifier: Operating System :: OS Independent
@@ -90,11 +90,21 @@ def list_devices(home_id: Optional[str] = None) -> str:
90
90
  参数:
91
91
  home_id: 可选,指定家庭ID则仅列出该家庭的设备;不传则列出所有设备。
92
92
 
93
- 返回每个设备的名称、did、model、在线状态等。
93
+ 返回每个设备的名称、did、model、在线状态以及所属家庭(home)和房间(room)等。
94
94
  """
95
95
  api = _get_api()
96
96
  _refresh_if_needed(api)
97
97
  devices = api.get_devices_list() + api.get_shared_devices_list()
98
+ homes = api.get_homes_list()
99
+ did_location = {}
100
+ for home in homes:
101
+ for room in home.get('roomlist', []):
102
+ for did in room.get('dids', []) or []:
103
+ did_location[did] = (home['name'], room['name'])
104
+ for device in devices:
105
+ home_name, room_name = did_location.get(device['did'], ("未知", "未知"))
106
+ device['home'] = home_name
107
+ device['room'] = room_name
98
108
  if home_id is not None:
99
109
  devices = [d for d in devices if d.get("home_id") == home_id]
100
110
  return json.dumps(devices, ensure_ascii=False)
@@ -0,0 +1 @@
1
+ version = "4.1.2"
@@ -0,0 +1,15 @@
1
+ .gitignore
2
+ LICENSE
3
+ MANIFEST.in
4
+ README.md
5
+ pyproject.toml
6
+ uv.lock
7
+ mijiaAPI/__init__.py
8
+ mijiaAPI/__main__.py
9
+ mijiaAPI/apis.py
10
+ mijiaAPI/devices.py
11
+ mijiaAPI/errors.py
12
+ mijiaAPI/logger.py
13
+ mijiaAPI/mcp_server.py
14
+ mijiaAPI/miutils.py
15
+ mijiaAPI/version.py
@@ -30,7 +30,7 @@ include = ["mijiaAPI"]
30
30
  version = {attr = "mijiaAPI.version.version"}
31
31
 
32
32
  [project.urls]
33
- Homepage = "https://github.com/Do1e/mijia-api"
33
+ Homepage = "https://mijia-api.do1e.com/"
34
34
  Repository = "https://github.com/Do1e/mijia-api"
35
35
 
36
36
  [dependency-groups]
@@ -1,84 +0,0 @@
1
- ---
2
- name: Bug report
3
- about: 提交一个遇到的bug
4
- title: "[BUG]"
5
- labels: bug
6
- assignees: ''
7
-
8
- ---
9
-
10
- <!--
11
- 感谢使用mijia-api!如果您遇到了任何问题或发现了错误,请按照以下格式提交您的Bug报告。这将帮助我们更快地定位并解决问题。
12
-
13
- 如何提交一个有效的Bug报告:
14
-
15
- 1. **确保这是一个Bug**:请先查阅[已知问题](https://github.com/Do1e/mijia-api/issues?q=is%3Aissue%20label%3Awontfix),确认您的问题不是已知的问题或是配置不当造成的。
16
- 2. **尝试重现问题**:在不同的环境或条件下尝试重现此问题,以确定是否总是发生。
17
- 3. **搜索现有问题**:查看现有的[Issue列表](https://github.com/Do1e/mijia-api/issues),确认这个问题还没有被报告过。
18
- 4. **提供详细信息**:
19
- - 您的操作系统和版本。
20
- - Python版本。
21
- - 项目的版本号。
22
- - 出现问题的具体步骤。
23
- - 实际行为与预期行为之间的差异。
24
- - 如果可能的话,附上相关的日志输出或截图。
25
- -->
26
-
27
- ## 报告模板
28
-
29
- ### 基本信息
30
-
31
- - **操作系统**: [例如: Windows 10, macOS Big Sur, Ubuntu 20.04]
32
- - **Python版本**: [例如: 3.8.5]
33
- - **项目版本**: [例如: 1.0.0]
34
- - **设备model**: [例如: "lumi.acpartner.v2"]
35
-
36
- ### 描述问题
37
-
38
- <!-- 简短描述遇到的问题是什么。 -->
39
-
40
- #### 步骤到复现
41
- <!--
42
- 1. 第一步...
43
- 2. 第二步...
44
- 3. 等等...
45
- -->
46
-
47
- #### 实际结果
48
- <!--
49
- 这里写实际发生了什么。
50
- -->
51
-
52
-
53
- #### 预期结果
54
- <!--
55
- 这里写你期望看到的结果是什么样的。
56
- -->
57
-
58
- #### 报错堆栈
59
- <!--
60
- 复制并在这里粘贴Python的完整报错堆栈。
61
- -->
62
-
63
- #### 日志信息
64
- <!--
65
- 在代码开头加上:
66
- ```python
67
- import logging
68
- logging.getLogger("mijiaAPI").setLevel(logging.DEBUG)
69
- ```
70
- 然后运行代码,复制并粘贴相关的日志输出,请注意手动隐藏任何敏感信息(如did、token等)。
71
- -->
72
-
73
- ### 附加信息
74
- <!--
75
- 如果有更多的上下文可以帮助我们理解问题所在,请在这里添加。比如错误消息、堆栈跟踪等。
76
- -->
77
-
78
-
79
-
80
- ---
81
-
82
- <!--
83
- 再次感谢您的贡献!通过您的帮助,我们可以让这个项目变得更好。
84
- -->
mijiaapi-4.1.1/PKG-INFO DELETED
@@ -1,108 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: mijiaAPI
3
- Version: 4.1.1
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://github.com/Do1e/mijia-api
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,116 +0,0 @@
1
- import json
2
- import logging
3
- import time
4
-
5
- from mijiaAPI import mijiaAPI
6
-
7
-
8
- logging.getLogger("mijiaAPI").setLevel(logging.DEBUG)
9
-
10
- api = mijiaAPI(".mijia-api-data/auth.json")
11
-
12
- # ----------------------- get homes list -----------------------
13
- homes = api.get_homes_list()
14
- with open(".mijia-api-data/homes.json", "w", encoding="utf-8") as f:
15
- json.dump(homes, f, ensure_ascii=False, indent=2)
16
- time.sleep(1)
17
- home_id = homes[0]['id']
18
- home_name = homes[0]['name']
19
-
20
- # ---------------------- get devices list ----------------------
21
- devices = api.get_devices_list()
22
- with open(".mijia-api-data/devices.json", "w", encoding="utf-8") as f:
23
- json.dump(devices, f, ensure_ascii=False, indent=2)
24
- time.sleep(1)
25
-
26
- # -------------------- get shared homes list -------------------
27
- shared_devices = api.get_shared_devices_list()
28
- with open(".mijia-api-data/shared_devices.json", "w", encoding="utf-8") as f:
29
- json.dump(shared_devices, f, ensure_ascii=False, indent=2)
30
- time.sleep(1)
31
-
32
- # ------------------ get devices with home_id ------------------
33
- devices_with_home = api.get_devices_list(home_id=home_id)
34
- with open(f".mijia-api-data/devices_in_{home_name}.json", "w", encoding="utf-8") as f:
35
- json.dump(devices_with_home, f, ensure_ascii=False, indent=2)
36
- time.sleep(1)
37
-
38
- # ---------------------- get scenes list -----------------------
39
- scenes = api.get_scenes_list()
40
- with open(".mijia-api-data/scenes.json", "w", encoding="utf-8") as f:
41
- json.dump(scenes, f, ensure_ascii=False, indent=2)
42
- time.sleep(1)
43
-
44
- # ------------------ get scenes with home_id -------------------
45
- scenes_with_home = api.get_scenes_list(home_id=home_id)
46
- with open(f".mijia-api-data/scenes_in_{home_name}.json", "w", encoding="utf-8") as f:
47
- json.dump(scenes_with_home, f, ensure_ascii=False, indent=2)
48
- time.sleep(1)
49
-
50
- # ------------------------- run scene --------------------------
51
- scence_id = scenes[0]['scene_id']
52
- scence_name = scenes[0]['name']
53
- scence_home_id = scenes[0]['home_id']
54
- ret = api.run_scene(scence_id, scence_home_id)
55
- print(f"已执行场景 {scence_name},响应: {ret}")
56
- time.sleep(1)
57
-
58
- # -------------------- get consumable items --------------------
59
- consumable_items = api.get_consumable_items()
60
- with open(".mijia-api-data/consumable_items.json", "w", encoding="utf-8") as f:
61
- json.dump(consumable_items, f, ensure_ascii=False, indent=2)
62
- time.sleep(1)
63
-
64
- # ------------- get consumable items with home_id --------------
65
- consumable_items_with_home = api.get_consumable_items(home_id=home_id)
66
- with open(f".mijia-api-data/consumable_items_in_{home_name}.json", "w", encoding="utf-8") as f:
67
- json.dump(consumable_items_with_home, f, ensure_ascii=False, indent=2)
68
- time.sleep(1)
69
-
70
- # ----------------- get/set device properties ------------------
71
- # did 和 model 从 get_devices_list() 接口获取
72
- # siid 和 piid 请查阅 https://home.miot-spec.com/spec/{model}
73
- # 或者也可以直接在 米家APP->智能->+->手动控制 中
74
- # 添加 scene,调用 run_scene() 接口控制设备
75
- for device in devices:
76
- if device["model"] == "yeelink.light.lamp4":
77
- break
78
-
79
- did = device["did"]
80
- name = device["name"]
81
-
82
- ret = api.get_devices_prop([
83
- {"did": did, "siid": 2, "piid": 2},
84
- {"did": did, "siid": 2, "piid": 3},
85
- ])
86
- brightness = ret[0]["value"]
87
- color_temperature = ret[1]["value"]
88
- print(f"获取设备 {name} 属性成功: {ret}")
89
- print(f"亮度: {brightness}%")
90
- print(f"色温: {color_temperature}K")
91
-
92
- ret = api.set_devices_prop([
93
- {"did": did, "siid": 2, "piid": 2, "value": 50},
94
- {"did": did, "siid": 2, "piid": 3, "value": 2700},
95
- ])
96
- print(f"设置设备 {name} 属性成功: {ret}")
97
- time.sleep(1)
98
-
99
- # ------------------------- run action -------------------------
100
- ret = api.run_action({"did": did, "siid": 2, "aiid": 1})
101
- print(f"执行设备 {name} 动作成功: {ret}")
102
- time.sleep(1)
103
-
104
- # ----------------------- get statistics -----------------------
105
- for device in devices:
106
- if device["model"] == "lumi.acpartner.mcn04":
107
- break
108
- ret = api.get_statistics({
109
- "did": device["did"],
110
- "key": "7.1",
111
- "data_type": "stat_month_v3",
112
- "limit": 6,
113
- "time_start": int(time.time() - 24 * 60 * 60 * 30 * 6),
114
- "time_end": int(time.time()),
115
- })
116
- print(f"获取设备 {device['name']} 统计数据成功: {ret}")
@@ -1,35 +0,0 @@
1
- import time
2
-
3
- from mijiaAPI import mijiaAPI
4
-
5
-
6
- api = mijiaAPI(".mijia-api-data/auth.json")
7
- devices = api.get_devices_list()
8
- for device in devices:
9
- if device['model'] == 'lumi.acpartner.mcn04':
10
- did = device['did']
11
- break
12
-
13
- # 参考 https://iot.mi.com/new/doc/accesses/direct-access/extension-development/extension-functions/statistical-interface
14
- ret = api.get_statistics({
15
- "did": did,
16
- "key": "7.1", # siid.piid,这里的7.1表示 lumi.acpartner.mcn04 的 power-consumption
17
- "data_type": "stat_month_v3", # 按月统计,可选:时(stat_hour_v3)、天(stat_day_v3)、星期(stat_week_v3)、月(stat_month_v3)
18
- "limit": 6, # 返回的最大条目数
19
- "time_start": int(time.time() - 24 * 3600 * 30 * 6),
20
- "time_end": int(time.time()),
21
- })
22
-
23
- """
24
- 已知问题:
25
- 支持的设备有限,而且我的空调貌似也只支持 stat_month_v3。
26
- 比较旧的设备使用的API会不一样,需要将`data_type`中的`_v3`去掉。
27
- 并且`key`也不一样,比如 lumi.acpartner.mcn02 的统计耗电量的`key`为`powerCost`。
28
- 详见 https://github.com/Do1e/mijia-api/issues/46
29
- """
30
-
31
- for item in ret:
32
- value = eval(item['value'])[0]
33
- ts = item['time']
34
- date = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(ts))
35
- print(f'{date}: {value}')
@@ -1,12 +0,0 @@
1
- import logging
2
-
3
- from mijiaAPI import mijiaAPI
4
-
5
-
6
- logging.getLogger("mijiaAPI").setLevel(logging.DEBUG)
7
-
8
- api = mijiaAPI(".mijia-api-data/auth.json")
9
- print(api.available)
10
- api.login() # 实际就是调用 QRlogin 方法
11
- print(api.available)
12
- print(api.get_homes_list())
@@ -1 +0,0 @@
1
- version = "4.1.1"
@@ -1,24 +0,0 @@
1
- .gitignore
2
- LICENSE
3
- README.md
4
- pyproject.toml
5
- uv.lock
6
- .github/ISSUE_TEMPLATE/bug_report.md
7
- demos/test_apis.py
8
- demos/test_get_statistics.py
9
- demos/test_login.py
10
- mijiaAPI/__init__.py
11
- mijiaAPI/__main__.py
12
- mijiaAPI/apis.py
13
- mijiaAPI/devices.py
14
- mijiaAPI/errors.py
15
- mijiaAPI/logger.py
16
- mijiaAPI/mcp_server.py
17
- mijiaAPI/miutils.py
18
- mijiaAPI/version.py
19
- mijiaAPI.egg-info/PKG-INFO
20
- mijiaAPI.egg-info/SOURCES.txt
21
- mijiaAPI.egg-info/dependency_links.txt
22
- mijiaAPI.egg-info/entry_points.txt
23
- mijiaAPI.egg-info/requires.txt
24
- mijiaAPI.egg-info/top_level.txt
@@ -1,2 +0,0 @@
1
- [console_scripts]
2
- mijiaAPI = mijiaAPI.__main__:cli
@@ -1,6 +0,0 @@
1
- fastmcp>=3.4.2
2
- pillow>=11.3.0
3
- pycryptodome>=3.23.0
4
- qrcode>=8.2
5
- requests>=2.32.5
6
- tzlocal>=5.3.1
@@ -1 +0,0 @@
1
- mijiaAPI
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
File without changes
File without changes