python-xiaobiu 0.2.1__tar.gz → 0.2.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 (56) hide show
  1. {python_xiaobiu-0.2.1 → python_xiaobiu-0.2.2}/.github/workflows/python-publish.yml +6 -1
  2. {python_xiaobiu-0.2.1 → python_xiaobiu-0.2.2}/.gitignore +3 -0
  3. {python_xiaobiu-0.2.1 → python_xiaobiu-0.2.2}/CHANGELOG.md +25 -0
  4. python_xiaobiu-0.2.1/README.md → python_xiaobiu-0.2.2/PKG-INFO +46 -20
  5. python_xiaobiu-0.2.1/PKG-INFO → python_xiaobiu-0.2.2/README.md +25 -39
  6. {python_xiaobiu-0.2.1 → python_xiaobiu-0.2.2}/pyproject.toml +13 -4
  7. {python_xiaobiu-0.2.1 → python_xiaobiu-0.2.2}/src/xiaobiu/ac_control.py +105 -30
  8. {python_xiaobiu-0.2.1 → python_xiaobiu-0.2.2}/src/xiaobiu/ac_status.py +23 -6
  9. {python_xiaobiu-0.2.1 → python_xiaobiu-0.2.2}/src/xiaobiu/cli.py +37 -0
  10. {python_xiaobiu-0.2.1 → python_xiaobiu-0.2.2}/src/xiaobiu/client.py +6 -2
  11. {python_xiaobiu-0.2.1 → python_xiaobiu-0.2.2}/tests/test_ac_control.py +80 -17
  12. {python_xiaobiu-0.2.1 → python_xiaobiu-0.2.2}/tests/test_ac_status.py +204 -10
  13. {python_xiaobiu-0.2.1 → python_xiaobiu-0.2.2}/tests/test_cli.py +49 -0
  14. python_xiaobiu-0.2.2/uv.lock +370 -0
  15. python_xiaobiu-0.2.1/uv.lock +0 -367
  16. {python_xiaobiu-0.2.1 → python_xiaobiu-0.2.2}/docs/plans/2026-06-01-ac-control-design/bdd-specs.md +0 -0
  17. {python_xiaobiu-0.2.1 → python_xiaobiu-0.2.2}/docs/plans/2026-06-01-ac-control-plan/_index.md +0 -0
  18. {python_xiaobiu-0.2.1 → python_xiaobiu-0.2.2}/docs/plans/2026-06-01-ac-control-plan/task-001-ac-enums-impl.md +0 -0
  19. {python_xiaobiu-0.2.1 → python_xiaobiu-0.2.2}/docs/plans/2026-06-01-ac-control-plan/task-001-ac-enums-test.md +0 -0
  20. {python_xiaobiu-0.2.1 → python_xiaobiu-0.2.2}/docs/plans/2026-06-01-ac-control-plan/task-002-ac-cmd-mappings-impl.md +0 -0
  21. {python_xiaobiu-0.2.1 → python_xiaobiu-0.2.2}/docs/plans/2026-06-01-ac-control-plan/task-002-ac-cmd-mappings-test.md +0 -0
  22. {python_xiaobiu-0.2.1 → python_xiaobiu-0.2.2}/docs/plans/2026-06-01-ac-control-plan/task-003-ac-app-oper-impl.md +0 -0
  23. {python_xiaobiu-0.2.1 → python_xiaobiu-0.2.2}/docs/plans/2026-06-01-ac-control-plan/task-003-ac-app-oper-test.md +0 -0
  24. {python_xiaobiu-0.2.1 → python_xiaobiu-0.2.2}/docs/plans/2026-06-01-ac-control-plan/task-004-ac-highlevel-impl.md +0 -0
  25. {python_xiaobiu-0.2.1 → python_xiaobiu-0.2.2}/docs/plans/2026-06-01-ac-control-plan/task-004-ac-highlevel-test.md +0 -0
  26. {python_xiaobiu-0.2.1 → python_xiaobiu-0.2.2}/docs/plans/2026-06-01-ac-control-plan/task-005-ac-panel-template-impl.md +0 -0
  27. {python_xiaobiu-0.2.1 → python_xiaobiu-0.2.2}/docs/plans/2026-06-01-ac-control-plan/task-005-ac-panel-template-test.md +0 -0
  28. {python_xiaobiu-0.2.1 → python_xiaobiu-0.2.2}/docs/plans/2026-06-01-ac-control-plan/task-006-ac-timers-impl.md +0 -0
  29. {python_xiaobiu-0.2.1 → python_xiaobiu-0.2.2}/docs/plans/2026-06-01-ac-control-plan/task-006-ac-timers-test.md +0 -0
  30. {python_xiaobiu-0.2.1 → python_xiaobiu-0.2.2}/docs/plans/2026-06-01-ac-control-plan/task-007-ac-state-hvac-impl.md +0 -0
  31. {python_xiaobiu-0.2.1 → python_xiaobiu-0.2.2}/docs/plans/2026-06-01-ac-control-plan/task-007-ac-state-hvac-test.md +0 -0
  32. {python_xiaobiu-0.2.1 → python_xiaobiu-0.2.2}/docs/plans/2026-06-01-ac-control-plan/task-008-cli-ac-control-impl.md +0 -0
  33. {python_xiaobiu-0.2.1 → python_xiaobiu-0.2.2}/docs/plans/2026-06-01-ac-control-plan/task-008-cli-ac-control-test.md +0 -0
  34. {python_xiaobiu-0.2.1 → python_xiaobiu-0.2.2}/docs/plans/2026-06-01-ac-control-plan/task-009-docs-readme-impl.md +0 -0
  35. {python_xiaobiu-0.2.1 → python_xiaobiu-0.2.2}/docs/plans/2026-06-02-ac-control-align-ha-design/bdd-specs.md +0 -0
  36. {python_xiaobiu-0.2.1 → python_xiaobiu-0.2.2}/docs/plans/2026-06-02-ac-control-align-ha-plan/_index.md +0 -0
  37. {python_xiaobiu-0.2.1 → python_xiaobiu-0.2.2}/src/xiaobiu/__init__.py +0 -0
  38. {python_xiaobiu-0.2.1 → python_xiaobiu-0.2.2}/src/xiaobiu/app_api.py +0 -0
  39. {python_xiaobiu-0.2.1 → python_xiaobiu-0.2.2}/src/xiaobiu/captcha_bridge.py +0 -0
  40. {python_xiaobiu-0.2.1 → python_xiaobiu-0.2.2}/src/xiaobiu/crypto.py +0 -0
  41. {python_xiaobiu-0.2.1 → python_xiaobiu-0.2.2}/src/xiaobiu/exceptions.py +0 -0
  42. {python_xiaobiu-0.2.1 → python_xiaobiu-0.2.2}/src/xiaobiu/har_templates.py +0 -0
  43. {python_xiaobiu-0.2.1 → python_xiaobiu-0.2.2}/src/xiaobiu/models.py +0 -0
  44. {python_xiaobiu-0.2.1 → python_xiaobiu-0.2.2}/src/xiaobiu/parsers.py +0 -0
  45. {python_xiaobiu-0.2.1 → python_xiaobiu-0.2.2}/src/xiaobiu/persistence.py +0 -0
  46. {python_xiaobiu-0.2.1 → python_xiaobiu-0.2.2}/src/xiaobiu/sms_login.py +0 -0
  47. {python_xiaobiu-0.2.1 → python_xiaobiu-0.2.2}/tests/__init__.py +0 -0
  48. {python_xiaobiu-0.2.1 → python_xiaobiu-0.2.2}/tests/test_app_api.py +0 -0
  49. {python_xiaobiu-0.2.1 → python_xiaobiu-0.2.2}/tests/test_captcha_bridge.py +0 -0
  50. {python_xiaobiu-0.2.1 → python_xiaobiu-0.2.2}/tests/test_client.py +0 -0
  51. {python_xiaobiu-0.2.1 → python_xiaobiu-0.2.2}/tests/test_crypto.py +0 -0
  52. {python_xiaobiu-0.2.1 → python_xiaobiu-0.2.2}/tests/test_har_templates.py +0 -0
  53. {python_xiaobiu-0.2.1 → python_xiaobiu-0.2.2}/tests/test_models.py +0 -0
  54. {python_xiaobiu-0.2.1 → python_xiaobiu-0.2.2}/tests/test_parsers.py +0 -0
  55. {python_xiaobiu-0.2.1 → python_xiaobiu-0.2.2}/tests/test_persistence.py +0 -0
  56. {python_xiaobiu-0.2.1 → python_xiaobiu-0.2.2}/tests/test_sms_login.py +0 -0
@@ -24,7 +24,12 @@ jobs:
24
24
 
25
25
  - uses: actions/setup-python@v5
26
26
  with:
27
- python-version: "3.x"
27
+ python-version: "3.14"
28
+
29
+ - name: Run tests
30
+ run: |
31
+ python -m pip install . pytest pytest-asyncio
32
+ python -m pytest
28
33
 
29
34
  - name: Build release distributions
30
35
  run: |
@@ -8,3 +8,6 @@ dist/
8
8
  .venv/
9
9
  *.suning-session*.json
10
10
  *.har
11
+ .codegraph/
12
+ .reasonix/
13
+ verify_ac.py
@@ -4,6 +4,31 @@ All notable changes to `python-xiaobiu` are documented in this file.
4
4
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
5
5
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## [0.2.2] - 2026-06-24
8
+
9
+ ### Added
10
+ - `raw-oper` CLI command for protocol testing with arbitrary `C_*` / `SN_*`
11
+ command fields.
12
+
13
+ ### Changed
14
+ - Split the write-side `C_MODE` and read-side `SN_MODE` mappings based on
15
+ live-device verification. One-touch mode is exposed as `auto`, while
16
+ `quick` remains a write-compatible alias.
17
+ - Panel-template requests now match the live endpoint contract and include
18
+ the logged-in user's `custno` as the `userid` header when available.
19
+ - Device capabilities now follow the mode values advertised by the panel
20
+ template instead of assuming a fixed list.
21
+ - `C_FRESHAIR` and `SN_PURIFY` are treated as aliases when normalizing status.
22
+ - Raised dependency floors to patched releases and added the test suite as a
23
+ required step in the PyPI publishing workflow.
24
+
25
+ ### Fixed
26
+ - Corrected heat, cool, dry, fan-only, and one-touch mode encoding for
27
+ control commands and status responses.
28
+ - Correctly falls back to `C_MODE` encoding when `SN_MODE` is blank.
29
+ - Prevented local protocol captures and analysis metadata from entering
30
+ source distributions.
31
+
7
32
  ## [0.2.1] - 2026-06-02
8
33
 
9
34
  ### Added
@@ -1,3 +1,24 @@
1
+ Metadata-Version: 2.4
2
+ Name: python-xiaobiu
3
+ Version: 0.2.2
4
+ Summary: Suning biu smart home SMS login and session client
5
+ Project-URL: Homepage, https://github.com/FaintGhost/python-xiaobiu
6
+ Project-URL: Bug Tracker, https://github.com/FaintGhost/python-xiaobiu/issues
7
+ Author-email: FaintGhost <zhang.yaowei@live.com>
8
+ License: MIT
9
+ Keywords: climate,home-assistant,smart-home,suning
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Operating System :: OS Independent
13
+ Classifier: Programming Language :: Python :: 3
14
+ Requires-Python: >=3.14
15
+ Requires-Dist: cryptography>=48.0.1
16
+ Requires-Dist: idna>=3.15
17
+ Requires-Dist: pydantic>=2.0.0
18
+ Requires-Dist: requests>=2.33.0
19
+ Requires-Dist: urllib3>=2.7.0
20
+ Description-Content-Type: text/markdown
21
+
1
22
  # python-xiaobiu
2
23
 
3
24
  Python client for Suning smart home SMS login and session management.
@@ -52,12 +73,12 @@ client.turn_on(family_id=37790, device_id="000165f9b029afa2e5d8")
52
73
  client.turn_off(family_id=37790, device_id="000165f9b029afa2e5d8")
53
74
 
54
75
  # Mode
55
- client.set_hvac_mode(family_id=37790, device_id="...", mode=HvacMode.COOL) # 制冷
56
- client.set_hvac_mode(family_id=37790, device_id="...", mode=HvacMode.HEAT) # 制热
57
- client.set_hvac_mode(family_id=37790, device_id="...", mode=HvacMode.FAN_ONLY) # 送风
58
- client.set_hvac_mode(family_id=37790, device_id="...", mode=HvacMode.DRY) # 除湿
59
- client.set_hvac_mode(family_id=37790, device_id="...", mode=HvacMode.AUTO) # 自动
60
- client.set_hvac_mode(family_id=37790, device_id="...", mode=HvacMode.QUICK) # 一键通 (C_MODE=5, 待实测确认)
76
+ client.set_hvac_mode(family_id=37790, device_id="...", mode=HvacMode.HEAT) # 制热 (C_MODE=1)
77
+ client.set_hvac_mode(family_id=37790, device_id="...", mode=HvacMode.COOL) # 制冷 (C_MODE=2)
78
+ client.set_hvac_mode(family_id=37790, device_id="...", mode=HvacMode.DRY) # 除湿 (C_MODE=3)
79
+ client.set_hvac_mode(family_id=37790, device_id="...", mode=HvacMode.FAN_ONLY) # 送风 (C_MODE=4)
80
+ client.set_hvac_mode(family_id=37790, device_id="...", mode=HvacMode.AUTO) # 一键通/自动 (C_MODE=6)
81
+ client.set_hvac_mode(family_id=37790, device_id="...", mode=HvacMode.QUICK) # 一键通/自动 (C_MODE=6, 与 AUTO 同)
61
82
 
62
83
  # Temperature
63
84
  client.set_temperature(family_id=37790, device_id="...", value=24.0) # 16.0–32.0
@@ -96,12 +117,11 @@ client.get_device_panel_template(family_id=37790, device_id="...")
96
117
  | Suning App | `xiaobiu` API | `C_*` field | HA climate field |
97
118
  |------------|---------------|------------|------------------|
98
119
  | 电源开关 | `turn_on/off` | `C_POWER` | `hvac_mode = off` when off |
99
- | 制冷 | `set_hvac_mode(COOL)` | `C_MODE=1` | `hvac_mode = cool` |
100
- | 制热 | `set_hvac_mode(HEAT)` | `C_MODE=2` | `hvac_mode = heat` |
101
- | 送风 | `set_hvac_mode(FAN_ONLY)` | `C_MODE=3` | `hvac_mode = fan_only` |
102
- | 除湿 | `set_hvac_mode(DRY)` | `C_MODE=4` | `hvac_mode = dry` |
103
- | 自动 | `set_hvac_mode(AUTO)` | `C_MODE=6` | `hvac_mode = auto` |
104
- | 一键通 | `set_hvac_mode(QUICK)` | `C_MODE=5` | `hvac_mode = auto` (map) |
120
+ | 制热 | `set_hvac_mode(HEAT)` | `C_MODE=1` | `hvac_mode = heat` |
121
+ | 制冷 | `set_hvac_mode(COOL)` | `C_MODE=2` | `hvac_mode = cool` |
122
+ | 除湿 | `set_hvac_mode(DRY)` | `C_MODE=3` | `hvac_mode = dry` |
123
+ | 送风 | `set_hvac_mode(FAN_ONLY)` | `C_MODE=4` (或 `5`) | `hvac_mode = fan_only` |
124
+ | 一键通/自动 | `set_hvac_mode(AUTO)` / `set_hvac_mode(QUICK)` | `C_MODE=6` | `hvac_mode = auto` |
105
125
  | 微风/低/中/高/强风 | `set_fan_mode(SILENT/LOW/MEDIUM/HIGH/TURBO)` | `C_FANSPEED=1..5` | `fan_mode` |
106
126
  | 上下摆风 | `set_vertical_swing(on=)` | `C_AIRVERTICAL` | `swing_mode` (HA 把 `swing_mode` 默认指垂直) |
107
127
  | 左右摆风 | `set_horizontal_swing(on=)` | `C_AIRHORIZONTAL` | `swing_horizontal_mode` |
@@ -109,6 +129,11 @@ client.get_device_panel_template(family_id=37790, device_id="...")
109
129
  | 空气清新 | `set_fresh_air(on=)` | `C_FRESHAIR` | `preset_mode = fresh_air` |
110
130
  | 电辅热 | `set_aux_heat(on=)` | `C_ELECHEATING` | `preset_mode = aux_heat` |
111
131
 
132
+ > **读/写编码不同**:上表是**写侧**(`C_MODE` 控制值)。设备**上报状态**用的是另一套 `SN_MODE` 值:
133
+ > `SN_MODE=1`(一键通/自动)、`2`(制冷)、`3`(制热)、`4`(送风)、`5`(除湿)。
134
+ > `infer_hvac_mode` 读状态时默认按 `SN_MODE` 解码;下发命令时 `set_hvac_mode` 用 `C_MODE`。
135
+ > 两套编码不一致(如 `C_MODE=1` 是制热,但 `SN_MODE=1` 是一键通),库内部已拆成两张表分别处理。
136
+
112
137
  ### `swing_mode` 集成注意事项
113
138
 
114
139
  按 Home Assistant climate entity 惯例:
@@ -190,18 +215,19 @@ xiaobiucli set-fresh-air --family-id 37790 --device-id <id> --on|--off
190
215
  xiaobiucli set-aux-heat --family-id 37790 --device-id <id> --on|--off
191
216
  xiaobiucli timers --family-id 37790 --device-id <id>
192
217
  xiaobiucli panel --family-id 37790 --device-id <id>
218
+ xiaobiucli raw-oper --family-id 37790 --device-id <id> --cmd C_MODE=1 [--cmd KEY=VALUE ...]
193
219
  ```
194
220
 
195
221
  ## Notes
196
222
 
197
- - **`C_MODE=5` → `HvacMode.QUICK`** (一键通) is **inferred** — the 2026-06-01
198
- HAR did not capture that button, and the App has no other unused mode
199
- value in the 0–7 range. Please confirm against a live device once
200
- and adjust if the App maps a different number to 一键通.
201
- - **`C_ELECHEATING` (电辅热)** was surfaced by `queryTemplate.do` and
202
- the value is inferred to be `0/1`. `set_aux_heat(on=True)` enforces
203
- the App's "only while heating" rule at the client (raises
204
- `SuningError` if the current mode is not HEAT).
223
+ - **`C_MODE` / `SN_MODE` 编码不同**(2026-06-17 真机实测确认):
224
+ - 写侧 `C_MODE`:`1`=制热、`2`=制冷、`3`=除湿、`4`=送风、`5`=送风(同 4)、`6`=一键通(≈自动)
225
+ - 读侧 `SN_MODE`:`1`=一键通(自动)、`2`=制冷、`3`=制热、`4`=送风、`5`=除湿
226
+ - 库内部用 `C_FIELD_TO_HVAC`(写)和 `SN_FIELD_TO_HVAC`(读)两张表分别处理。
227
+ - **一键通 ≈ 自动**:这台设备没有独立的 AUTO 模式,`C_MODE=6`(一键通)在语义上最接近,
228
+ 暴露为 `HvacMode.AUTO`;`HvacMode.QUICK` 也指向 `C_MODE=6`。
229
+ - **`C_ELECHEATING` (电辅热)** 值域已实测确认为 `0/1`。`set_aux_heat(on=True)` 在客户端
230
+ 强制 App 的"仅制热时生效"规则(当前模式非 HEAT 时 raise `SuningError`)。
205
231
  - **`SN_CLOUD_TIMER` writes** are not implemented in this release.
206
232
  - **Unknown `C_MODE` values** (e.g. `7`, which neither the App nor the
207
233
  capture expose) collapse to `hvac_mode = None` so Home Assistant can
@@ -1,22 +1,3 @@
1
- Metadata-Version: 2.4
2
- Name: python-xiaobiu
3
- Version: 0.2.1
4
- Summary: Suning biu smart home SMS login and session client
5
- Project-URL: Homepage, https://github.com/FaintGhost/python-xiaobiu
6
- Project-URL: Bug Tracker, https://github.com/FaintGhost/python-xiaobiu/issues
7
- Author-email: FaintGhost <zhang.yaowei@live.com>
8
- License: MIT
9
- Keywords: climate,home-assistant,smart-home,suning
10
- Classifier: Intended Audience :: Developers
11
- Classifier: License :: OSI Approved :: MIT License
12
- Classifier: Operating System :: OS Independent
13
- Classifier: Programming Language :: Python :: 3
14
- Requires-Python: >=3.14
15
- Requires-Dist: cryptography>=44.0.0
16
- Requires-Dist: pydantic>=2.0.0
17
- Requires-Dist: requests>=2.28.0
18
- Description-Content-Type: text/markdown
19
-
20
1
  # python-xiaobiu
21
2
 
22
3
  Python client for Suning smart home SMS login and session management.
@@ -71,12 +52,12 @@ client.turn_on(family_id=37790, device_id="000165f9b029afa2e5d8")
71
52
  client.turn_off(family_id=37790, device_id="000165f9b029afa2e5d8")
72
53
 
73
54
  # Mode
74
- client.set_hvac_mode(family_id=37790, device_id="...", mode=HvacMode.COOL) # 制冷
75
- client.set_hvac_mode(family_id=37790, device_id="...", mode=HvacMode.HEAT) # 制热
76
- client.set_hvac_mode(family_id=37790, device_id="...", mode=HvacMode.FAN_ONLY) # 送风
77
- client.set_hvac_mode(family_id=37790, device_id="...", mode=HvacMode.DRY) # 除湿
78
- client.set_hvac_mode(family_id=37790, device_id="...", mode=HvacMode.AUTO) # 自动
79
- client.set_hvac_mode(family_id=37790, device_id="...", mode=HvacMode.QUICK) # 一键通 (C_MODE=5, 待实测确认)
55
+ client.set_hvac_mode(family_id=37790, device_id="...", mode=HvacMode.HEAT) # 制热 (C_MODE=1)
56
+ client.set_hvac_mode(family_id=37790, device_id="...", mode=HvacMode.COOL) # 制冷 (C_MODE=2)
57
+ client.set_hvac_mode(family_id=37790, device_id="...", mode=HvacMode.DRY) # 除湿 (C_MODE=3)
58
+ client.set_hvac_mode(family_id=37790, device_id="...", mode=HvacMode.FAN_ONLY) # 送风 (C_MODE=4)
59
+ client.set_hvac_mode(family_id=37790, device_id="...", mode=HvacMode.AUTO) # 一键通/自动 (C_MODE=6)
60
+ client.set_hvac_mode(family_id=37790, device_id="...", mode=HvacMode.QUICK) # 一键通/自动 (C_MODE=6, 与 AUTO 同)
80
61
 
81
62
  # Temperature
82
63
  client.set_temperature(family_id=37790, device_id="...", value=24.0) # 16.0–32.0
@@ -115,12 +96,11 @@ client.get_device_panel_template(family_id=37790, device_id="...")
115
96
  | Suning App | `xiaobiu` API | `C_*` field | HA climate field |
116
97
  |------------|---------------|------------|------------------|
117
98
  | 电源开关 | `turn_on/off` | `C_POWER` | `hvac_mode = off` when off |
118
- | 制冷 | `set_hvac_mode(COOL)` | `C_MODE=1` | `hvac_mode = cool` |
119
- | 制热 | `set_hvac_mode(HEAT)` | `C_MODE=2` | `hvac_mode = heat` |
120
- | 送风 | `set_hvac_mode(FAN_ONLY)` | `C_MODE=3` | `hvac_mode = fan_only` |
121
- | 除湿 | `set_hvac_mode(DRY)` | `C_MODE=4` | `hvac_mode = dry` |
122
- | 自动 | `set_hvac_mode(AUTO)` | `C_MODE=6` | `hvac_mode = auto` |
123
- | 一键通 | `set_hvac_mode(QUICK)` | `C_MODE=5` | `hvac_mode = auto` (map) |
99
+ | 制热 | `set_hvac_mode(HEAT)` | `C_MODE=1` | `hvac_mode = heat` |
100
+ | 制冷 | `set_hvac_mode(COOL)` | `C_MODE=2` | `hvac_mode = cool` |
101
+ | 除湿 | `set_hvac_mode(DRY)` | `C_MODE=3` | `hvac_mode = dry` |
102
+ | 送风 | `set_hvac_mode(FAN_ONLY)` | `C_MODE=4` (或 `5`) | `hvac_mode = fan_only` |
103
+ | 一键通/自动 | `set_hvac_mode(AUTO)` / `set_hvac_mode(QUICK)` | `C_MODE=6` | `hvac_mode = auto` |
124
104
  | 微风/低/中/高/强风 | `set_fan_mode(SILENT/LOW/MEDIUM/HIGH/TURBO)` | `C_FANSPEED=1..5` | `fan_mode` |
125
105
  | 上下摆风 | `set_vertical_swing(on=)` | `C_AIRVERTICAL` | `swing_mode` (HA 把 `swing_mode` 默认指垂直) |
126
106
  | 左右摆风 | `set_horizontal_swing(on=)` | `C_AIRHORIZONTAL` | `swing_horizontal_mode` |
@@ -128,6 +108,11 @@ client.get_device_panel_template(family_id=37790, device_id="...")
128
108
  | 空气清新 | `set_fresh_air(on=)` | `C_FRESHAIR` | `preset_mode = fresh_air` |
129
109
  | 电辅热 | `set_aux_heat(on=)` | `C_ELECHEATING` | `preset_mode = aux_heat` |
130
110
 
111
+ > **读/写编码不同**:上表是**写侧**(`C_MODE` 控制值)。设备**上报状态**用的是另一套 `SN_MODE` 值:
112
+ > `SN_MODE=1`(一键通/自动)、`2`(制冷)、`3`(制热)、`4`(送风)、`5`(除湿)。
113
+ > `infer_hvac_mode` 读状态时默认按 `SN_MODE` 解码;下发命令时 `set_hvac_mode` 用 `C_MODE`。
114
+ > 两套编码不一致(如 `C_MODE=1` 是制热,但 `SN_MODE=1` 是一键通),库内部已拆成两张表分别处理。
115
+
131
116
  ### `swing_mode` 集成注意事项
132
117
 
133
118
  按 Home Assistant climate entity 惯例:
@@ -209,18 +194,19 @@ xiaobiucli set-fresh-air --family-id 37790 --device-id <id> --on|--off
209
194
  xiaobiucli set-aux-heat --family-id 37790 --device-id <id> --on|--off
210
195
  xiaobiucli timers --family-id 37790 --device-id <id>
211
196
  xiaobiucli panel --family-id 37790 --device-id <id>
197
+ xiaobiucli raw-oper --family-id 37790 --device-id <id> --cmd C_MODE=1 [--cmd KEY=VALUE ...]
212
198
  ```
213
199
 
214
200
  ## Notes
215
201
 
216
- - **`C_MODE=5` → `HvacMode.QUICK`** (一键通) is **inferred** — the 2026-06-01
217
- HAR did not capture that button, and the App has no other unused mode
218
- value in the 0–7 range. Please confirm against a live device once
219
- and adjust if the App maps a different number to 一键通.
220
- - **`C_ELECHEATING` (电辅热)** was surfaced by `queryTemplate.do` and
221
- the value is inferred to be `0/1`. `set_aux_heat(on=True)` enforces
222
- the App's "only while heating" rule at the client (raises
223
- `SuningError` if the current mode is not HEAT).
202
+ - **`C_MODE` / `SN_MODE` 编码不同**(2026-06-17 真机实测确认):
203
+ - 写侧 `C_MODE`:`1`=制热、`2`=制冷、`3`=除湿、`4`=送风、`5`=送风(同 4)、`6`=一键通(≈自动)
204
+ - 读侧 `SN_MODE`:`1`=一键通(自动)、`2`=制冷、`3`=制热、`4`=送风、`5`=除湿
205
+ - 库内部用 `C_FIELD_TO_HVAC`(写)和 `SN_FIELD_TO_HVAC`(读)两张表分别处理。
206
+ - **一键通 ≈ 自动**:这台设备没有独立的 AUTO 模式,`C_MODE=6`(一键通)在语义上最接近,
207
+ 暴露为 `HvacMode.AUTO`;`HvacMode.QUICK` 也指向 `C_MODE=6`。
208
+ - **`C_ELECHEATING` (电辅热)** 值域已实测确认为 `0/1`。`set_aux_heat(on=True)` 在客户端
209
+ 强制 App 的"仅制热时生效"规则(当前模式非 HEAT 时 raise `SuningError`)。
224
210
  - **`SN_CLOUD_TIMER` writes** are not implemented in this release.
225
211
  - **Unknown `C_MODE` values** (e.g. `7`, which neither the App nor the
226
212
  capture expose) collapse to `hvac_mode = None` so Home Assistant can
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "python-xiaobiu"
3
- version = "0.2.1"
3
+ version = "0.2.2"
4
4
  description = "Suning biu smart home SMS login and session client"
5
5
  readme = "README.md"
6
6
  license = { text = "MIT" }
@@ -16,9 +16,11 @@ classifiers = [
16
16
  ]
17
17
  requires-python = ">=3.14"
18
18
  dependencies = [
19
- "cryptography>=44.0.0",
19
+ "cryptography>=48.0.1",
20
+ "idna>=3.15",
20
21
  "pydantic>=2.0.0",
21
- "requests>=2.28.0",
22
+ "requests>=2.33.0",
23
+ "urllib3>=2.7.0",
22
24
  ]
23
25
 
24
26
  [project.urls]
@@ -30,7 +32,7 @@ xiaobiucli = "xiaobiu:main"
30
32
 
31
33
  [dependency-groups]
32
34
  dev = [
33
- "pytest>=8.0.0",
35
+ "pytest>=9.0.3",
34
36
  "pytest-asyncio>=0.23.0",
35
37
  ]
36
38
 
@@ -41,5 +43,12 @@ build-backend = "hatchling.build"
41
43
  [tool.hatch.build.targets.wheel]
42
44
  packages = ["src/xiaobiu"]
43
45
 
46
+ [tool.hatch.build]
47
+ exclude = [
48
+ "/.codegraph",
49
+ "/.reasonix",
50
+ "/verify_ac.py",
51
+ ]
52
+
44
53
  [tool.pytest.ini_options]
45
54
  asyncio_mode = "auto"
@@ -41,15 +41,45 @@ PANEL_QUERY_URL = "https://shcss.suning.com/shcss-web/api/panel/queryTemplate.do
41
41
  TEMP_MIN_C = 16.0
42
42
  TEMP_MAX_C = 32.0
43
43
 
44
+ # ---------------------------------------------------------------------------
45
+ # Mode mapping tables
46
+ # ---------------------------------------------------------------------------
47
+ #
48
+ # Suning encodes the HVAC mode with *two different* value sets:
49
+ #
50
+ # * ``C_MODE`` (control) — the value you send in an ``appOper`` command.
51
+ # * ``SN_MODE`` (status) — the value the device reports back in its status.
52
+ #
53
+ # They are NOT the same encoding, so reads and writes need separate tables.
54
+ # Values below were confirmed by live-device testing (2026-06-17) plus the
55
+ # ``queryTemplate.do`` panel definition:
56
+ #
57
+ # C_MODE (write): 1=制热 2=制冷 3=除湿 4=送风 5=送风 6=一键通(=自动)
58
+ # SN_MODE (read): 1=一键通 2=制冷 3=制热 4=送风 5=除湿
59
+ #
60
+ # Note: this device has no dedicated AUTO mode; ``C_MODE=6`` (一键通) is the
61
+ # closest semantic match and is exposed as ``HvacMode.AUTO``. ``C_MODE=5``
62
+ # behaves the same as ``4`` (送风) on the tested device.
63
+
64
+ # Write side: C_MODE control value → HvacMode
44
65
  C_FIELD_TO_HVAC: dict[str, HvacMode] = {
45
- "1": HvacMode.COOL,
46
- "2": HvacMode.HEAT,
47
- "3": HvacMode.FAN_ONLY,
48
- "4": HvacMode.DRY,
49
- "5": HvacMode.QUICK,
66
+ "1": HvacMode.HEAT,
67
+ "2": HvacMode.COOL,
68
+ "3": HvacMode.DRY,
69
+ "4": HvacMode.FAN_ONLY,
70
+ "5": HvacMode.FAN_ONLY,
50
71
  "6": HvacMode.AUTO,
51
72
  }
52
73
 
74
+ # Read side: SN_MODE status value → HvacMode
75
+ SN_FIELD_TO_HVAC: dict[str, HvacMode] = {
76
+ "1": HvacMode.AUTO,
77
+ "2": HvacMode.COOL,
78
+ "3": HvacMode.HEAT,
79
+ "4": HvacMode.FAN_ONLY,
80
+ "5": HvacMode.DRY,
81
+ }
82
+
53
83
  C_FIELD_TO_FAN: dict[str, FanSpeed] = {
54
84
  "0": FanSpeed.AUTO,
55
85
  "1": FanSpeed.SILENT,
@@ -59,7 +89,16 @@ C_FIELD_TO_FAN: dict[str, FanSpeed] = {
59
89
  "5": FanSpeed.TURBO,
60
90
  }
61
91
 
62
- HVAC_TO_C_FIELD: dict[HvacMode, str] = {mode: raw for raw, mode in C_FIELD_TO_HVAC.items()}
92
+ # HvacMode → preferred C_MODE control value (first write-table hit wins).
93
+ # QUICK shares C_MODE=6 with AUTO on the tested device (一键通 ≈ 自动).
94
+ HVAC_TO_C_FIELD: dict[HvacMode, str] = {
95
+ HvacMode.HEAT: "1",
96
+ HvacMode.COOL: "2",
97
+ HvacMode.DRY: "3",
98
+ HvacMode.FAN_ONLY: "4",
99
+ HvacMode.AUTO: "6",
100
+ HvacMode.QUICK: "6",
101
+ }
63
102
  FAN_TO_C_FIELD: dict[FanSpeed, str] = {speed: raw for raw, speed in C_FIELD_TO_FAN.items()}
64
103
 
65
104
  SWING_TO_CMD: dict[SwingMode, dict[str, str]] = {
@@ -172,6 +211,7 @@ def get_device_panel_template(
172
211
  model_id: str,
173
212
  *,
174
213
  category_id: str = "0002",
214
+ template_id: str = "PANEL_AC",
175
215
  ) -> DeviceCapabilities | None:
176
216
  """Fetch the device's :class:`DeviceCapabilities`.
177
217
 
@@ -180,14 +220,24 @@ def get_device_panel_template(
180
220
  name for backward compatibility — the returned object's
181
221
  :class:`DeviceCapabilities` includes a ``raw`` payload carrying the
182
222
  unparsed template.
223
+
224
+ The panel endpoint (``queryTemplate.do``) is queried with ``modelId``
225
+ and ``templateId`` (confirmed from a live HAR capture). A ``userid``
226
+ header carrying the logged-in user's ``custno`` cookie value is sent
227
+ so the server returns the full template instead of a login redirect.
183
228
  """
184
229
 
185
- query = (
186
- f"{PANEL_QUERY_URL}"
187
- f"?deviceId={device_id}&modelId={model_id}&categoryId={category_id}"
188
- )
230
+ query = f"{PANEL_QUERY_URL}?modelId={model_id}&templateId={template_id}"
231
+ headers: dict[str, str] = {}
232
+ custno = None
189
233
  try:
190
- response = client.session.get(query, timeout=client.timeout)
234
+ custno = client.session.cookies.get("custno")
235
+ except Exception:
236
+ pass
237
+ if custno:
238
+ headers["userid"] = str(custno)
239
+ try:
240
+ response = client.session.get(query, timeout=client.timeout, headers=headers)
191
241
  response.raise_for_status()
192
242
  payload = response.json()
193
243
  except Exception:
@@ -261,20 +311,24 @@ def build_capabilities_from_template(
261
311
 
262
312
  has = set(fields)
263
313
  hvac_modes: list[str] = []
264
- # The device speaks a single C_MODE knob; we expose the HA-equivalent
265
- # standard names. We never report HEAT_COOL because the AC has no
266
- # range-control primitive — AUTO is the implicit form.
314
+ # Build the hvac_modes list from the C_MODE control values the panel
315
+ # actually advertises (its ``k`` array), mapped through the write table.
316
+ # ``off`` is always offered (power toggle). Unknown C_MODE values that
317
+ # have no HvacMode mapping are simply skipped. When the panel template
318
+ # lacks a ``k`` array for C_MODE (e.g. no ``raw`` was supplied), fall back
319
+ # to the full set of known modes so callers still get a usable list.
267
320
  if "C_MODE" in has:
268
- hvac_modes = [
269
- HvacMode.OFF.value,
270
- HvacMode.COOL.value,
271
- HvacMode.HEAT.value,
272
- HvacMode.DRY.value,
273
- HvacMode.FAN_ONLY.value,
274
- HvacMode.AUTO.value,
275
- ]
276
- # QUICK is inferred (C_MODE=5) so we add it when the field is present.
277
- hvac_modes.append(HvacMode.QUICK.value)
321
+ hvac_modes = [HvacMode.OFF.value]
322
+ seen: set[str] = {HvacMode.OFF.value}
323
+ mode_field = field_map.get("C_MODE")
324
+ advertised = mode_field.raw_values if mode_field is not None else []
325
+ if not advertised:
326
+ advertised = list(C_FIELD_TO_HVAC.keys())
327
+ for raw_val in advertised:
328
+ mapped = C_FIELD_TO_HVAC.get(str(raw_val).strip())
329
+ if mapped is not None and mapped.value not in seen:
330
+ hvac_modes.append(mapped.value)
331
+ seen.add(mapped.value)
278
332
  fan_modes: list[str] = []
279
333
  if "C_FANSPEED" in has:
280
334
  fan_modes = [
@@ -361,13 +415,30 @@ def list_device_timers(client: Any, device_id: str) -> list[Timer]:
361
415
  return timers
362
416
 
363
417
 
364
- def infer_hvac_mode(*, power_on: bool | None, mode_raw: Any) -> HvacMode | None:
418
+ def infer_hvac_mode(
419
+ *,
420
+ power_on: bool | None,
421
+ mode_raw: Any,
422
+ field_kind: str = "sn",
423
+ ) -> HvacMode | None:
365
424
  """Translate raw status fields into a typed HVAC mode.
366
425
 
367
426
  ``power_on is False`` always wins and yields ``HvacMode.OFF``; only an
368
427
  explicitly powered-on device is mapped to a running mode. Unknown
369
- mode values (e.g. HAR has not exposed ``C_MODE=5``) collapse to
370
- ``None`` so the caller can render an ``unavailable`` preview.
428
+ mode values collapse to ``None`` so the caller can render an
429
+ ``unavailable`` preview.
430
+
431
+ ``field_kind`` selects the encoding table:
432
+
433
+ * ``"sn"`` (default) — ``mode_raw`` is an ``SN_MODE`` *status* value
434
+ (read from the device status payload); uses :data:`SN_FIELD_TO_HVAC`.
435
+ * ``"c"`` — ``mode_raw`` is a ``C_MODE`` *control* value (the value
436
+ you would send in an ``appOper`` command); uses
437
+ :data:`C_FIELD_TO_HVAC`.
438
+
439
+ The two encodings differ on this device (e.g. ``C_MODE=1`` is 制热 but
440
+ ``SN_MODE=1`` is 一键通/自动), so callers reading device status should
441
+ keep the default ``"sn"``.
371
442
  """
372
443
 
373
444
  if power_on is False:
@@ -376,7 +447,8 @@ def infer_hvac_mode(*, power_on: bool | None, mode_raw: Any) -> HvacMode | None:
376
447
  return None
377
448
  if mode_raw is None:
378
449
  return None
379
- return C_FIELD_TO_HVAC.get(str(mode_raw).strip())
450
+ table = SN_FIELD_TO_HVAC if field_kind != "c" else C_FIELD_TO_HVAC
451
+ return table.get(str(mode_raw).strip())
380
452
 
381
453
 
382
454
  def infer_fan_speed(speed_raw: Any) -> FanSpeed | None:
@@ -420,11 +492,13 @@ def infer_hvac_action(
420
492
  return HvacAction.FAN
421
493
  if current_temp is None or target_temp is None:
422
494
  return HvacAction.IDLE
423
- if mode_value in (HvacMode.HEAT.value, HvacMode.QUICK.value):
495
+ if mode_value == HvacMode.HEAT.value:
424
496
  return HvacAction.HEATING if current_temp < target_temp else HvacAction.IDLE
425
497
  if mode_value == HvacMode.COOL.value:
426
498
  return HvacAction.COOLING if current_temp > target_temp else HvacAction.IDLE
427
- if mode_value in (HvacMode.AUTO.value, HvacMode.HEAT_COOL.value):
499
+ # AUTO and QUICK (一键通) both behave like HEAT_COOL: pick the side
500
+ # that has work to do.
501
+ if mode_value in (HvacMode.AUTO.value, HvacMode.QUICK.value, HvacMode.HEAT_COOL.value):
428
502
  if current_temp < target_temp:
429
503
  return HvacAction.HEATING
430
504
  if current_temp > target_temp:
@@ -632,6 +706,7 @@ __all__ = [
632
706
  "PRESET_ON_CMD",
633
707
  "PanelTemplate",
634
708
  "QUERY_TIMER_URL",
709
+ "SN_FIELD_TO_HVAC",
635
710
  "SWING_TO_CMD",
636
711
  "TEMP_MAX_C",
637
712
  "TEMP_MIN_C",
@@ -228,13 +228,23 @@ def _normalize_air_conditioner_status(device: dict[str, Any]) -> AirConditionerS
228
228
  _coalesce(raw_status.get("SN_AIRVERTICAL"), raw_status.get("C_AIRVERTICAL"))
229
229
  )
230
230
  eco_enabled = _parse_bool_flag(_coalesce(raw_status.get("SN_ECO"), raw_status.get("C_ECO")))
231
- purify_enabled = _parse_bool_flag(raw_status.get("SN_PURIFY"))
232
- fresh_air_enabled = _parse_bool_flag(raw_status.get("C_FRESHAIR"))
231
+ purify_enabled = _parse_bool_flag(
232
+ _coalesce(raw_status.get("SN_PURIFY"), raw_status.get("C_FRESHAIR"))
233
+ )
234
+ fresh_air_enabled = _parse_bool_flag(
235
+ _coalesce(raw_status.get("C_FRESHAIR"), raw_status.get("SN_PURIFY"))
236
+ )
233
237
  electric_heating_enabled = _parse_bool_flag(
234
238
  _coalesce(raw_status.get("SN_ELECHEATING"), raw_status.get("C_ELECHEATING"))
235
239
  )
236
- mode_raw = _coalesce(raw_status.get("SN_MODE"), raw_status.get("C_MODE"))
237
- hvac_mode = infer_hvac_mode(power_on=power_on, mode_raw=mode_raw) if online else None
240
+ sn_mode_raw = _coalesce(raw_status.get("SN_MODE"))
241
+ mode_raw = _coalesce(sn_mode_raw, raw_status.get("C_MODE"))
242
+ mode_field_kind = "sn" if sn_mode_raw is not None else "c"
243
+ hvac_mode = (
244
+ infer_hvac_mode(power_on=power_on, mode_raw=mode_raw, field_kind=mode_field_kind)
245
+ if online
246
+ else None
247
+ )
238
248
  hvac_action = (
239
249
  ac_control.infer_hvac_action(
240
250
  power_on=power_on,
@@ -282,12 +292,19 @@ def _normalize_air_conditioner_status(device: dict[str, Any]) -> AirConditionerS
282
292
  )
283
293
 
284
294
 
285
- def infer_hvac_mode(*, power_on: bool | None, mode_raw: Any) -> HvacMode | None:
295
+ def infer_hvac_mode(
296
+ *,
297
+ power_on: bool | None,
298
+ mode_raw: Any,
299
+ field_kind: str = "sn",
300
+ ) -> HvacMode | None:
286
301
  """Translate raw status fields into a typed :class:`HvacMode`."""
287
302
 
288
303
  from . import ac_control
289
304
 
290
- return ac_control.infer_hvac_mode(power_on=power_on, mode_raw=mode_raw)
305
+ return ac_control.infer_hvac_mode(
306
+ power_on=power_on, mode_raw=mode_raw, field_kind=field_kind,
307
+ )
291
308
 
292
309
 
293
310
  def _is_air_conditioner_device(device: dict[str, Any]) -> bool:
@@ -159,6 +159,21 @@ def _build_parser() -> argparse.ArgumentParser:
159
159
  add_shared_arguments(panel_cmd)
160
160
  panel_cmd.add_argument("--family-id", required=True)
161
161
  panel_cmd.add_argument("--device-id", required=True)
162
+
163
+ raw_oper = subparsers.add_parser(
164
+ "raw-oper",
165
+ help="直接下发任意 C_*/SN_* 字段到 appOper,绕开模式映射表(用于协议实测)",
166
+ )
167
+ add_shared_arguments(raw_oper)
168
+ raw_oper.add_argument("--family-id", required=True)
169
+ raw_oper.add_argument("--device-id", required=True)
170
+ raw_oper.add_argument(
171
+ "--cmd",
172
+ action="append",
173
+ required=True,
174
+ metavar="KEY=VALUE",
175
+ help="要下发的字段,可多次指定,例如 --cmd C_MODE=1 --cmd C_FANSPEED=0",
176
+ )
162
177
  return parser
163
178
 
164
179
 
@@ -488,6 +503,28 @@ def main(argv: list[str] | None = None) -> int:
488
503
  template.model_dump(mode="json") if template is not None else None,
489
504
  )
490
505
  return 0
506
+ if args.command == "raw-oper":
507
+ cmd: dict[str, str] = {}
508
+ for piece in args.cmd:
509
+ if "=" not in piece:
510
+ raise SuningError(f"--cmd 必须是 KEY=VALUE 形式,收到: {piece!r}")
511
+ key, value = piece.split("=", 1)
512
+ cmd[key.strip()] = value.strip()
513
+ target_device, model_id = client._resolve_ac_target(
514
+ args.family_id, args.device_id,
515
+ )
516
+ payload = client.app_oper(target_device, model_id, cmd)
517
+ _print_payload(
518
+ {
519
+ "status": "ok",
520
+ "command": "raw-oper",
521
+ "device_id": target_device,
522
+ "model_id": model_id,
523
+ "cmd": cmd,
524
+ "response": payload,
525
+ },
526
+ )
527
+ return 0
491
528
  except CaptchaRequiredError as error:
492
529
  _print_payload(
493
530
  {
@@ -366,8 +366,12 @@ class SuningSmartHomeClient:
366
366
  def _build_ha_climate_preview(self, status: AirConditionerStatus) -> Any:
367
367
  return ac_status._build_ha_climate_preview(status)
368
368
 
369
- def _infer_hvac_mode(self, *, power_on: bool | None, mode_raw: Any) -> HvacMode | None:
370
- return ac_status.infer_hvac_mode(power_on=power_on, mode_raw=mode_raw)
369
+ def _infer_hvac_mode(
370
+ self, *, power_on: bool | None, mode_raw: Any, field_kind: str = "sn",
371
+ ) -> HvacMode | None:
372
+ return ac_status.infer_hvac_mode(
373
+ power_on=power_on, mode_raw=mode_raw, field_kind=field_kind,
374
+ )
371
375
 
372
376
  # SMS-login private helpers (re-exported for the test suite).
373
377
  def _captcha_fields(self, captcha: CaptchaSolution) -> dict[str, str]: