python-xiaobiu 0.1.1__tar.gz → 0.2.1__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 (58) hide show
  1. {python_xiaobiu-0.1.1 → python_xiaobiu-0.2.1}/.gitignore +1 -0
  2. python_xiaobiu-0.2.1/CHANGELOG.md +95 -0
  3. python_xiaobiu-0.2.1/PKG-INFO +232 -0
  4. python_xiaobiu-0.2.1/README.md +213 -0
  5. python_xiaobiu-0.2.1/docs/plans/2026-06-01-ac-control-design/bdd-specs.md +305 -0
  6. python_xiaobiu-0.2.1/docs/plans/2026-06-01-ac-control-plan/_index.md +80 -0
  7. python_xiaobiu-0.2.1/docs/plans/2026-06-01-ac-control-plan/task-001-ac-enums-impl.md +43 -0
  8. python_xiaobiu-0.2.1/docs/plans/2026-06-01-ac-control-plan/task-001-ac-enums-test.md +43 -0
  9. python_xiaobiu-0.2.1/docs/plans/2026-06-01-ac-control-plan/task-002-ac-cmd-mappings-impl.md +44 -0
  10. python_xiaobiu-0.2.1/docs/plans/2026-06-01-ac-control-plan/task-002-ac-cmd-mappings-test.md +56 -0
  11. python_xiaobiu-0.2.1/docs/plans/2026-06-01-ac-control-plan/task-003-ac-app-oper-impl.md +42 -0
  12. python_xiaobiu-0.2.1/docs/plans/2026-06-01-ac-control-plan/task-003-ac-app-oper-test.md +68 -0
  13. python_xiaobiu-0.2.1/docs/plans/2026-06-01-ac-control-plan/task-004-ac-highlevel-impl.md +65 -0
  14. python_xiaobiu-0.2.1/docs/plans/2026-06-01-ac-control-plan/task-004-ac-highlevel-test.md +48 -0
  15. python_xiaobiu-0.2.1/docs/plans/2026-06-01-ac-control-plan/task-005-ac-panel-template-impl.md +45 -0
  16. python_xiaobiu-0.2.1/docs/plans/2026-06-01-ac-control-plan/task-005-ac-panel-template-test.md +64 -0
  17. python_xiaobiu-0.2.1/docs/plans/2026-06-01-ac-control-plan/task-006-ac-timers-impl.md +37 -0
  18. python_xiaobiu-0.2.1/docs/plans/2026-06-01-ac-control-plan/task-006-ac-timers-test.md +60 -0
  19. python_xiaobiu-0.2.1/docs/plans/2026-06-01-ac-control-plan/task-007-ac-state-hvac-impl.md +51 -0
  20. python_xiaobiu-0.2.1/docs/plans/2026-06-01-ac-control-plan/task-007-ac-state-hvac-test.md +57 -0
  21. python_xiaobiu-0.2.1/docs/plans/2026-06-01-ac-control-plan/task-008-cli-ac-control-impl.md +121 -0
  22. python_xiaobiu-0.2.1/docs/plans/2026-06-01-ac-control-plan/task-008-cli-ac-control-test.md +49 -0
  23. python_xiaobiu-0.2.1/docs/plans/2026-06-01-ac-control-plan/task-009-docs-readme-impl.md +40 -0
  24. python_xiaobiu-0.2.1/docs/plans/2026-06-02-ac-control-align-ha-design/bdd-specs.md +149 -0
  25. python_xiaobiu-0.2.1/docs/plans/2026-06-02-ac-control-align-ha-plan/_index.md +61 -0
  26. {python_xiaobiu-0.1.1 → python_xiaobiu-0.2.1}/pyproject.toml +1 -1
  27. {python_xiaobiu-0.1.1 → python_xiaobiu-0.2.1}/src/xiaobiu/__init__.py +14 -0
  28. python_xiaobiu-0.2.1/src/xiaobiu/ac_control.py +658 -0
  29. python_xiaobiu-0.2.1/src/xiaobiu/ac_status.py +441 -0
  30. python_xiaobiu-0.2.1/src/xiaobiu/app_api.py +163 -0
  31. python_xiaobiu-0.2.1/src/xiaobiu/cli.py +534 -0
  32. python_xiaobiu-0.2.1/src/xiaobiu/client.py +687 -0
  33. python_xiaobiu-0.2.1/src/xiaobiu/exceptions.py +40 -0
  34. python_xiaobiu-0.2.1/src/xiaobiu/har_templates.py +190 -0
  35. {python_xiaobiu-0.1.1 → python_xiaobiu-0.2.1}/src/xiaobiu/models.py +103 -0
  36. python_xiaobiu-0.2.1/src/xiaobiu/parsers.py +94 -0
  37. python_xiaobiu-0.2.1/src/xiaobiu/persistence.py +36 -0
  38. python_xiaobiu-0.2.1/src/xiaobiu/sms_login.py +535 -0
  39. python_xiaobiu-0.2.1/tests/test_ac_control.py +759 -0
  40. python_xiaobiu-0.1.1/tests/test_client.py → python_xiaobiu-0.2.1/tests/test_ac_status.py +291 -286
  41. python_xiaobiu-0.2.1/tests/test_app_api.py +67 -0
  42. python_xiaobiu-0.2.1/tests/test_cli.py +533 -0
  43. python_xiaobiu-0.2.1/tests/test_client.py +13 -0
  44. python_xiaobiu-0.2.1/tests/test_har_templates.py +274 -0
  45. python_xiaobiu-0.2.1/tests/test_models.py +105 -0
  46. python_xiaobiu-0.2.1/tests/test_parsers.py +81 -0
  47. python_xiaobiu-0.2.1/tests/test_persistence.py +48 -0
  48. python_xiaobiu-0.2.1/tests/test_sms_login.py +213 -0
  49. {python_xiaobiu-0.1.1 → python_xiaobiu-0.2.1}/uv.lock +1 -1
  50. python_xiaobiu-0.1.1/PKG-INFO +0 -68
  51. python_xiaobiu-0.1.1/README.md +0 -49
  52. python_xiaobiu-0.1.1/src/xiaobiu/client.py +0 -1557
  53. {python_xiaobiu-0.1.1 → python_xiaobiu-0.2.1}/.github/workflows/python-publish.yml +0 -0
  54. {python_xiaobiu-0.1.1 → python_xiaobiu-0.2.1}/src/xiaobiu/captcha_bridge.py +0 -0
  55. {python_xiaobiu-0.1.1 → python_xiaobiu-0.2.1}/src/xiaobiu/crypto.py +0 -0
  56. {python_xiaobiu-0.1.1 → python_xiaobiu-0.2.1}/tests/__init__.py +0 -0
  57. {python_xiaobiu-0.1.1 → python_xiaobiu-0.2.1}/tests/test_captcha_bridge.py +0 -0
  58. {python_xiaobiu-0.1.1 → python_xiaobiu-0.2.1}/tests/test_crypto.py +0 -0
@@ -4,6 +4,7 @@ build/
4
4
  dist/
5
5
  *.egg-info/
6
6
  .pytest_cache/
7
+ .coverage
7
8
  .venv/
8
9
  *.suning-session*.json
9
10
  *.har
@@ -0,0 +1,95 @@
1
+ # Changelog
2
+
3
+ All notable changes to `python-xiaobiu` are documented in this file.
4
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
5
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [0.2.1] - 2026-06-02
8
+
9
+ ### Added
10
+ - `HvacAction` enum (`OFF` / `PREHEATING` / `HEATING` / `COOLING` /
11
+ `DRYING` / `FAN` / `IDLE` / `DEFROSTING`) and
12
+ `AirConditionerStatus.hvac_action` field, inferred from
13
+ `power_on × hvac_mode × current_temp vs target_temp` so HA can
14
+ render the live state of the AC.
15
+ - `DeviceCapabilities` / `CapabilityField` models driven by the
16
+ device's panel template. `client.get_device_panel_template()`
17
+ now returns a `DeviceCapabilities` with `hvac_modes` /
18
+ `fan_modes` / `swing_modes` / `preset_modes` lists and per-field
19
+ metadata (raw / display / icon URLs) parsed from `queryTemplate.do`.
20
+ This lets HA integrators advertise exactly what the device supports
21
+ instead of hard-coding the lists.
22
+
23
+ ### Changed
24
+ - README "Air Conditioner Control" section now documents
25
+ `hvac_action` inference rules and shows a `DeviceCapabilities`
26
+ usage snippet.
27
+
28
+ ## [0.2.0] - 2026-06-02
29
+
30
+ ### Added
31
+ - Air-conditioner control surface: `turn_on` / `turn_off` / `set_hvac_mode` /
32
+ `set_temperature` / `set_fan_mode` / `set_swing_mode` / `set_preset_mode` /
33
+ `app_oper` on `SuningSmartHomeClient`.
34
+ - Independent boolean setters (HA-aligned): `set_eco` / `set_fresh_air` /
35
+ `set_aux_heat` / `set_vertical_swing` / `set_horizontal_swing`.
36
+ - `HvacMode.QUICK` for the inferred one-touch mode (C_MODE=5).
37
+ - Device introspection: `get_device_panel_template` / `list_device_timers`.
38
+ - Typed enums aligned with the
39
+ [Home Assistant climate entity](https://developers.home-assistant.io/docs/core/entity/climate/):
40
+ `HvacMode` / `FanSpeed` / `SwingMode` / `PresetMode` / `PanelTemplate` / `Timer`.
41
+ - Strongly-typed `hvac_mode` inference in `AirConditionerStatus` from the
42
+ raw `C_MODE` / `SN_MODE` + `C_POWER` fields (offline devices report
43
+ `None`).
44
+ - New CLI sub-commands: `control`, `set-mode`, `set-temperature`,
45
+ `set-fan`, `set-swing`, `set-vertical-swing`, `set-horizontal-swing`,
46
+ `set-eco`, `set-fresh-air`, `set-aux-heat`, `timers`, `panel`.
47
+ - `set_aux_heat(on=True)` enforces the App's "aux heat only while
48
+ heating" rule (raises `SuningError` if the current `hvac_mode` is
49
+ not `HEAT`).
50
+ - `AirConditionerStatus.ha_climate_preview.notes` now surfaces the raw
51
+ `C_ELECHEATING` field when the device reports it.
52
+
53
+ ### Changed
54
+ - **Breaking**: `FanSpeed` enum values renamed to match HA climate
55
+ fan modes — `LOW→SILENT`, `MID→LOW`, `HIGH→MEDIUM`, `HIGHER→HIGH`,
56
+ `HIGHEST→TURBO`. The `C_FANSPEED` raw value mapping (0..5) is
57
+ unchanged.
58
+ - **Breaking**: `set_hvac_mode(HvacMode.OFF)` no longer sends
59
+ `{"C_MODE": "0"}`; it powers the device off via `{"C_POWER": "0"}`.
60
+ - `AirConditionerStatus` now carries a typed `hvac_mode` field (was
61
+ implicit / `None`).
62
+ - `client._resolve_ac_target` reads the `model` field returned by
63
+ the live `list_devices` endpoint (was `modelId`).
64
+ - README: "Air Conditioner Control" section now includes a HA
65
+ climate entity mapping table and a Notes section flagging
66
+ `C_ELECHEATING` (untested) and `SN_CLOUD_TIMER` (writes not
67
+ implemented).
68
+
69
+ ### Removed
70
+ - **Breaking**: `SuningSmartHomeClient.set_electric_heating()` and
71
+ `ac_control.set_electric_heating()` were removed. Use
72
+ `set_aux_heat(on=...)` instead.
73
+
74
+ ### Refactored
75
+ - `client.py` (1990 lines, 36 defs/classes, god class) was split
76
+ into 8 focused modules: `exceptions`, `parsers`, `persistence`,
77
+ `app_api`, `sms_login`, `har_templates`, `ac_status`, `cli`.
78
+ `client.py` is now a 687-line thin façade with re-exports for
79
+ full backward compatibility of the public API.
80
+ - `tests/test_client.py` (1033 lines) was split into 7 focused test
81
+ files matching the new module boundaries.
82
+
83
+ ## [0.1.1] - 2026-03-22
84
+
85
+ ### Fixed
86
+ - `list_devices` now decodes the device payload shape returned by the
87
+ live API (familyId / id field).
88
+
89
+ ## [0.1.0] - 2026-03-21
90
+
91
+ ### Added
92
+ - Initial release: SMS login, captcha bridge, session persistence,
93
+ family / device enumeration, basic air-conditioner status read.
94
+ - `xiaobiucli` with `login`, `send-sms`, `check`, `families`,
95
+ `devices`, `device-status`, `keep-alive` sub-commands.
@@ -0,0 +1,232 @@
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
+ # python-xiaobiu
21
+
22
+ Python client for Suning smart home SMS login and session management.
23
+
24
+ Used by the [ha-suning](https://github.com/FaintGhost/ha-suning) Home Assistant custom integration.
25
+
26
+ ## Install
27
+
28
+ ```bash
29
+ pip install python-xiaobiu
30
+ ```
31
+
32
+ ## Usage
33
+
34
+ ```python
35
+ from xiaobiu import CaptchaRequiredError, SuningSmartHomeClient
36
+
37
+ client = SuningSmartHomeClient(state_path=".suning-session.json")
38
+
39
+ try:
40
+ client.send_sms_code("13800000000")
41
+ except CaptchaRequiredError as error:
42
+ print(error.risk_type, error.sms_ticket)
43
+
44
+ client.login_with_sms_code(phone_number="13800000000", sms_code="123456")
45
+ print(client.list_family_infos())
46
+ ```
47
+
48
+ ## Air Conditioner Control
49
+
50
+ Suning's "小标" App exposes a flat per-device control surface where every
51
+ button on the AC card maps to a single ``C_*`` field on the ``appOper``
52
+ endpoint. This client mirrors that surface and aligns the typed layer
53
+ with the [Home Assistant climate entity](https://developers.home-assistant.io/docs/core/entity/climate/).
54
+
55
+ ```python
56
+ from xiaobiu import (
57
+ FanSpeed,
58
+ HvacMode,
59
+ PresetMode,
60
+ SwingMode,
61
+ )
62
+
63
+ status = client.get_air_conditioner_status(
64
+ family_id=37790,
65
+ device_id="000165f9b029afa2e5d8",
66
+ )
67
+ print(status.hvac_mode) # HvacMode.{OFF,COOL,HEAT,FAN_ONLY,DRY,AUTO,QUICK} or None
68
+
69
+ # Power
70
+ client.turn_on(family_id=37790, device_id="000165f9b029afa2e5d8")
71
+ client.turn_off(family_id=37790, device_id="000165f9b029afa2e5d8")
72
+
73
+ # 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, 待实测确认)
80
+
81
+ # Temperature
82
+ client.set_temperature(family_id=37790, device_id="...", value=24.0) # 16.0–32.0
83
+
84
+ # Fan (App 标签 / C_FANSPEED raw / HA fan_mode)
85
+ client.set_fan_mode(family_id=37790, device_id="...", speed=FanSpeed.AUTO) # 自动 / 0 / auto
86
+ client.set_fan_mode(family_id=37790, device_id="...", speed=FanSpeed.SILENT) # 微风 / 1 / silent
87
+ client.set_fan_mode(family_id=37790, device_id="...", speed=FanSpeed.LOW) # 低风 / 2 / low
88
+ client.set_fan_mode(family_id=37790, device_id="...", speed=FanSpeed.MEDIUM) # 中风 / 3 / medium
89
+ client.set_fan_mode(family_id=37790, device_id="...", speed=FanSpeed.HIGH) # 高风 / 4 / high
90
+ client.set_fan_mode(family_id=37790, device_id="...", speed=FanSpeed.TURBO) # 强风 / 5 / turbo
91
+
92
+ # Swing (vertical/horizontal can be toggled independently)
93
+ client.set_vertical_swing(family_id=37790, device_id="...", on=True) # 上下摆风 开
94
+ client.set_vertical_swing(family_id=37790, device_id="...", on=False) # 上下摆风 关
95
+ client.set_horizontal_swing(family_id=37790, device_id="...", on=True) # 左右摆风 开
96
+ client.set_horizontal_swing(family_id=37790, device_id="...", on=False) # 左右摆风 关
97
+ # HA convenience setter that writes both fields at once
98
+ client.set_swing_mode(family_id=37790, device_id="...", swing=SwingMode.BOTH)
99
+
100
+ # Presets (each is a single boolean field)
101
+ client.set_eco(family_id=37790, device_id="...", on=True) # ECO 开
102
+ client.set_eco(family_id=37790, device_id="...", on=False) # ECO 关
103
+ client.set_fresh_air(family_id=37790, device_id="...", on=True) # 空气清新 开
104
+ client.set_fresh_air(family_id=37790, device_id="...", on=False) # 空气清新 关
105
+ client.set_aux_heat(family_id=37790, device_id="...", on=True) # 电辅热 开(仅制热)
106
+ client.set_aux_heat(family_id=37790, device_id="...", on=False) # 电辅热 关
107
+
108
+ # Read side
109
+ client.list_device_timers(family_id=37790, device_id="...")
110
+ client.get_device_panel_template(family_id=37790, device_id="...")
111
+ ```
112
+
113
+ ### HA climate entity mapping
114
+
115
+ | Suning App | `xiaobiu` API | `C_*` field | HA climate field |
116
+ |------------|---------------|------------|------------------|
117
+ | 电源开关 | `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) |
124
+ | 微风/低/中/高/强风 | `set_fan_mode(SILENT/LOW/MEDIUM/HIGH/TURBO)` | `C_FANSPEED=1..5` | `fan_mode` |
125
+ | 上下摆风 | `set_vertical_swing(on=)` | `C_AIRVERTICAL` | `swing_mode` (HA 把 `swing_mode` 默认指垂直) |
126
+ | 左右摆风 | `set_horizontal_swing(on=)` | `C_AIRHORIZONTAL` | `swing_horizontal_mode` |
127
+ | ECO | `set_eco(on=)` | `C_ECO` | `preset_mode = eco` |
128
+ | 空气清新 | `set_fresh_air(on=)` | `C_FRESHAIR` | `preset_mode = fresh_air` |
129
+ | 电辅热 | `set_aux_heat(on=)` | `C_ELECHEATING` | `preset_mode = aux_heat` |
130
+
131
+ ### `swing_mode` 集成注意事项
132
+
133
+ 按 Home Assistant climate entity 惯例:
134
+
135
+ - **`swing_mode` 属性专指垂直摆风**。HA 集成作者应在 `async_set_swing_mode(swing_mode)` 里把 `"vertical"` / `"off"` 映射到 `client.set_swing_mode(SwingMode.VERTICAL)` / `SwingMode.OFF`。
136
+ - **`swing_horizontal_mode` 是独立属性**。`"on"` / `"off"` 映射到 `client.set_horizontal_swing(on=True/False)`。
137
+ - **`SwingMode.ON` 不支持**。苏宁设备物理上没有"开摆不指定方向"语义——要么 vertical 要么 horizontal,要么都开。HA 集成遇到 `swing_mode = "on"` 时应映射到 `SwingMode.BOTH`(或 `VERTICAL`)。
138
+ - **`set_swing_mode(SwingMode.HORIZONTAL)` 与 `set_horizontal_swing(on=True)` 设备层等价**(都把 `C_AIRHORIZONTAL` 设为 1),但**HA 集成应走 `set_horizontal_swing`** 保持与 HA 字段语义一致。`set_swing_mode(SwingMode.HORIZONTAL)` 主要给脚本/手动控制用,一次发两字段。
139
+ - **`set_swing_mode(SwingMode.BOTH)` 等价于 `set_vertical_swing(on=True); set_horizontal_swing(on=True)`,但只走一次网络**。HA 集成没有"BOTH"标准值,组合调用更标准。
140
+
141
+ ### `hvac_action` 推断
142
+
143
+ `AirConditionerStatus.hvac_action` 由 `ac_control.infer_hvac_action` 在 `_normalize_air_conditioner_status` 时填入,推断规则:
144
+
145
+ | 条件 | 推断 |
146
+ |------|------|
147
+ | `power_on=False` 或 `hvac_mode=off` | `HvacAction.OFF` |
148
+ | `hvac_mode=heat` 且 `current_temp < target_temp` | `HvacAction.HEATING` |
149
+ | `hvac_mode=heat` 且 `current_temp >= target_temp` | `HvacAction.IDLE` |
150
+ | `hvac_mode=cool` 且 `current_temp > target_temp` | `HvacAction.COOLING` |
151
+ | `hvac_mode=cool` 且 `current_temp <= target_temp` | `HvacAction.IDLE` |
152
+ | `hvac_mode=dry` | `HvacAction.DRYING` |
153
+ | `hvac_mode=fan_only` | `HvacAction.FAN` |
154
+ | `hvac_mode=auto` / `heat_cool` | 根据 current vs target 二选一(heating/cooling/idle) |
155
+ | `power_on=None`(设备离线) | `HvacAction=None` → HA 渲染 `unavailable` |
156
+
157
+ ### 动态能力表(`DeviceCapabilities`)
158
+
159
+ `client.get_device_panel_template(family_id, device_id)` 现在返回 `DeviceCapabilities`,从 `queryTemplate.do` 实时解析:
160
+
161
+ ```python
162
+ caps = client.get_device_panel_template(family_id=37790, device_id="000165f9b029afa2e5d8")
163
+ caps.hvac_modes # ["off", "cool", "heat", "dry", "fan_only", "auto", "quick"]
164
+ caps.fan_modes # ["auto", "silent", "low", "medium", "high", "turbo"]
165
+ caps.swing_modes # ["off", "vertical", "horizontal", "both"]
166
+ caps.preset_modes # ["none", "eco", "fresh_air", "aux_heat"]
167
+ caps.supports_vertical_swing # True
168
+ caps.supports_horizontal_swing # True
169
+ caps.supports_eco
170
+ caps.supports_fresh_air
171
+ caps.supports_aux_heat
172
+ caps.fields["C_FANSPEED"].raw_values # ["0","1","2","3","4","5"]
173
+ caps.fields["C_FANSPEED"].display_values # ["自动","微风","低风","中风","高风","强风"]
174
+ caps.fields["C_FANSPEED"].icon_urls # [6 个图标 URL]
175
+ ```
176
+
177
+ HA 集成应在 `async_setup_entry` 时调一次 `get_device_panel_template` 缓存起来,**直接喂给 `hvac_modes` / `fan_modes` / `swing_modes` / `preset_modes` 属性**——不要再硬编码列表。
178
+
179
+ ### `preset_mode` 自定义值
180
+
181
+ 按 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` 服务对应)。
182
+
183
+ ## CLI
184
+
185
+ ```bash
186
+ # Interactive login
187
+ xiaobiucli login --phone 13800000000 --state-file .suning-session.json
188
+
189
+ # Send SMS only
190
+ xiaobiucli send-sms --phone 13800000000 --state-file .suning-session.json
191
+
192
+ # Check session
193
+ xiaobiucli check --state-file .suning-session.json
194
+
195
+ # List families / devices
196
+ xiaobiucli families --state-file .suning-session.json
197
+ xiaobiucli devices --family-id 37790 --state-file .suning-session.json
198
+
199
+ # Air-conditioner control
200
+ xiaobiucli control --family-id 37790 --device-id <id> --power on|off
201
+ xiaobiucli set-mode --family-id 37790 --device-id <id> --mode off|cool|heat|fan_only|dry|auto|quick
202
+ xiaobiucli set-temperature --family-id 37790 --device-id <id> --temperature 24.0
203
+ xiaobiucli set-fan --family-id 37790 --device-id <id> --speed auto|silent|low|medium|high|turbo
204
+ xiaobiucli set-swing --family-id 37790 --device-id <id> --mode off|vertical|horizontal|both
205
+ xiaobiucli set-vertical-swing --family-id 37790 --device-id <id> --on|--off
206
+ xiaobiucli set-horizontal-swing --family-id 37790 --device-id <id> --on|--off
207
+ xiaobiucli set-eco --family-id 37790 --device-id <id> --on|--off
208
+ xiaobiucli set-fresh-air --family-id 37790 --device-id <id> --on|--off
209
+ xiaobiucli set-aux-heat --family-id 37790 --device-id <id> --on|--off
210
+ xiaobiucli timers --family-id 37790 --device-id <id>
211
+ xiaobiucli panel --family-id 37790 --device-id <id>
212
+ ```
213
+
214
+ ## Notes
215
+
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).
224
+ - **`SN_CLOUD_TIMER` writes** are not implemented in this release.
225
+ - **Unknown `C_MODE` values** (e.g. `7`, which neither the App nor the
226
+ capture expose) collapse to `hvac_mode = None` so Home Assistant can
227
+ render `unavailable` rather than guessing.
228
+
229
+ ## Requirements
230
+
231
+ - Python >= 3.14
232
+ - `cryptography`, `pydantic`, `requests`
@@ -0,0 +1,213 @@
1
+ # python-xiaobiu
2
+
3
+ Python client for Suning smart home SMS login and session management.
4
+
5
+ Used by the [ha-suning](https://github.com/FaintGhost/ha-suning) Home Assistant custom integration.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ pip install python-xiaobiu
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```python
16
+ from xiaobiu import CaptchaRequiredError, SuningSmartHomeClient
17
+
18
+ client = SuningSmartHomeClient(state_path=".suning-session.json")
19
+
20
+ try:
21
+ client.send_sms_code("13800000000")
22
+ except CaptchaRequiredError as error:
23
+ print(error.risk_type, error.sms_ticket)
24
+
25
+ client.login_with_sms_code(phone_number="13800000000", sms_code="123456")
26
+ print(client.list_family_infos())
27
+ ```
28
+
29
+ ## Air Conditioner Control
30
+
31
+ Suning's "小标" App exposes a flat per-device control surface where every
32
+ button on the AC card maps to a single ``C_*`` field on the ``appOper``
33
+ endpoint. This client mirrors that surface and aligns the typed layer
34
+ with the [Home Assistant climate entity](https://developers.home-assistant.io/docs/core/entity/climate/).
35
+
36
+ ```python
37
+ from xiaobiu import (
38
+ FanSpeed,
39
+ HvacMode,
40
+ PresetMode,
41
+ SwingMode,
42
+ )
43
+
44
+ status = client.get_air_conditioner_status(
45
+ family_id=37790,
46
+ device_id="000165f9b029afa2e5d8",
47
+ )
48
+ print(status.hvac_mode) # HvacMode.{OFF,COOL,HEAT,FAN_ONLY,DRY,AUTO,QUICK} or None
49
+
50
+ # Power
51
+ client.turn_on(family_id=37790, device_id="000165f9b029afa2e5d8")
52
+ client.turn_off(family_id=37790, device_id="000165f9b029afa2e5d8")
53
+
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, 待实测确认)
61
+
62
+ # Temperature
63
+ client.set_temperature(family_id=37790, device_id="...", value=24.0) # 16.0–32.0
64
+
65
+ # Fan (App 标签 / C_FANSPEED raw / HA fan_mode)
66
+ client.set_fan_mode(family_id=37790, device_id="...", speed=FanSpeed.AUTO) # 自动 / 0 / auto
67
+ client.set_fan_mode(family_id=37790, device_id="...", speed=FanSpeed.SILENT) # 微风 / 1 / silent
68
+ client.set_fan_mode(family_id=37790, device_id="...", speed=FanSpeed.LOW) # 低风 / 2 / low
69
+ client.set_fan_mode(family_id=37790, device_id="...", speed=FanSpeed.MEDIUM) # 中风 / 3 / medium
70
+ client.set_fan_mode(family_id=37790, device_id="...", speed=FanSpeed.HIGH) # 高风 / 4 / high
71
+ client.set_fan_mode(family_id=37790, device_id="...", speed=FanSpeed.TURBO) # 强风 / 5 / turbo
72
+
73
+ # Swing (vertical/horizontal can be toggled independently)
74
+ client.set_vertical_swing(family_id=37790, device_id="...", on=True) # 上下摆风 开
75
+ client.set_vertical_swing(family_id=37790, device_id="...", on=False) # 上下摆风 关
76
+ client.set_horizontal_swing(family_id=37790, device_id="...", on=True) # 左右摆风 开
77
+ client.set_horizontal_swing(family_id=37790, device_id="...", on=False) # 左右摆风 关
78
+ # HA convenience setter that writes both fields at once
79
+ client.set_swing_mode(family_id=37790, device_id="...", swing=SwingMode.BOTH)
80
+
81
+ # Presets (each is a single boolean field)
82
+ client.set_eco(family_id=37790, device_id="...", on=True) # ECO 开
83
+ client.set_eco(family_id=37790, device_id="...", on=False) # ECO 关
84
+ client.set_fresh_air(family_id=37790, device_id="...", on=True) # 空气清新 开
85
+ client.set_fresh_air(family_id=37790, device_id="...", on=False) # 空气清新 关
86
+ client.set_aux_heat(family_id=37790, device_id="...", on=True) # 电辅热 开(仅制热)
87
+ client.set_aux_heat(family_id=37790, device_id="...", on=False) # 电辅热 关
88
+
89
+ # Read side
90
+ client.list_device_timers(family_id=37790, device_id="...")
91
+ client.get_device_panel_template(family_id=37790, device_id="...")
92
+ ```
93
+
94
+ ### HA climate entity mapping
95
+
96
+ | Suning App | `xiaobiu` API | `C_*` field | HA climate field |
97
+ |------------|---------------|------------|------------------|
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) |
105
+ | 微风/低/中/高/强风 | `set_fan_mode(SILENT/LOW/MEDIUM/HIGH/TURBO)` | `C_FANSPEED=1..5` | `fan_mode` |
106
+ | 上下摆风 | `set_vertical_swing(on=)` | `C_AIRVERTICAL` | `swing_mode` (HA 把 `swing_mode` 默认指垂直) |
107
+ | 左右摆风 | `set_horizontal_swing(on=)` | `C_AIRHORIZONTAL` | `swing_horizontal_mode` |
108
+ | ECO | `set_eco(on=)` | `C_ECO` | `preset_mode = eco` |
109
+ | 空气清新 | `set_fresh_air(on=)` | `C_FRESHAIR` | `preset_mode = fresh_air` |
110
+ | 电辅热 | `set_aux_heat(on=)` | `C_ELECHEATING` | `preset_mode = aux_heat` |
111
+
112
+ ### `swing_mode` 集成注意事项
113
+
114
+ 按 Home Assistant climate entity 惯例:
115
+
116
+ - **`swing_mode` 属性专指垂直摆风**。HA 集成作者应在 `async_set_swing_mode(swing_mode)` 里把 `"vertical"` / `"off"` 映射到 `client.set_swing_mode(SwingMode.VERTICAL)` / `SwingMode.OFF`。
117
+ - **`swing_horizontal_mode` 是独立属性**。`"on"` / `"off"` 映射到 `client.set_horizontal_swing(on=True/False)`。
118
+ - **`SwingMode.ON` 不支持**。苏宁设备物理上没有"开摆不指定方向"语义——要么 vertical 要么 horizontal,要么都开。HA 集成遇到 `swing_mode = "on"` 时应映射到 `SwingMode.BOTH`(或 `VERTICAL`)。
119
+ - **`set_swing_mode(SwingMode.HORIZONTAL)` 与 `set_horizontal_swing(on=True)` 设备层等价**(都把 `C_AIRHORIZONTAL` 设为 1),但**HA 集成应走 `set_horizontal_swing`** 保持与 HA 字段语义一致。`set_swing_mode(SwingMode.HORIZONTAL)` 主要给脚本/手动控制用,一次发两字段。
120
+ - **`set_swing_mode(SwingMode.BOTH)` 等价于 `set_vertical_swing(on=True); set_horizontal_swing(on=True)`,但只走一次网络**。HA 集成没有"BOTH"标准值,组合调用更标准。
121
+
122
+ ### `hvac_action` 推断
123
+
124
+ `AirConditionerStatus.hvac_action` 由 `ac_control.infer_hvac_action` 在 `_normalize_air_conditioner_status` 时填入,推断规则:
125
+
126
+ | 条件 | 推断 |
127
+ |------|------|
128
+ | `power_on=False` 或 `hvac_mode=off` | `HvacAction.OFF` |
129
+ | `hvac_mode=heat` 且 `current_temp < target_temp` | `HvacAction.HEATING` |
130
+ | `hvac_mode=heat` 且 `current_temp >= target_temp` | `HvacAction.IDLE` |
131
+ | `hvac_mode=cool` 且 `current_temp > target_temp` | `HvacAction.COOLING` |
132
+ | `hvac_mode=cool` 且 `current_temp <= target_temp` | `HvacAction.IDLE` |
133
+ | `hvac_mode=dry` | `HvacAction.DRYING` |
134
+ | `hvac_mode=fan_only` | `HvacAction.FAN` |
135
+ | `hvac_mode=auto` / `heat_cool` | 根据 current vs target 二选一(heating/cooling/idle) |
136
+ | `power_on=None`(设备离线) | `HvacAction=None` → HA 渲染 `unavailable` |
137
+
138
+ ### 动态能力表(`DeviceCapabilities`)
139
+
140
+ `client.get_device_panel_template(family_id, device_id)` 现在返回 `DeviceCapabilities`,从 `queryTemplate.do` 实时解析:
141
+
142
+ ```python
143
+ caps = client.get_device_panel_template(family_id=37790, device_id="000165f9b029afa2e5d8")
144
+ caps.hvac_modes # ["off", "cool", "heat", "dry", "fan_only", "auto", "quick"]
145
+ caps.fan_modes # ["auto", "silent", "low", "medium", "high", "turbo"]
146
+ caps.swing_modes # ["off", "vertical", "horizontal", "both"]
147
+ caps.preset_modes # ["none", "eco", "fresh_air", "aux_heat"]
148
+ caps.supports_vertical_swing # True
149
+ caps.supports_horizontal_swing # True
150
+ caps.supports_eco
151
+ caps.supports_fresh_air
152
+ caps.supports_aux_heat
153
+ caps.fields["C_FANSPEED"].raw_values # ["0","1","2","3","4","5"]
154
+ caps.fields["C_FANSPEED"].display_values # ["自动","微风","低风","中风","高风","强风"]
155
+ caps.fields["C_FANSPEED"].icon_urls # [6 个图标 URL]
156
+ ```
157
+
158
+ HA 集成应在 `async_setup_entry` 时调一次 `get_device_panel_template` 缓存起来,**直接喂给 `hvac_modes` / `fan_modes` / `swing_modes` / `preset_modes` 属性**——不要再硬编码列表。
159
+
160
+ ### `preset_mode` 自定义值
161
+
162
+ 按 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` 服务对应)。
163
+
164
+ ## CLI
165
+
166
+ ```bash
167
+ # Interactive login
168
+ xiaobiucli login --phone 13800000000 --state-file .suning-session.json
169
+
170
+ # Send SMS only
171
+ xiaobiucli send-sms --phone 13800000000 --state-file .suning-session.json
172
+
173
+ # Check session
174
+ xiaobiucli check --state-file .suning-session.json
175
+
176
+ # List families / devices
177
+ xiaobiucli families --state-file .suning-session.json
178
+ xiaobiucli devices --family-id 37790 --state-file .suning-session.json
179
+
180
+ # Air-conditioner control
181
+ xiaobiucli control --family-id 37790 --device-id <id> --power on|off
182
+ xiaobiucli set-mode --family-id 37790 --device-id <id> --mode off|cool|heat|fan_only|dry|auto|quick
183
+ xiaobiucli set-temperature --family-id 37790 --device-id <id> --temperature 24.0
184
+ xiaobiucli set-fan --family-id 37790 --device-id <id> --speed auto|silent|low|medium|high|turbo
185
+ xiaobiucli set-swing --family-id 37790 --device-id <id> --mode off|vertical|horizontal|both
186
+ xiaobiucli set-vertical-swing --family-id 37790 --device-id <id> --on|--off
187
+ xiaobiucli set-horizontal-swing --family-id 37790 --device-id <id> --on|--off
188
+ xiaobiucli set-eco --family-id 37790 --device-id <id> --on|--off
189
+ xiaobiucli set-fresh-air --family-id 37790 --device-id <id> --on|--off
190
+ xiaobiucli set-aux-heat --family-id 37790 --device-id <id> --on|--off
191
+ xiaobiucli timers --family-id 37790 --device-id <id>
192
+ xiaobiucli panel --family-id 37790 --device-id <id>
193
+ ```
194
+
195
+ ## Notes
196
+
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).
205
+ - **`SN_CLOUD_TIMER` writes** are not implemented in this release.
206
+ - **Unknown `C_MODE` values** (e.g. `7`, which neither the App nor the
207
+ capture expose) collapse to `hvac_mode = None` so Home Assistant can
208
+ render `unavailable` rather than guessing.
209
+
210
+ ## Requirements
211
+
212
+ - Python >= 3.14
213
+ - `cryptography`, `pydantic`, `requests`