python-xiaobiu 0.1.0__tar.gz → 0.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. {python_xiaobiu-0.1.0 → python_xiaobiu-0.2.0}/.gitignore +1 -0
  2. python_xiaobiu-0.2.0/CHANGELOG.md +74 -0
  3. python_xiaobiu-0.2.0/PKG-INFO +180 -0
  4. python_xiaobiu-0.2.0/README.md +161 -0
  5. python_xiaobiu-0.2.0/docs/plans/2026-06-01-ac-control-design/bdd-specs.md +305 -0
  6. python_xiaobiu-0.2.0/docs/plans/2026-06-01-ac-control-plan/_index.md +80 -0
  7. python_xiaobiu-0.2.0/docs/plans/2026-06-01-ac-control-plan/task-001-ac-enums-impl.md +43 -0
  8. python_xiaobiu-0.2.0/docs/plans/2026-06-01-ac-control-plan/task-001-ac-enums-test.md +43 -0
  9. python_xiaobiu-0.2.0/docs/plans/2026-06-01-ac-control-plan/task-002-ac-cmd-mappings-impl.md +44 -0
  10. python_xiaobiu-0.2.0/docs/plans/2026-06-01-ac-control-plan/task-002-ac-cmd-mappings-test.md +56 -0
  11. python_xiaobiu-0.2.0/docs/plans/2026-06-01-ac-control-plan/task-003-ac-app-oper-impl.md +42 -0
  12. python_xiaobiu-0.2.0/docs/plans/2026-06-01-ac-control-plan/task-003-ac-app-oper-test.md +68 -0
  13. python_xiaobiu-0.2.0/docs/plans/2026-06-01-ac-control-plan/task-004-ac-highlevel-impl.md +65 -0
  14. python_xiaobiu-0.2.0/docs/plans/2026-06-01-ac-control-plan/task-004-ac-highlevel-test.md +48 -0
  15. python_xiaobiu-0.2.0/docs/plans/2026-06-01-ac-control-plan/task-005-ac-panel-template-impl.md +45 -0
  16. python_xiaobiu-0.2.0/docs/plans/2026-06-01-ac-control-plan/task-005-ac-panel-template-test.md +64 -0
  17. python_xiaobiu-0.2.0/docs/plans/2026-06-01-ac-control-plan/task-006-ac-timers-impl.md +37 -0
  18. python_xiaobiu-0.2.0/docs/plans/2026-06-01-ac-control-plan/task-006-ac-timers-test.md +60 -0
  19. python_xiaobiu-0.2.0/docs/plans/2026-06-01-ac-control-plan/task-007-ac-state-hvac-impl.md +51 -0
  20. python_xiaobiu-0.2.0/docs/plans/2026-06-01-ac-control-plan/task-007-ac-state-hvac-test.md +57 -0
  21. python_xiaobiu-0.2.0/docs/plans/2026-06-01-ac-control-plan/task-008-cli-ac-control-impl.md +121 -0
  22. python_xiaobiu-0.2.0/docs/plans/2026-06-01-ac-control-plan/task-008-cli-ac-control-test.md +49 -0
  23. python_xiaobiu-0.2.0/docs/plans/2026-06-01-ac-control-plan/task-009-docs-readme-impl.md +40 -0
  24. python_xiaobiu-0.2.0/docs/plans/2026-06-02-ac-control-align-ha-design/bdd-specs.md +149 -0
  25. python_xiaobiu-0.2.0/docs/plans/2026-06-02-ac-control-align-ha-plan/_index.md +61 -0
  26. {python_xiaobiu-0.1.0 → python_xiaobiu-0.2.0}/pyproject.toml +1 -1
  27. {python_xiaobiu-0.1.0 → python_xiaobiu-0.2.0}/src/xiaobiu/__init__.py +12 -0
  28. python_xiaobiu-0.2.0/src/xiaobiu/ac_control.py +494 -0
  29. python_xiaobiu-0.2.0/src/xiaobiu/ac_status.py +428 -0
  30. python_xiaobiu-0.2.0/src/xiaobiu/app_api.py +163 -0
  31. python_xiaobiu-0.2.0/src/xiaobiu/cli.py +534 -0
  32. python_xiaobiu-0.2.0/src/xiaobiu/client.py +687 -0
  33. python_xiaobiu-0.2.0/src/xiaobiu/exceptions.py +40 -0
  34. python_xiaobiu-0.2.0/src/xiaobiu/har_templates.py +190 -0
  35. {python_xiaobiu-0.1.0 → python_xiaobiu-0.2.0}/src/xiaobiu/models.py +49 -0
  36. python_xiaobiu-0.2.0/src/xiaobiu/parsers.py +94 -0
  37. python_xiaobiu-0.2.0/src/xiaobiu/persistence.py +36 -0
  38. python_xiaobiu-0.2.0/src/xiaobiu/sms_login.py +535 -0
  39. python_xiaobiu-0.2.0/tests/test_ac_control.py +568 -0
  40. python_xiaobiu-0.1.0/tests/test_client.py → python_xiaobiu-0.2.0/tests/test_ac_status.py +356 -286
  41. python_xiaobiu-0.2.0/tests/test_app_api.py +67 -0
  42. python_xiaobiu-0.2.0/tests/test_cli.py +533 -0
  43. python_xiaobiu-0.2.0/tests/test_client.py +13 -0
  44. python_xiaobiu-0.2.0/tests/test_har_templates.py +274 -0
  45. python_xiaobiu-0.2.0/tests/test_models.py +105 -0
  46. python_xiaobiu-0.2.0/tests/test_parsers.py +81 -0
  47. python_xiaobiu-0.2.0/tests/test_persistence.py +48 -0
  48. python_xiaobiu-0.2.0/tests/test_sms_login.py +213 -0
  49. {python_xiaobiu-0.1.0 → python_xiaobiu-0.2.0}/uv.lock +1 -1
  50. python_xiaobiu-0.1.0/PKG-INFO +0 -68
  51. python_xiaobiu-0.1.0/README.md +0 -49
  52. python_xiaobiu-0.1.0/src/xiaobiu/client.py +0 -1558
  53. {python_xiaobiu-0.1.0 → python_xiaobiu-0.2.0}/.github/workflows/python-publish.yml +0 -0
  54. {python_xiaobiu-0.1.0 → python_xiaobiu-0.2.0}/src/xiaobiu/captcha_bridge.py +0 -0
  55. {python_xiaobiu-0.1.0 → python_xiaobiu-0.2.0}/src/xiaobiu/crypto.py +0 -0
  56. {python_xiaobiu-0.1.0 → python_xiaobiu-0.2.0}/tests/__init__.py +0 -0
  57. {python_xiaobiu-0.1.0 → python_xiaobiu-0.2.0}/tests/test_captcha_bridge.py +0 -0
  58. {python_xiaobiu-0.1.0 → python_xiaobiu-0.2.0}/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,74 @@
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.0] - 2026-06-02
8
+
9
+ ### Added
10
+ - Air-conditioner control surface: `turn_on` / `turn_off` / `set_hvac_mode` /
11
+ `set_temperature` / `set_fan_mode` / `set_swing_mode` / `set_preset_mode` /
12
+ `app_oper` on `SuningSmartHomeClient`.
13
+ - Independent boolean setters (HA-aligned): `set_eco` / `set_fresh_air` /
14
+ `set_aux_heat` / `set_vertical_swing` / `set_horizontal_swing`.
15
+ - `HvacMode.QUICK` for the inferred one-touch mode (C_MODE=5).
16
+ - Device introspection: `get_device_panel_template` / `list_device_timers`.
17
+ - Typed enums aligned with the
18
+ [Home Assistant climate entity](https://developers.home-assistant.io/docs/core/entity/climate/):
19
+ `HvacMode` / `FanSpeed` / `SwingMode` / `PresetMode` / `PanelTemplate` / `Timer`.
20
+ - Strongly-typed `hvac_mode` inference in `AirConditionerStatus` from the
21
+ raw `C_MODE` / `SN_MODE` + `C_POWER` fields (offline devices report
22
+ `None`).
23
+ - New CLI sub-commands: `control`, `set-mode`, `set-temperature`,
24
+ `set-fan`, `set-swing`, `set-vertical-swing`, `set-horizontal-swing`,
25
+ `set-eco`, `set-fresh-air`, `set-aux-heat`, `timers`, `panel`.
26
+ - `set_aux_heat(on=True)` enforces the App's "aux heat only while
27
+ heating" rule (raises `SuningError` if the current `hvac_mode` is
28
+ not `HEAT`).
29
+ - `AirConditionerStatus.ha_climate_preview.notes` now surfaces the raw
30
+ `C_ELECHEATING` field when the device reports it.
31
+
32
+ ### Changed
33
+ - **Breaking**: `FanSpeed` enum values renamed to match HA climate
34
+ fan modes — `LOW→SILENT`, `MID→LOW`, `HIGH→MEDIUM`, `HIGHER→HIGH`,
35
+ `HIGHEST→TURBO`. The `C_FANSPEED` raw value mapping (0..5) is
36
+ unchanged.
37
+ - **Breaking**: `set_hvac_mode(HvacMode.OFF)` no longer sends
38
+ `{"C_MODE": "0"}`; it powers the device off via `{"C_POWER": "0"}`.
39
+ - `AirConditionerStatus` now carries a typed `hvac_mode` field (was
40
+ implicit / `None`).
41
+ - `client._resolve_ac_target` reads the `model` field returned by
42
+ the live `list_devices` endpoint (was `modelId`).
43
+ - README: "Air Conditioner Control" section now includes a HA
44
+ climate entity mapping table and a Notes section flagging
45
+ `C_ELECHEATING` (untested) and `SN_CLOUD_TIMER` (writes not
46
+ implemented).
47
+
48
+ ### Removed
49
+ - **Breaking**: `SuningSmartHomeClient.set_electric_heating()` and
50
+ `ac_control.set_electric_heating()` were removed. Use
51
+ `set_aux_heat(on=...)` instead.
52
+
53
+ ### Refactored
54
+ - `client.py` (1990 lines, 36 defs/classes, god class) was split
55
+ into 8 focused modules: `exceptions`, `parsers`, `persistence`,
56
+ `app_api`, `sms_login`, `har_templates`, `ac_status`, `cli`.
57
+ `client.py` is now a 687-line thin façade with re-exports for
58
+ full backward compatibility of the public API.
59
+ - `tests/test_client.py` (1033 lines) was split into 7 focused test
60
+ files matching the new module boundaries.
61
+
62
+ ## [0.1.1] - 2026-03-22
63
+
64
+ ### Fixed
65
+ - `list_devices` now decodes the device payload shape returned by the
66
+ live API (familyId / id field).
67
+
68
+ ## [0.1.0] - 2026-03-21
69
+
70
+ ### Added
71
+ - Initial release: SMS login, captcha bridge, session persistence,
72
+ family / device enumeration, basic air-conditioner status read.
73
+ - `xiaobiucli` with `login`, `send-sms`, `check`, `families`,
74
+ `devices`, `device-status`, `keep-alive` sub-commands.
@@ -0,0 +1,180 @@
1
+ Metadata-Version: 2.4
2
+ Name: python-xiaobiu
3
+ Version: 0.2.0
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_vertical_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
+ ## CLI
132
+
133
+ ```bash
134
+ # Interactive login
135
+ xiaobiucli login --phone 13800000000 --state-file .suning-session.json
136
+
137
+ # Send SMS only
138
+ xiaobiucli send-sms --phone 13800000000 --state-file .suning-session.json
139
+
140
+ # Check session
141
+ xiaobiucli check --state-file .suning-session.json
142
+
143
+ # List families / devices
144
+ xiaobiucli families --state-file .suning-session.json
145
+ xiaobiucli devices --family-id 37790 --state-file .suning-session.json
146
+
147
+ # Air-conditioner control
148
+ xiaobiucli control --family-id 37790 --device-id <id> --power on|off
149
+ xiaobiucli set-mode --family-id 37790 --device-id <id> --mode off|cool|heat|fan_only|dry|auto|quick
150
+ xiaobiucli set-temperature --family-id 37790 --device-id <id> --temperature 24.0
151
+ xiaobiucli set-fan --family-id 37790 --device-id <id> --speed auto|silent|low|medium|high|turbo
152
+ xiaobiucli set-swing --family-id 37790 --device-id <id> --mode off|vertical|horizontal|both
153
+ xiaobiucli set-vertical-swing --family-id 37790 --device-id <id> --on|--off
154
+ xiaobiucli set-horizontal-swing --family-id 37790 --device-id <id> --on|--off
155
+ xiaobiucli set-eco --family-id 37790 --device-id <id> --on|--off
156
+ xiaobiucli set-fresh-air --family-id 37790 --device-id <id> --on|--off
157
+ xiaobiucli set-aux-heat --family-id 37790 --device-id <id> --on|--off
158
+ xiaobiucli timers --family-id 37790 --device-id <id>
159
+ xiaobiucli panel --family-id 37790 --device-id <id>
160
+ ```
161
+
162
+ ## Notes
163
+
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).
172
+ - **`SN_CLOUD_TIMER` writes** are not implemented in this release.
173
+ - **Unknown `C_MODE` values** (e.g. `7`, which neither the App nor the
174
+ capture expose) collapse to `hvac_mode = None` so Home Assistant can
175
+ render `unavailable` rather than guessing.
176
+
177
+ ## Requirements
178
+
179
+ - Python >= 3.14
180
+ - `cryptography`, `pydantic`, `requests`
@@ -0,0 +1,161 @@
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_vertical_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
+ ## CLI
113
+
114
+ ```bash
115
+ # Interactive login
116
+ xiaobiucli login --phone 13800000000 --state-file .suning-session.json
117
+
118
+ # Send SMS only
119
+ xiaobiucli send-sms --phone 13800000000 --state-file .suning-session.json
120
+
121
+ # Check session
122
+ xiaobiucli check --state-file .suning-session.json
123
+
124
+ # List families / devices
125
+ xiaobiucli families --state-file .suning-session.json
126
+ xiaobiucli devices --family-id 37790 --state-file .suning-session.json
127
+
128
+ # Air-conditioner control
129
+ xiaobiucli control --family-id 37790 --device-id <id> --power on|off
130
+ xiaobiucli set-mode --family-id 37790 --device-id <id> --mode off|cool|heat|fan_only|dry|auto|quick
131
+ xiaobiucli set-temperature --family-id 37790 --device-id <id> --temperature 24.0
132
+ xiaobiucli set-fan --family-id 37790 --device-id <id> --speed auto|silent|low|medium|high|turbo
133
+ xiaobiucli set-swing --family-id 37790 --device-id <id> --mode off|vertical|horizontal|both
134
+ xiaobiucli set-vertical-swing --family-id 37790 --device-id <id> --on|--off
135
+ xiaobiucli set-horizontal-swing --family-id 37790 --device-id <id> --on|--off
136
+ xiaobiucli set-eco --family-id 37790 --device-id <id> --on|--off
137
+ xiaobiucli set-fresh-air --family-id 37790 --device-id <id> --on|--off
138
+ xiaobiucli set-aux-heat --family-id 37790 --device-id <id> --on|--off
139
+ xiaobiucli timers --family-id 37790 --device-id <id>
140
+ xiaobiucli panel --family-id 37790 --device-id <id>
141
+ ```
142
+
143
+ ## Notes
144
+
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).
153
+ - **`SN_CLOUD_TIMER` writes** are not implemented in this release.
154
+ - **Unknown `C_MODE` values** (e.g. `7`, which neither the App nor the
155
+ capture expose) collapse to `hvac_mode = None` so Home Assistant can
156
+ render `unavailable` rather than guessing.
157
+
158
+ ## Requirements
159
+
160
+ - Python >= 3.14
161
+ - `cryptography`, `pydantic`, `requests`