python-xiaobiu 0.1.1__py3-none-any.whl → 0.2.1__py3-none-any.whl

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.
@@ -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,18 @@
1
+ xiaobiu/__init__.py,sha256=vuubbRNBH7hN-QW8_-aYQcOjj10OQp26w_7imNU9KO8,837
2
+ xiaobiu/ac_control.py,sha256=y1TYVcUjpssBFy8LLjK2XqKXqy5nlox2-8sbIzHTp8w,19444
3
+ xiaobiu/ac_status.py,sha256=DkYQxxiBDuwIJgDPpMVxkErMrdKWHCmMB0PlWZQ4XGY,14605
4
+ xiaobiu/app_api.py,sha256=gJLa-iq60s_YEEM00E4lMcTsBKoV60GtaaqBsWWOWio,4729
5
+ xiaobiu/captcha_bridge.py,sha256=l8c3HnspQt1JDM1sDKnvcM4yvf7NZosSQ7x2AlO-kEA,12920
6
+ xiaobiu/cli.py,sha256=eDGyv5VCOP3O4l8HCJk_XtgxLPCAOR12zuB0CYpTdQI,17599
7
+ xiaobiu/client.py,sha256=44Ay-Yr0O74UXV6BuNOJrytaVmssHwNghPVE0U1fE-I,23047
8
+ xiaobiu/crypto.py,sha256=C0Lcp2Cfy-075hv65b1RYfn6UbiHneLhp4PhUftzzOk,2424
9
+ xiaobiu/exceptions.py,sha256=RKaity_UctboUGeC8QE0iF0KcqfYqlVHnfOQ2yXQT7c,1036
10
+ xiaobiu/har_templates.py,sha256=clatrCsn4_AxlSrpy99mJVThI34bFQpQQMoM-4H9e08,5562
11
+ xiaobiu/models.py,sha256=h6lhH0GQIgH9zUwmQLBBAY-SJBZjYr5LMxXqiRVrDOI,6223
12
+ xiaobiu/parsers.py,sha256=5Cb90sN5rw_SNv2BukOoiLmeG9Mxegq-XGkgE8YkxvU,3046
13
+ xiaobiu/persistence.py,sha256=k9ZES5DyE-OkptlLLw0jnBWwGtdDxgrn0YiVhAQ1V8c,887
14
+ xiaobiu/sms_login.py,sha256=5zQS_lhFvADdp6BnoenvSLdOSK1hWaT35rQQ4K3Ig-w,16394
15
+ python_xiaobiu-0.2.1.dist-info/METADATA,sha256=md0rsQR6QsSNdz9scltusVDM2gwYSaHN_p_atxxfULY,11785
16
+ python_xiaobiu-0.2.1.dist-info/WHEEL,sha256=mffPy8wBnZQn2VnJUU5jE99KsxaSfiyMHV9Yt0aLVxs,87
17
+ python_xiaobiu-0.2.1.dist-info/entry_points.txt,sha256=w1z8h63RRusoSGAbbSMpNcq4qbN3HOedsMlxwuFH3U8,44
18
+ python_xiaobiu-0.2.1.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: hatchling 1.29.0
2
+ Generator: hatchling 1.30.1
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
xiaobiu/__init__.py CHANGED
@@ -12,9 +12,16 @@ from .models import (
12
12
  AuthState,
13
13
  CaptchaSolution,
14
14
  FamilyInfo,
15
+ FanSpeed,
15
16
  HAClimatePreview,
17
+ HvacAction,
18
+ HvacMode,
16
19
  LoginPageConfig,
20
+ PanelTemplate,
21
+ PresetMode,
17
22
  SignedRequestTemplate,
23
+ SwingMode,
24
+ Timer,
18
25
  )
19
26
 
20
27
  __all__ = [
@@ -24,12 +31,19 @@ __all__ = [
24
31
  "CaptchaRequiredError",
25
32
  "CaptchaSolution",
26
33
  "FamilyInfo",
34
+ "FanSpeed",
27
35
  "HAClimatePreview",
36
+ "HvacAction",
37
+ "HvacMode",
28
38
  "LoginPageConfig",
39
+ "PanelTemplate",
40
+ "PresetMode",
29
41
  "SmsRateLimitedError",
30
42
  "SignedRequestTemplate",
31
43
  "SuningError",
32
44
  "SuningSmartHomeClient",
45
+ "SwingMode",
46
+ "Timer",
33
47
  "main",
34
48
  "parse_jsonp_or_json",
35
49
  ]