python-xiaobiu 0.2.0__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 (55) hide show
  1. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.1}/CHANGELOG.md +21 -0
  2. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.1}/PKG-INFO +54 -2
  3. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.1}/README.md +53 -1
  4. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.1}/pyproject.toml +1 -1
  5. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.1}/src/xiaobiu/__init__.py +2 -0
  6. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.1}/src/xiaobiu/ac_control.py +169 -5
  7. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.1}/src/xiaobiu/ac_status.py +13 -0
  8. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.1}/src/xiaobiu/models.py +54 -0
  9. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.1}/tests/test_ac_control.py +193 -2
  10. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.1}/uv.lock +1 -1
  11. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.1}/.github/workflows/python-publish.yml +0 -0
  12. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.1}/.gitignore +0 -0
  13. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.1}/docs/plans/2026-06-01-ac-control-design/bdd-specs.md +0 -0
  14. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.1}/docs/plans/2026-06-01-ac-control-plan/_index.md +0 -0
  15. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.1}/docs/plans/2026-06-01-ac-control-plan/task-001-ac-enums-impl.md +0 -0
  16. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.1}/docs/plans/2026-06-01-ac-control-plan/task-001-ac-enums-test.md +0 -0
  17. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.1}/docs/plans/2026-06-01-ac-control-plan/task-002-ac-cmd-mappings-impl.md +0 -0
  18. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.1}/docs/plans/2026-06-01-ac-control-plan/task-002-ac-cmd-mappings-test.md +0 -0
  19. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.1}/docs/plans/2026-06-01-ac-control-plan/task-003-ac-app-oper-impl.md +0 -0
  20. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.1}/docs/plans/2026-06-01-ac-control-plan/task-003-ac-app-oper-test.md +0 -0
  21. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.1}/docs/plans/2026-06-01-ac-control-plan/task-004-ac-highlevel-impl.md +0 -0
  22. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.1}/docs/plans/2026-06-01-ac-control-plan/task-004-ac-highlevel-test.md +0 -0
  23. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.1}/docs/plans/2026-06-01-ac-control-plan/task-005-ac-panel-template-impl.md +0 -0
  24. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.1}/docs/plans/2026-06-01-ac-control-plan/task-005-ac-panel-template-test.md +0 -0
  25. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.1}/docs/plans/2026-06-01-ac-control-plan/task-006-ac-timers-impl.md +0 -0
  26. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.1}/docs/plans/2026-06-01-ac-control-plan/task-006-ac-timers-test.md +0 -0
  27. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.1}/docs/plans/2026-06-01-ac-control-plan/task-007-ac-state-hvac-impl.md +0 -0
  28. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.1}/docs/plans/2026-06-01-ac-control-plan/task-007-ac-state-hvac-test.md +0 -0
  29. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.1}/docs/plans/2026-06-01-ac-control-plan/task-008-cli-ac-control-impl.md +0 -0
  30. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.1}/docs/plans/2026-06-01-ac-control-plan/task-008-cli-ac-control-test.md +0 -0
  31. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.1}/docs/plans/2026-06-01-ac-control-plan/task-009-docs-readme-impl.md +0 -0
  32. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.1}/docs/plans/2026-06-02-ac-control-align-ha-design/bdd-specs.md +0 -0
  33. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.1}/docs/plans/2026-06-02-ac-control-align-ha-plan/_index.md +0 -0
  34. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.1}/src/xiaobiu/app_api.py +0 -0
  35. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.1}/src/xiaobiu/captcha_bridge.py +0 -0
  36. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.1}/src/xiaobiu/cli.py +0 -0
  37. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.1}/src/xiaobiu/client.py +0 -0
  38. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.1}/src/xiaobiu/crypto.py +0 -0
  39. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.1}/src/xiaobiu/exceptions.py +0 -0
  40. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.1}/src/xiaobiu/har_templates.py +0 -0
  41. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.1}/src/xiaobiu/parsers.py +0 -0
  42. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.1}/src/xiaobiu/persistence.py +0 -0
  43. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.1}/src/xiaobiu/sms_login.py +0 -0
  44. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.1}/tests/__init__.py +0 -0
  45. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.1}/tests/test_ac_status.py +0 -0
  46. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.1}/tests/test_app_api.py +0 -0
  47. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.1}/tests/test_captcha_bridge.py +0 -0
  48. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.1}/tests/test_cli.py +0 -0
  49. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.1}/tests/test_client.py +0 -0
  50. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.1}/tests/test_crypto.py +0 -0
  51. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.1}/tests/test_har_templates.py +0 -0
  52. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.1}/tests/test_models.py +0 -0
  53. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.1}/tests/test_parsers.py +0 -0
  54. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.1}/tests/test_persistence.py +0 -0
  55. {python_xiaobiu-0.2.0 → python_xiaobiu-0.2.1}/tests/test_sms_login.py +0 -0
@@ -4,6 +4,27 @@ 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.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
+
7
28
  ## [0.2.0] - 2026-06-02
8
29
 
9
30
  ### 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.1
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
@@ -122,12 +122,64 @@ client.get_device_panel_template(family_id=37790, device_id="...")
122
122
  | 自动 | `set_hvac_mode(AUTO)` | `C_MODE=6` | `hvac_mode = auto` |
123
123
  | 一键通 | `set_hvac_mode(QUICK)` | `C_MODE=5` | `hvac_mode = auto` (map) |
124
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` |
125
+ | 上下摆风 | `set_vertical_swing(on=)` | `C_AIRVERTICAL` | `swing_mode` (HA 把 `swing_mode` 默认指垂直) |
126
126
  | 左右摆风 | `set_horizontal_swing(on=)` | `C_AIRHORIZONTAL` | `swing_horizontal_mode` |
127
127
  | ECO | `set_eco(on=)` | `C_ECO` | `preset_mode = eco` |
128
128
  | 空气清新 | `set_fresh_air(on=)` | `C_FRESHAIR` | `preset_mode = fresh_air` |
129
129
  | 电辅热 | `set_aux_heat(on=)` | `C_ELECHEATING` | `preset_mode = aux_heat` |
130
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
+
131
183
  ## CLI
132
184
 
133
185
  ```bash
@@ -103,12 +103,64 @@ client.get_device_panel_template(family_id=37790, device_id="...")
103
103
  | 自动 | `set_hvac_mode(AUTO)` | `C_MODE=6` | `hvac_mode = auto` |
104
104
  | 一键通 | `set_hvac_mode(QUICK)` | `C_MODE=5` | `hvac_mode = auto` (map) |
105
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` |
106
+ | 上下摆风 | `set_vertical_swing(on=)` | `C_AIRVERTICAL` | `swing_mode` (HA 把 `swing_mode` 默认指垂直) |
107
107
  | 左右摆风 | `set_horizontal_swing(on=)` | `C_AIRHORIZONTAL` | `swing_horizontal_mode` |
108
108
  | ECO | `set_eco(on=)` | `C_ECO` | `preset_mode = eco` |
109
109
  | 空气清新 | `set_fresh_air(on=)` | `C_FRESHAIR` | `preset_mode = fresh_air` |
110
110
  | 电辅热 | `set_aux_heat(on=)` | `C_ELECHEATING` | `preset_mode = aux_heat` |
111
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
+
112
164
  ## CLI
113
165
 
114
166
  ```bash
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "python-xiaobiu"
3
- version = "0.2.0"
3
+ version = "0.2.1"
4
4
  description = "Suning biu smart home SMS login and session client"
5
5
  readme = "README.md"
6
6
  license = { text = "MIT" }
@@ -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",
@@ -19,7 +19,10 @@ from typing import TYPE_CHECKING, Any, Mapping, Sequence
19
19
 
20
20
  from .exceptions import SuningError
21
21
  from .models import (
22
+ CapabilityField,
23
+ DeviceCapabilities,
22
24
  FanSpeed,
25
+ HvacAction,
23
26
  HvacMode,
24
27
  PanelTemplate,
25
28
  PresetMode,
@@ -169,11 +172,14 @@ def get_device_panel_template(
169
172
  model_id: str,
170
173
  *,
171
174
  category_id: str = "0002",
172
- ) -> PanelTemplate | None:
173
- """Fetch the runtime panel template for ``device_id``.
175
+ ) -> DeviceCapabilities | None:
176
+ """Fetch the device's :class:`DeviceCapabilities`.
174
177
 
175
178
  Returns ``None`` on any failure (HTTP error, malformed JSON, code != 0)
176
- so the caller can keep going on a partial response.
179
+ so the caller can keep going on a partial response. Kept the legacy
180
+ name for backward compatibility — the returned object's
181
+ :class:`DeviceCapabilities` includes a ``raw`` payload carrying the
182
+ unparsed template.
177
183
  """
178
184
 
179
185
  query = (
@@ -195,10 +201,122 @@ def get_device_panel_template(
195
201
  components = parse_panel_components(containers)
196
202
  if components is None:
197
203
  return None
198
- return PanelTemplate(
204
+ return build_capabilities_from_template(
199
205
  device_id=device_id,
200
206
  model_id=model_id,
201
- components=components,
207
+ category_id=category_id,
208
+ fields=components,
209
+ raw=data_block,
210
+ )
211
+
212
+
213
+ def build_capabilities_from_template(
214
+ *,
215
+ device_id: str,
216
+ model_id: str,
217
+ category_id: str,
218
+ fields: list[str],
219
+ raw: Mapping[str, Any] | None = None,
220
+ ) -> DeviceCapabilities:
221
+ """Build a :class:`DeviceCapabilities` from a flattened field set.
222
+
223
+ ``fields`` is the sorted list of ``C_*`` / ``SN_*`` keys returned by
224
+ :func:`parse_panel_components`. The boolean support flags are derived
225
+ from membership; the HA-facing ``*_modes`` lists always include
226
+ the standard ``off`` sentinel so the integration can render the
227
+ toggle.
228
+ """
229
+
230
+ raw_dict = dict(raw) if raw else {}
231
+ keys_block = raw_dict.get("keys") or []
232
+ field_map: dict[str, CapabilityField] = {}
233
+ for key_entry in keys_block:
234
+ if not isinstance(key_entry, Mapping):
235
+ continue
236
+ raw_key = str(key_entry.get("key") or "")
237
+ if not raw_key:
238
+ continue
239
+ field_map[raw_key] = CapabilityField(
240
+ key=raw_key,
241
+ name=str(key_entry.get("name") or raw_key),
242
+ type=str(key_entry.get("type") or ""),
243
+ raw_values=[str(v) for v in (key_entry.get("k") or [])],
244
+ display_values=[str(v) for v in (key_entry.get("v") or [])],
245
+ sn_property_id=key_entry.get("snPropertyId"),
246
+ icon_urls=[str(u) for u in (key_entry.get("icon") or [])],
247
+ raw=dict(key_entry),
248
+ )
249
+ # Fallback: when the panel template lacks a ``keys`` block, seed the
250
+ # field map with placeholder CapabilityFields derived from the
251
+ # flattened field set so callers can still ask ``"C_POWER" in
252
+ # caps.fields``.
253
+ for raw_key in fields:
254
+ if raw_key in field_map:
255
+ continue
256
+ field_map[raw_key] = CapabilityField(
257
+ key=raw_key,
258
+ name=raw_key,
259
+ type="",
260
+ )
261
+
262
+ has = set(fields)
263
+ hvac_modes: list[str] = []
264
+ # The device speaks a single C_MODE knob; we expose the HA-equivalent
265
+ # standard names. We never report HEAT_COOL because the AC has no
266
+ # range-control primitive — AUTO is the implicit form.
267
+ if "C_MODE" in has:
268
+ hvac_modes = [
269
+ HvacMode.OFF.value,
270
+ HvacMode.COOL.value,
271
+ HvacMode.HEAT.value,
272
+ HvacMode.DRY.value,
273
+ HvacMode.FAN_ONLY.value,
274
+ HvacMode.AUTO.value,
275
+ ]
276
+ # QUICK is inferred (C_MODE=5) so we add it when the field is present.
277
+ hvac_modes.append(HvacMode.QUICK.value)
278
+ fan_modes: list[str] = []
279
+ if "C_FANSPEED" in has:
280
+ fan_modes = [
281
+ FanSpeed.AUTO.value,
282
+ FanSpeed.SILENT.value,
283
+ FanSpeed.LOW.value,
284
+ FanSpeed.MEDIUM.value,
285
+ FanSpeed.HIGH.value,
286
+ FanSpeed.TURBO.value,
287
+ ]
288
+ swing_modes: list[str] = []
289
+ if "C_AIRVERTICAL" in has or "C_AIRHORIZONTAL" in has:
290
+ swing_modes = [
291
+ SwingMode.OFF.value,
292
+ SwingMode.VERTICAL.value,
293
+ SwingMode.HORIZONTAL.value,
294
+ SwingMode.BOTH.value,
295
+ ]
296
+ preset_modes: list[str] = [PresetMode.NONE.value]
297
+ if "C_ECO" in has:
298
+ preset_modes.append(PresetMode.ECO.value)
299
+ if "C_FRESHAIR" in has:
300
+ preset_modes.append(PresetMode.FRESH_AIR.value)
301
+ if "C_ELECHEATING" in has:
302
+ preset_modes.append(PresetMode.AUX_HEAT.value)
303
+
304
+ return DeviceCapabilities(
305
+ device_id=device_id,
306
+ model_id=model_id,
307
+ category_id=category_id,
308
+ fields=field_map,
309
+ hvac_modes=hvac_modes,
310
+ fan_modes=fan_modes,
311
+ swing_modes=swing_modes,
312
+ preset_modes=preset_modes,
313
+ supports_vertical_swing="C_AIRVERTICAL" in has,
314
+ supports_horizontal_swing="C_AIRHORIZONTAL" in has,
315
+ supports_eco="C_ECO" in has,
316
+ supports_fresh_air="C_FRESHAIR" in has,
317
+ supports_aux_heat="C_ELECHEATING" in has,
318
+ supports_target_temperature="C_TEMPERATURE" in has,
319
+ raw=raw_dict,
202
320
  )
203
321
 
204
322
 
@@ -269,6 +387,52 @@ def infer_fan_speed(speed_raw: Any) -> FanSpeed | None:
269
387
  return C_FIELD_TO_FAN.get(str(speed_raw).strip())
270
388
 
271
389
 
390
+ def infer_hvac_action(
391
+ *,
392
+ power_on: bool | None,
393
+ hvac_mode: HvacMode | str | None,
394
+ current_temp: float | None,
395
+ target_temp: float | None,
396
+ ) -> HvacAction | None:
397
+ """Infer the device's current :class:`HvacAction` from its status fields.
398
+
399
+ Power off → ``OFF``. Mode is ``DRY`` / ``FAN_ONLY`` → ``DRYING`` / ``FAN``.
400
+ Mode is ``HEAT`` or ``COOL`` → ``HEATING`` / ``COOLING`` if there is still
401
+ work to do (current temp below / above target), else ``IDLE``.
402
+ Mode is ``AUTO`` → behave like ``HEAT_COOL``: pick the side that has work.
403
+ ``HEAT_COOL`` itself collapses to whichever side has work (else ``IDLE``).
404
+ When ``power_on`` is unknown we return ``None`` so HA can render
405
+ ``unavailable`` rather than guess.
406
+ """
407
+
408
+ if power_on is None:
409
+ return None
410
+ if power_on is False:
411
+ return HvacAction.OFF
412
+ if hvac_mode is None:
413
+ return HvacAction.IDLE
414
+ mode_value = hvac_mode.value if isinstance(hvac_mode, HvacMode) else str(hvac_mode)
415
+ if mode_value == HvacMode.OFF.value:
416
+ return HvacAction.OFF
417
+ if mode_value == HvacMode.DRY.value:
418
+ return HvacAction.DRYING
419
+ if mode_value == HvacMode.FAN_ONLY.value:
420
+ return HvacAction.FAN
421
+ if current_temp is None or target_temp is None:
422
+ return HvacAction.IDLE
423
+ if mode_value in (HvacMode.HEAT.value, HvacMode.QUICK.value):
424
+ return HvacAction.HEATING if current_temp < target_temp else HvacAction.IDLE
425
+ if mode_value == HvacMode.COOL.value:
426
+ return HvacAction.COOLING if current_temp > target_temp else HvacAction.IDLE
427
+ if mode_value in (HvacMode.AUTO.value, HvacMode.HEAT_COOL.value):
428
+ if current_temp < target_temp:
429
+ return HvacAction.HEATING
430
+ if current_temp > target_temp:
431
+ return HvacAction.COOLING
432
+ return HvacAction.IDLE
433
+ return HvacAction.IDLE
434
+
435
+
272
436
  # ---------------------------------------------------------------------------
273
437
  # High-level helpers
274
438
  # ---------------------------------------------------------------------------
@@ -23,8 +23,10 @@ from .models import (
23
23
  AirConditionerStatus,
24
24
  FamilyInfo,
25
25
  HAClimatePreview,
26
+ HvacAction,
26
27
  HvacMode,
27
28
  )
29
+ from . import ac_control
28
30
 
29
31
  MEMBER_BASE_INFO_URL = "https://shcss.suning.com/shcss-web/api/member/queryMemberBaseInfo.do"
30
32
  FAMILY_LIST_URL = "https://itapig.suning.com/api/trade/shcss/queryAllFamily"
@@ -233,6 +235,16 @@ def _normalize_air_conditioner_status(device: dict[str, Any]) -> AirConditionerS
233
235
  )
234
236
  mode_raw = _coalesce(raw_status.get("SN_MODE"), raw_status.get("C_MODE"))
235
237
  hvac_mode = infer_hvac_mode(power_on=power_on, mode_raw=mode_raw) if online else None
238
+ hvac_action = (
239
+ ac_control.infer_hvac_action(
240
+ power_on=power_on,
241
+ hvac_mode=hvac_mode,
242
+ current_temp=current_temperature,
243
+ target_temp=target_temperature,
244
+ )
245
+ if online
246
+ else None
247
+ )
236
248
 
237
249
  status = AirConditionerStatus(
238
250
  device_id=str(device.get("id")),
@@ -249,6 +261,7 @@ def _normalize_air_conditioner_status(device: dict[str, Any]) -> AirConditionerS
249
261
  refresh_time=raw_status.get("refreshTime"),
250
262
  power_on=power_on,
251
263
  hvac_mode=hvac_mode,
264
+ hvac_action=hvac_action,
252
265
  current_temperature=current_temperature,
253
266
  target_temperature=target_temperature,
254
267
  outdoor_temperature=outdoor_temperature,
@@ -98,6 +98,7 @@ class AirConditionerStatus(SuningBaseModel):
98
98
  refresh_time: str | None = None
99
99
  power_on: bool | None = None
100
100
  hvac_mode: HvacMode | None = None
101
+ hvac_action: HvacAction | None = None
101
102
  current_temperature: float | None = None
102
103
  target_temperature: float | None = None
103
104
  outdoor_temperature: float | None = None
@@ -146,6 +147,19 @@ class HvacMode(str, Enum):
146
147
  QUICK = "quick"
147
148
 
148
149
 
150
+ class HvacAction(str, Enum):
151
+ """What the AC is actively doing right now — mirrors HA's HVACAction enum."""
152
+
153
+ OFF = "off"
154
+ PREHEATING = "preheating"
155
+ HEATING = "heating"
156
+ COOLING = "cooling"
157
+ DRYING = "drying"
158
+ FAN = "fan"
159
+ IDLE = "idle"
160
+ DEFROSTING = "defrosting"
161
+
162
+
149
163
  class FanSpeed(str, Enum):
150
164
  AUTO = "auto"
151
165
  SILENT = "silent"
@@ -180,3 +194,43 @@ class Timer(SuningBaseModel):
180
194
  schedule: str
181
195
  enabled: bool
182
196
  command: dict[str, str] = Field(default_factory=dict)
197
+
198
+
199
+ class CapabilityField(SuningBaseModel):
200
+ """One field advertised by the device's panel template (e.g. ``C_FANSPEED``)."""
201
+
202
+ key: str
203
+ name: str
204
+ type: str
205
+ raw_values: list[str] = Field(default_factory=list)
206
+ display_values: list[str] = Field(default_factory=list)
207
+ sn_property_id: str | None = None
208
+ icon_urls: list[str] = Field(default_factory=list)
209
+ raw: dict[str, Any] = Field(default_factory=dict)
210
+
211
+
212
+ class DeviceCapabilities(SuningBaseModel):
213
+ """Capabilities advertised by the device's panel template.
214
+
215
+ Drives the HA climate entity's ``hvac_modes`` / ``fan_modes`` /
216
+ ``swing_modes`` / ``preset_modes`` lists so the integration can
217
+ advertise only what the device actually supports.
218
+ """
219
+
220
+ device_id: str
221
+ model_id: str
222
+ category_id: str
223
+ fields: dict[str, CapabilityField] = Field(default_factory=dict)
224
+ hvac_modes: list[str] = Field(default_factory=list)
225
+ fan_modes: list[str] = Field(default_factory=list)
226
+ swing_modes: list[str] = Field(default_factory=list)
227
+ preset_modes: list[str] = Field(default_factory=list)
228
+ supports_vertical_swing: bool = False
229
+ supports_horizontal_swing: bool = False
230
+ supports_eco: bool = False
231
+ supports_fresh_air: bool = False
232
+ supports_aux_heat: bool = False
233
+ supports_target_temperature: bool = True
234
+ min_target_temperature: float = 16.0
235
+ max_target_temperature: float = 32.0
236
+ raw: dict[str, Any] = Field(default_factory=dict)
@@ -282,8 +282,9 @@ def test_get_device_panel_template_hits_url_and_parses() -> None:
282
282
  assert template is not None
283
283
  assert template.device_id == "000165f9b029afa2e5d8"
284
284
  assert template.model_id == "0001000200150000"
285
- assert "C_POWER" in template.components
286
- assert "C_MODE" in template.components
285
+ assert "C_POWER" in template.fields
286
+ assert "C_MODE" in template.fields
287
+ assert "cool" in template.hvac_modes
287
288
  called_url = client.session.get.call_args.args[0]
288
289
  assert called_url.startswith(PANEL_QUERY_URL)
289
290
  assert "deviceId=000165f9b029afa2e5d8" in called_url
@@ -566,3 +567,193 @@ def test_set_aux_heat_sends_field_directly() -> None:
566
567
  assert set_aux_heat is not None
567
568
  assert _capture_cmd(set_aux_heat, on=True) == {"C_ELECHEATING": "1"}
568
569
  assert _capture_cmd(set_aux_heat, on=False) == {"C_ELECHEATING": "0"}
570
+
571
+
572
+ # ---------------------------------------------------------------------------
573
+ # infer_hvac_action
574
+ # ---------------------------------------------------------------------------
575
+
576
+
577
+ def test_infer_hvac_action_off_when_power_off() -> None:
578
+ from xiaobiu.ac_control import infer_hvac_action
579
+
580
+ assert (
581
+ infer_hvac_action(
582
+ power_on=False, hvac_mode=HvacMode.HEAT, current_temp=10.0, target_temp=20.0,
583
+ )
584
+ == "off"
585
+ )
586
+
587
+
588
+ def test_infer_hvac_action_none_when_power_unknown() -> None:
589
+ from xiaobiu.ac_control import infer_hvac_action
590
+
591
+ assert (
592
+ infer_hvac_action(
593
+ power_on=None, hvac_mode=HvacMode.HEAT, current_temp=10.0, target_temp=20.0,
594
+ )
595
+ is None
596
+ )
597
+
598
+
599
+ def test_infer_hvac_action_heating_when_below_target() -> None:
600
+ from xiaobiu.ac_control import infer_hvac_action
601
+
602
+ assert (
603
+ infer_hvac_action(
604
+ power_on=True, hvac_mode=HvacMode.HEAT,
605
+ current_temp=18.0, target_temp=22.0,
606
+ )
607
+ == "heating"
608
+ )
609
+
610
+
611
+ def test_infer_hvac_action_cooling_when_above_target() -> None:
612
+ from xiaobiu.ac_control import infer_hvac_action
613
+
614
+ assert (
615
+ infer_hvac_action(
616
+ power_on=True, hvac_mode=HvacMode.COOL,
617
+ current_temp=28.0, target_temp=24.0,
618
+ )
619
+ == "cooling"
620
+ )
621
+
622
+
623
+ def test_infer_hvac_action_idle_when_at_target() -> None:
624
+ from xiaobiu.ac_control import infer_hvac_action
625
+
626
+ assert (
627
+ infer_hvac_action(
628
+ power_on=True, hvac_mode=HvacMode.HEAT,
629
+ current_temp=22.0, target_temp=22.0,
630
+ )
631
+ == "idle"
632
+ )
633
+
634
+
635
+ def test_infer_hvac_action_dry_and_fan() -> None:
636
+ from xiaobiu.ac_control import infer_hvac_action
637
+
638
+ assert (
639
+ infer_hvac_action(
640
+ power_on=True, hvac_mode=HvacMode.DRY, current_temp=24.0, target_temp=24.0,
641
+ )
642
+ == "drying"
643
+ )
644
+ assert (
645
+ infer_hvac_action(
646
+ power_on=True, hvac_mode=HvacMode.FAN_ONLY, current_temp=24.0, target_temp=24.0,
647
+ )
648
+ == "fan"
649
+ )
650
+
651
+
652
+ def test_infer_hvac_action_auto_picks_heating_or_cooling() -> None:
653
+ from xiaobiu.ac_control import infer_hvac_action
654
+
655
+ assert (
656
+ infer_hvac_action(
657
+ power_on=True, hvac_mode=HvacMode.AUTO,
658
+ current_temp=18.0, target_temp=22.0,
659
+ )
660
+ == "heating"
661
+ )
662
+ assert (
663
+ infer_hvac_action(
664
+ power_on=True, hvac_mode=HvacMode.AUTO,
665
+ current_temp=28.0, target_temp=22.0,
666
+ )
667
+ == "cooling"
668
+ )
669
+ assert (
670
+ infer_hvac_action(
671
+ power_on=True, hvac_mode=HvacMode.AUTO,
672
+ current_temp=22.0, target_temp=22.0,
673
+ )
674
+ == "idle"
675
+ )
676
+
677
+
678
+ def test_infer_hvac_action_quick_treated_like_heat() -> None:
679
+ from xiaobiu.ac_control import infer_hvac_action
680
+
681
+ assert (
682
+ infer_hvac_action(
683
+ power_on=True, hvac_mode=HvacMode.QUICK,
684
+ current_temp=18.0, target_temp=22.0,
685
+ )
686
+ == "heating"
687
+ )
688
+
689
+
690
+ def test_infer_hvac_action_idle_when_temps_missing() -> None:
691
+ from xiaobiu.ac_control import infer_hvac_action
692
+
693
+ assert (
694
+ infer_hvac_action(
695
+ power_on=True, hvac_mode=HvacMode.HEAT, current_temp=None, target_temp=22.0,
696
+ )
697
+ == "idle"
698
+ )
699
+
700
+
701
+ # ---------------------------------------------------------------------------
702
+ # build_capabilities_from_template
703
+ # ---------------------------------------------------------------------------
704
+
705
+
706
+ def test_build_capabilities_emits_modes_for_supported_fields() -> None:
707
+ from xiaobiu.ac_control import build_capabilities_from_template
708
+
709
+ caps = build_capabilities_from_template(
710
+ device_id="d",
711
+ model_id="m",
712
+ category_id="0002",
713
+ fields=["C_MODE", "C_FANSPEED", "C_AIRVERTICAL", "C_AIRHORIZONTAL", "C_ECO"],
714
+ )
715
+ assert "cool" in caps.hvac_modes
716
+ assert "heat" in caps.hvac_modes
717
+ assert "auto" in caps.fan_modes
718
+ assert "turbo" in caps.fan_modes
719
+ assert "off" in caps.swing_modes
720
+ assert "both" in caps.swing_modes
721
+ assert "eco" in caps.preset_modes
722
+ assert caps.supports_vertical_swing is True
723
+ assert caps.supports_horizontal_swing is True
724
+ assert caps.supports_eco is True
725
+ assert caps.supports_fresh_air is False
726
+
727
+
728
+ def test_build_capabilities_marks_no_fields_when_template_empty() -> None:
729
+ from xiaobiu.ac_control import build_capabilities_from_template
730
+
731
+ caps = build_capabilities_from_template(
732
+ device_id="d", model_id="m", category_id="0002", fields=[],
733
+ )
734
+ assert caps.hvac_modes == []
735
+ assert caps.fan_modes == []
736
+ assert caps.swing_modes == []
737
+ assert caps.preset_modes == ["none"]
738
+ assert caps.supports_vertical_swing is False
739
+
740
+
741
+ def test_build_capabilities_includes_aux_heat_when_field_present() -> None:
742
+ from xiaobiu.ac_control import build_capabilities_from_template
743
+
744
+ caps = build_capabilities_from_template(
745
+ device_id="d", model_id="m", category_id="0002",
746
+ fields=["C_MODE", "C_ELECHEATING"],
747
+ )
748
+ assert "aux_heat" in caps.preset_modes
749
+ assert caps.supports_aux_heat is True
750
+
751
+
752
+ def test_build_capabilities_quick_appears_in_hvac_modes() -> None:
753
+ from xiaobiu.ac_control import build_capabilities_from_template
754
+
755
+ caps = build_capabilities_from_template(
756
+ device_id="d", model_id="m", category_id="0002", fields=["C_MODE"],
757
+ )
758
+ assert "quick" in caps.hvac_modes
759
+
@@ -294,7 +294,7 @@ wheels = [
294
294
 
295
295
  [[package]]
296
296
  name = "python-xiaobiu"
297
- version = "0.2.0"
297
+ version = "0.2.1"
298
298
  source = { editable = "." }
299
299
  dependencies = [
300
300
  { name = "cryptography" },