python-xiaobiu 0.2.0__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.0 → python_xiaobiu-0.2.2}/.github/workflows/python-publish.yml +6 -1
  2. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.2}/.gitignore +3 -0
  3. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.2}/CHANGELOG.md +46 -0
  4. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.2}/PKG-INFO +83 -24
  5. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.2}/README.md +78 -21
  6. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.2}/pyproject.toml +13 -4
  7. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.2}/src/xiaobiu/__init__.py +2 -0
  8. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.2}/src/xiaobiu/ac_control.py +259 -20
  9. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.2}/src/xiaobiu/ac_status.py +36 -6
  10. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.2}/src/xiaobiu/cli.py +37 -0
  11. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.2}/src/xiaobiu/client.py +6 -2
  12. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.2}/src/xiaobiu/models.py +54 -0
  13. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.2}/tests/test_ac_control.py +271 -17
  14. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.2}/tests/test_ac_status.py +204 -10
  15. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.2}/tests/test_cli.py +49 -0
  16. python_xiaobiu-0.2.2/uv.lock +370 -0
  17. python_xiaobiu-0.2.0/uv.lock +0 -367
  18. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.2}/docs/plans/2026-06-01-ac-control-design/bdd-specs.md +0 -0
  19. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.2}/docs/plans/2026-06-01-ac-control-plan/_index.md +0 -0
  20. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.2}/docs/plans/2026-06-01-ac-control-plan/task-001-ac-enums-impl.md +0 -0
  21. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.2}/docs/plans/2026-06-01-ac-control-plan/task-001-ac-enums-test.md +0 -0
  22. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.2}/docs/plans/2026-06-01-ac-control-plan/task-002-ac-cmd-mappings-impl.md +0 -0
  23. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.2}/docs/plans/2026-06-01-ac-control-plan/task-002-ac-cmd-mappings-test.md +0 -0
  24. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.2}/docs/plans/2026-06-01-ac-control-plan/task-003-ac-app-oper-impl.md +0 -0
  25. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.2}/docs/plans/2026-06-01-ac-control-plan/task-003-ac-app-oper-test.md +0 -0
  26. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.2}/docs/plans/2026-06-01-ac-control-plan/task-004-ac-highlevel-impl.md +0 -0
  27. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.2}/docs/plans/2026-06-01-ac-control-plan/task-004-ac-highlevel-test.md +0 -0
  28. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.2}/docs/plans/2026-06-01-ac-control-plan/task-005-ac-panel-template-impl.md +0 -0
  29. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.2}/docs/plans/2026-06-01-ac-control-plan/task-005-ac-panel-template-test.md +0 -0
  30. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.2}/docs/plans/2026-06-01-ac-control-plan/task-006-ac-timers-impl.md +0 -0
  31. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.2}/docs/plans/2026-06-01-ac-control-plan/task-006-ac-timers-test.md +0 -0
  32. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.2}/docs/plans/2026-06-01-ac-control-plan/task-007-ac-state-hvac-impl.md +0 -0
  33. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.2}/docs/plans/2026-06-01-ac-control-plan/task-007-ac-state-hvac-test.md +0 -0
  34. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.2}/docs/plans/2026-06-01-ac-control-plan/task-008-cli-ac-control-impl.md +0 -0
  35. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.2}/docs/plans/2026-06-01-ac-control-plan/task-008-cli-ac-control-test.md +0 -0
  36. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.2}/docs/plans/2026-06-01-ac-control-plan/task-009-docs-readme-impl.md +0 -0
  37. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.2}/docs/plans/2026-06-02-ac-control-align-ha-design/bdd-specs.md +0 -0
  38. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.2}/docs/plans/2026-06-02-ac-control-align-ha-plan/_index.md +0 -0
  39. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.2}/src/xiaobiu/app_api.py +0 -0
  40. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.2}/src/xiaobiu/captcha_bridge.py +0 -0
  41. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.2}/src/xiaobiu/crypto.py +0 -0
  42. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.2}/src/xiaobiu/exceptions.py +0 -0
  43. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.2}/src/xiaobiu/har_templates.py +0 -0
  44. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.2}/src/xiaobiu/parsers.py +0 -0
  45. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.2}/src/xiaobiu/persistence.py +0 -0
  46. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.2}/src/xiaobiu/sms_login.py +0 -0
  47. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.2}/tests/__init__.py +0 -0
  48. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.2}/tests/test_app_api.py +0 -0
  49. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.2}/tests/test_captcha_bridge.py +0 -0
  50. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.2}/tests/test_client.py +0 -0
  51. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.2}/tests/test_crypto.py +0 -0
  52. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.2}/tests/test_har_templates.py +0 -0
  53. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.2}/tests/test_models.py +0 -0
  54. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.2}/tests/test_parsers.py +0 -0
  55. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.2}/tests/test_persistence.py +0 -0
  56. {python_xiaobiu-0.2.0 → 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,52 @@ 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
+
32
+ ## [0.2.1] - 2026-06-02
33
+
34
+ ### Added
35
+ - `HvacAction` enum (`OFF` / `PREHEATING` / `HEATING` / `COOLING` /
36
+ `DRYING` / `FAN` / `IDLE` / `DEFROSTING`) and
37
+ `AirConditionerStatus.hvac_action` field, inferred from
38
+ `power_on × hvac_mode × current_temp vs target_temp` so HA can
39
+ render the live state of the AC.
40
+ - `DeviceCapabilities` / `CapabilityField` models driven by the
41
+ device's panel template. `client.get_device_panel_template()`
42
+ now returns a `DeviceCapabilities` with `hvac_modes` /
43
+ `fan_modes` / `swing_modes` / `preset_modes` lists and per-field
44
+ metadata (raw / display / icon URLs) parsed from `queryTemplate.do`.
45
+ This lets HA integrators advertise exactly what the device supports
46
+ instead of hard-coding the lists.
47
+
48
+ ### Changed
49
+ - README "Air Conditioner Control" section now documents
50
+ `hvac_action` inference rules and shows a `DeviceCapabilities`
51
+ usage snippet.
52
+
7
53
  ## [0.2.0] - 2026-06-02
8
54
 
9
55
  ### Added
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-xiaobiu
3
- Version: 0.2.0
3
+ Version: 0.2.2
4
4
  Summary: Suning biu smart home SMS login and session client
5
5
  Project-URL: Homepage, https://github.com/FaintGhost/python-xiaobiu
6
6
  Project-URL: Bug Tracker, https://github.com/FaintGhost/python-xiaobiu/issues
@@ -12,9 +12,11 @@ Classifier: License :: OSI Approved :: MIT License
12
12
  Classifier: Operating System :: OS Independent
13
13
  Classifier: Programming Language :: Python :: 3
14
14
  Requires-Python: >=3.14
15
- Requires-Dist: cryptography>=44.0.0
15
+ Requires-Dist: cryptography>=48.0.1
16
+ Requires-Dist: idna>=3.15
16
17
  Requires-Dist: pydantic>=2.0.0
17
- Requires-Dist: requests>=2.28.0
18
+ Requires-Dist: requests>=2.33.0
19
+ Requires-Dist: urllib3>=2.7.0
18
20
  Description-Content-Type: text/markdown
19
21
 
20
22
  # python-xiaobiu
@@ -71,12 +73,12 @@ client.turn_on(family_id=37790, device_id="000165f9b029afa2e5d8")
71
73
  client.turn_off(family_id=37790, device_id="000165f9b029afa2e5d8")
72
74
 
73
75
  # 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, 待实测确认)
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 同)
80
82
 
81
83
  # Temperature
82
84
  client.set_temperature(family_id=37790, device_id="...", value=24.0) # 16.0–32.0
@@ -115,19 +117,75 @@ client.get_device_panel_template(family_id=37790, device_id="...")
115
117
  | Suning App | `xiaobiu` API | `C_*` field | HA climate field |
116
118
  |------------|---------------|------------|------------------|
117
119
  | 电源开关 | `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) |
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` |
124
125
  | 微风/低/中/高/强风 | `set_fan_mode(SILENT/LOW/MEDIUM/HIGH/TURBO)` | `C_FANSPEED=1..5` | `fan_mode` |
125
- | 上下摆风 | `set_vertical_swing(on=)` | `C_AIRVERTICAL` | `swing_vertical_mode` |
126
+ | 上下摆风 | `set_vertical_swing(on=)` | `C_AIRVERTICAL` | `swing_mode` (HA 把 `swing_mode` 默认指垂直) |
126
127
  | 左右摆风 | `set_horizontal_swing(on=)` | `C_AIRHORIZONTAL` | `swing_horizontal_mode` |
127
128
  | ECO | `set_eco(on=)` | `C_ECO` | `preset_mode = eco` |
128
129
  | 空气清新 | `set_fresh_air(on=)` | `C_FRESHAIR` | `preset_mode = fresh_air` |
129
130
  | 电辅热 | `set_aux_heat(on=)` | `C_ELECHEATING` | `preset_mode = aux_heat` |
130
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
+
137
+ ### `swing_mode` 集成注意事项
138
+
139
+ 按 Home Assistant climate entity 惯例:
140
+
141
+ - **`swing_mode` 属性专指垂直摆风**。HA 集成作者应在 `async_set_swing_mode(swing_mode)` 里把 `"vertical"` / `"off"` 映射到 `client.set_swing_mode(SwingMode.VERTICAL)` / `SwingMode.OFF`。
142
+ - **`swing_horizontal_mode` 是独立属性**。`"on"` / `"off"` 映射到 `client.set_horizontal_swing(on=True/False)`。
143
+ - **`SwingMode.ON` 不支持**。苏宁设备物理上没有"开摆不指定方向"语义——要么 vertical 要么 horizontal,要么都开。HA 集成遇到 `swing_mode = "on"` 时应映射到 `SwingMode.BOTH`(或 `VERTICAL`)。
144
+ - **`set_swing_mode(SwingMode.HORIZONTAL)` 与 `set_horizontal_swing(on=True)` 设备层等价**(都把 `C_AIRHORIZONTAL` 设为 1),但**HA 集成应走 `set_horizontal_swing`** 保持与 HA 字段语义一致。`set_swing_mode(SwingMode.HORIZONTAL)` 主要给脚本/手动控制用,一次发两字段。
145
+ - **`set_swing_mode(SwingMode.BOTH)` 等价于 `set_vertical_swing(on=True); set_horizontal_swing(on=True)`,但只走一次网络**。HA 集成没有"BOTH"标准值,组合调用更标准。
146
+
147
+ ### `hvac_action` 推断
148
+
149
+ `AirConditionerStatus.hvac_action` 由 `ac_control.infer_hvac_action` 在 `_normalize_air_conditioner_status` 时填入,推断规则:
150
+
151
+ | 条件 | 推断 |
152
+ |------|------|
153
+ | `power_on=False` 或 `hvac_mode=off` | `HvacAction.OFF` |
154
+ | `hvac_mode=heat` 且 `current_temp < target_temp` | `HvacAction.HEATING` |
155
+ | `hvac_mode=heat` 且 `current_temp >= target_temp` | `HvacAction.IDLE` |
156
+ | `hvac_mode=cool` 且 `current_temp > target_temp` | `HvacAction.COOLING` |
157
+ | `hvac_mode=cool` 且 `current_temp <= target_temp` | `HvacAction.IDLE` |
158
+ | `hvac_mode=dry` | `HvacAction.DRYING` |
159
+ | `hvac_mode=fan_only` | `HvacAction.FAN` |
160
+ | `hvac_mode=auto` / `heat_cool` | 根据 current vs target 二选一(heating/cooling/idle) |
161
+ | `power_on=None`(设备离线) | `HvacAction=None` → HA 渲染 `unavailable` |
162
+
163
+ ### 动态能力表(`DeviceCapabilities`)
164
+
165
+ `client.get_device_panel_template(family_id, device_id)` 现在返回 `DeviceCapabilities`,从 `queryTemplate.do` 实时解析:
166
+
167
+ ```python
168
+ caps = client.get_device_panel_template(family_id=37790, device_id="000165f9b029afa2e5d8")
169
+ caps.hvac_modes # ["off", "cool", "heat", "dry", "fan_only", "auto", "quick"]
170
+ caps.fan_modes # ["auto", "silent", "low", "medium", "high", "turbo"]
171
+ caps.swing_modes # ["off", "vertical", "horizontal", "both"]
172
+ caps.preset_modes # ["none", "eco", "fresh_air", "aux_heat"]
173
+ caps.supports_vertical_swing # True
174
+ caps.supports_horizontal_swing # True
175
+ caps.supports_eco
176
+ caps.supports_fresh_air
177
+ caps.supports_aux_heat
178
+ caps.fields["C_FANSPEED"].raw_values # ["0","1","2","3","4","5"]
179
+ caps.fields["C_FANSPEED"].display_values # ["自动","微风","低风","中风","高风","强风"]
180
+ caps.fields["C_FANSPEED"].icon_urls # [6 个图标 URL]
181
+ ```
182
+
183
+ HA 集成应在 `async_setup_entry` 时调一次 `get_device_panel_template` 缓存起来,**直接喂给 `hvac_modes` / `fan_modes` / `swing_modes` / `preset_modes` 属性**——不要再硬编码列表。
184
+
185
+ ### `preset_mode` 自定义值
186
+
187
+ 按 HA 文档,自定义 preset 是允许的("you're also allowed to add custom presets")。所以 `fresh_air` 和 `aux_heat` 不在 HA 标准列表里,但 HA 集成**可以**把它们放进 `preset_modes` 列表(中文用户友好)或直接用 `aux_heat` 这个 HA 官方名(与 `turn_aux_heat_on/off` 服务对应)。
188
+
131
189
  ## CLI
132
190
 
133
191
  ```bash
@@ -157,18 +215,19 @@ xiaobiucli set-fresh-air --family-id 37790 --device-id <id> --on|--off
157
215
  xiaobiucli set-aux-heat --family-id 37790 --device-id <id> --on|--off
158
216
  xiaobiucli timers --family-id 37790 --device-id <id>
159
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 ...]
160
219
  ```
161
220
 
162
221
  ## Notes
163
222
 
164
- - **`C_MODE=5` → `HvacMode.QUICK`** (一键通) is **inferred** — the 2026-06-01
165
- HAR did not capture that button, and the App has no other unused mode
166
- value in the 0–7 range. Please confirm against a live device once
167
- and adjust if the App maps a different number to 一键通.
168
- - **`C_ELECHEATING` (电辅热)** was surfaced by `queryTemplate.do` and
169
- the value is inferred to be `0/1`. `set_aux_heat(on=True)` enforces
170
- the App's "only while heating" rule at the client (raises
171
- `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`)。
172
231
  - **`SN_CLOUD_TIMER` writes** are not implemented in this release.
173
232
  - **Unknown `C_MODE` values** (e.g. `7`, which neither the App nor the
174
233
  capture expose) collapse to `hvac_mode = None` so Home Assistant can
@@ -52,12 +52,12 @@ client.turn_on(family_id=37790, device_id="000165f9b029afa2e5d8")
52
52
  client.turn_off(family_id=37790, device_id="000165f9b029afa2e5d8")
53
53
 
54
54
  # 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, 待实测确认)
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 同)
61
61
 
62
62
  # Temperature
63
63
  client.set_temperature(family_id=37790, device_id="...", value=24.0) # 16.0–32.0
@@ -96,19 +96,75 @@ client.get_device_panel_template(family_id=37790, device_id="...")
96
96
  | Suning App | `xiaobiu` API | `C_*` field | HA climate field |
97
97
  |------------|---------------|------------|------------------|
98
98
  | 电源开关 | `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) |
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` |
105
104
  | 微风/低/中/高/强风 | `set_fan_mode(SILENT/LOW/MEDIUM/HIGH/TURBO)` | `C_FANSPEED=1..5` | `fan_mode` |
106
- | 上下摆风 | `set_vertical_swing(on=)` | `C_AIRVERTICAL` | `swing_vertical_mode` |
105
+ | 上下摆风 | `set_vertical_swing(on=)` | `C_AIRVERTICAL` | `swing_mode` (HA 把 `swing_mode` 默认指垂直) |
107
106
  | 左右摆风 | `set_horizontal_swing(on=)` | `C_AIRHORIZONTAL` | `swing_horizontal_mode` |
108
107
  | ECO | `set_eco(on=)` | `C_ECO` | `preset_mode = eco` |
109
108
  | 空气清新 | `set_fresh_air(on=)` | `C_FRESHAIR` | `preset_mode = fresh_air` |
110
109
  | 电辅热 | `set_aux_heat(on=)` | `C_ELECHEATING` | `preset_mode = aux_heat` |
111
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
+
116
+ ### `swing_mode` 集成注意事项
117
+
118
+ 按 Home Assistant climate entity 惯例:
119
+
120
+ - **`swing_mode` 属性专指垂直摆风**。HA 集成作者应在 `async_set_swing_mode(swing_mode)` 里把 `"vertical"` / `"off"` 映射到 `client.set_swing_mode(SwingMode.VERTICAL)` / `SwingMode.OFF`。
121
+ - **`swing_horizontal_mode` 是独立属性**。`"on"` / `"off"` 映射到 `client.set_horizontal_swing(on=True/False)`。
122
+ - **`SwingMode.ON` 不支持**。苏宁设备物理上没有"开摆不指定方向"语义——要么 vertical 要么 horizontal,要么都开。HA 集成遇到 `swing_mode = "on"` 时应映射到 `SwingMode.BOTH`(或 `VERTICAL`)。
123
+ - **`set_swing_mode(SwingMode.HORIZONTAL)` 与 `set_horizontal_swing(on=True)` 设备层等价**(都把 `C_AIRHORIZONTAL` 设为 1),但**HA 集成应走 `set_horizontal_swing`** 保持与 HA 字段语义一致。`set_swing_mode(SwingMode.HORIZONTAL)` 主要给脚本/手动控制用,一次发两字段。
124
+ - **`set_swing_mode(SwingMode.BOTH)` 等价于 `set_vertical_swing(on=True); set_horizontal_swing(on=True)`,但只走一次网络**。HA 集成没有"BOTH"标准值,组合调用更标准。
125
+
126
+ ### `hvac_action` 推断
127
+
128
+ `AirConditionerStatus.hvac_action` 由 `ac_control.infer_hvac_action` 在 `_normalize_air_conditioner_status` 时填入,推断规则:
129
+
130
+ | 条件 | 推断 |
131
+ |------|------|
132
+ | `power_on=False` 或 `hvac_mode=off` | `HvacAction.OFF` |
133
+ | `hvac_mode=heat` 且 `current_temp < target_temp` | `HvacAction.HEATING` |
134
+ | `hvac_mode=heat` 且 `current_temp >= target_temp` | `HvacAction.IDLE` |
135
+ | `hvac_mode=cool` 且 `current_temp > target_temp` | `HvacAction.COOLING` |
136
+ | `hvac_mode=cool` 且 `current_temp <= target_temp` | `HvacAction.IDLE` |
137
+ | `hvac_mode=dry` | `HvacAction.DRYING` |
138
+ | `hvac_mode=fan_only` | `HvacAction.FAN` |
139
+ | `hvac_mode=auto` / `heat_cool` | 根据 current vs target 二选一(heating/cooling/idle) |
140
+ | `power_on=None`(设备离线) | `HvacAction=None` → HA 渲染 `unavailable` |
141
+
142
+ ### 动态能力表(`DeviceCapabilities`)
143
+
144
+ `client.get_device_panel_template(family_id, device_id)` 现在返回 `DeviceCapabilities`,从 `queryTemplate.do` 实时解析:
145
+
146
+ ```python
147
+ caps = client.get_device_panel_template(family_id=37790, device_id="000165f9b029afa2e5d8")
148
+ caps.hvac_modes # ["off", "cool", "heat", "dry", "fan_only", "auto", "quick"]
149
+ caps.fan_modes # ["auto", "silent", "low", "medium", "high", "turbo"]
150
+ caps.swing_modes # ["off", "vertical", "horizontal", "both"]
151
+ caps.preset_modes # ["none", "eco", "fresh_air", "aux_heat"]
152
+ caps.supports_vertical_swing # True
153
+ caps.supports_horizontal_swing # True
154
+ caps.supports_eco
155
+ caps.supports_fresh_air
156
+ caps.supports_aux_heat
157
+ caps.fields["C_FANSPEED"].raw_values # ["0","1","2","3","4","5"]
158
+ caps.fields["C_FANSPEED"].display_values # ["自动","微风","低风","中风","高风","强风"]
159
+ caps.fields["C_FANSPEED"].icon_urls # [6 个图标 URL]
160
+ ```
161
+
162
+ HA 集成应在 `async_setup_entry` 时调一次 `get_device_panel_template` 缓存起来,**直接喂给 `hvac_modes` / `fan_modes` / `swing_modes` / `preset_modes` 属性**——不要再硬编码列表。
163
+
164
+ ### `preset_mode` 自定义值
165
+
166
+ 按 HA 文档,自定义 preset 是允许的("you're also allowed to add custom presets")。所以 `fresh_air` 和 `aux_heat` 不在 HA 标准列表里,但 HA 集成**可以**把它们放进 `preset_modes` 列表(中文用户友好)或直接用 `aux_heat` 这个 HA 官方名(与 `turn_aux_heat_on/off` 服务对应)。
167
+
112
168
  ## CLI
113
169
 
114
170
  ```bash
@@ -138,18 +194,19 @@ xiaobiucli set-fresh-air --family-id 37790 --device-id <id> --on|--off
138
194
  xiaobiucli set-aux-heat --family-id 37790 --device-id <id> --on|--off
139
195
  xiaobiucli timers --family-id 37790 --device-id <id>
140
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 ...]
141
198
  ```
142
199
 
143
200
  ## Notes
144
201
 
145
- - **`C_MODE=5` → `HvacMode.QUICK`** (一键通) is **inferred** — the 2026-06-01
146
- HAR did not capture that button, and the App has no other unused mode
147
- value in the 0–7 range. Please confirm against a live device once
148
- and adjust if the App maps a different number to 一键通.
149
- - **`C_ELECHEATING` (电辅热)** was surfaced by `queryTemplate.do` and
150
- the value is inferred to be `0/1`. `set_aux_heat(on=True)` enforces
151
- the App's "only while heating" rule at the client (raises
152
- `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`)。
153
210
  - **`SN_CLOUD_TIMER` writes** are not implemented in this release.
154
211
  - **Unknown `C_MODE` values** (e.g. `7`, which neither the App nor the
155
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.0"
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"
@@ -14,6 +14,7 @@ from .models import (
14
14
  FamilyInfo,
15
15
  FanSpeed,
16
16
  HAClimatePreview,
17
+ HvacAction,
17
18
  HvacMode,
18
19
  LoginPageConfig,
19
20
  PanelTemplate,
@@ -32,6 +33,7 @@ __all__ = [
32
33
  "FamilyInfo",
33
34
  "FanSpeed",
34
35
  "HAClimatePreview",
36
+ "HvacAction",
35
37
  "HvacMode",
36
38
  "LoginPageConfig",
37
39
  "PanelTemplate",