python-xiaobiu 0.2.1__py3-none-any.whl → 0.2.3__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.
- {python_xiaobiu-0.2.1.dist-info → python_xiaobiu-0.2.3.dist-info}/METADATA +48 -25
- {python_xiaobiu-0.2.1.dist-info → python_xiaobiu-0.2.3.dist-info}/RECORD +8 -8
- {python_xiaobiu-0.2.1.dist-info → python_xiaobiu-0.2.3.dist-info}/WHEEL +1 -1
- xiaobiu/ac_control.py +208 -34
- xiaobiu/ac_status.py +23 -6
- xiaobiu/cli.py +37 -0
- xiaobiu/client.py +39 -3
- {python_xiaobiu-0.2.1.dist-info → python_xiaobiu-0.2.3.dist-info}/entry_points.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
2
|
Name: python-xiaobiu
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.3
|
|
4
4
|
Summary: Suning biu smart home SMS login and session client
|
|
5
5
|
Project-URL: Homepage, https://github.com/FaintGhost/python-xiaobiu
|
|
6
6
|
Project-URL: Bug Tracker, https://github.com/FaintGhost/python-xiaobiu/issues
|
|
@@ -12,9 +12,11 @@ Classifier: License :: OSI Approved :: MIT License
|
|
|
12
12
|
Classifier: Operating System :: OS Independent
|
|
13
13
|
Classifier: Programming Language :: Python :: 3
|
|
14
14
|
Requires-Python: >=3.14
|
|
15
|
-
Requires-Dist: cryptography>=
|
|
15
|
+
Requires-Dist: cryptography>=48.0.1
|
|
16
|
+
Requires-Dist: idna>=3.15
|
|
16
17
|
Requires-Dist: pydantic>=2.0.0
|
|
17
|
-
Requires-Dist: requests>=2.
|
|
18
|
+
Requires-Dist: requests>=2.33.0
|
|
19
|
+
Requires-Dist: urllib3>=2.7.0
|
|
18
20
|
Description-Content-Type: text/markdown
|
|
19
21
|
|
|
20
22
|
# python-xiaobiu
|
|
@@ -71,12 +73,12 @@ client.turn_on(family_id=37790, device_id="000165f9b029afa2e5d8")
|
|
|
71
73
|
client.turn_off(family_id=37790, device_id="000165f9b029afa2e5d8")
|
|
72
74
|
|
|
73
75
|
# Mode
|
|
74
|
-
client.set_hvac_mode(family_id=37790, device_id="...", mode=HvacMode.
|
|
75
|
-
client.set_hvac_mode(family_id=37790, device_id="...", mode=HvacMode.
|
|
76
|
-
client.set_hvac_mode(family_id=37790, device_id="...", mode=HvacMode.
|
|
77
|
-
client.set_hvac_mode(family_id=37790, device_id="...", mode=HvacMode.
|
|
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) #
|
|
76
|
+
client.set_hvac_mode(family_id=37790, device_id="...", mode=HvacMode.HEAT) # 制热 (C_MODE=1)
|
|
77
|
+
client.set_hvac_mode(family_id=37790, device_id="...", mode=HvacMode.COOL) # 制冷 (C_MODE=2)
|
|
78
|
+
client.set_hvac_mode(family_id=37790, device_id="...", mode=HvacMode.DRY) # 除湿 (C_MODE=3)
|
|
79
|
+
client.set_hvac_mode(family_id=37790, device_id="...", mode=HvacMode.FAN_ONLY) # 送风 (C_MODE=4)
|
|
80
|
+
client.set_hvac_mode(family_id=37790, device_id="...", mode=HvacMode.AUTO) # 一键通/自动 (C_MODE=6)
|
|
81
|
+
client.set_hvac_mode(family_id=37790, device_id="...", mode=HvacMode.QUICK) # 一键通/自动 (C_MODE=6, 与 AUTO 同)
|
|
80
82
|
|
|
81
83
|
# Temperature
|
|
82
84
|
client.set_temperature(family_id=37790, device_id="...", value=24.0) # 16.0–32.0
|
|
@@ -110,17 +112,31 @@ client.list_device_timers(family_id=37790, device_id="...")
|
|
|
110
112
|
client.get_device_panel_template(family_id=37790, device_id="...")
|
|
111
113
|
```
|
|
112
114
|
|
|
115
|
+
### Timers
|
|
116
|
+
|
|
117
|
+
```python
|
|
118
|
+
timers = client.list_device_timers(family_id=37790, device_id="...")
|
|
119
|
+
client.set_device_timer(
|
|
120
|
+
family_id=37790, device_id="...",
|
|
121
|
+
hour=23, minute=0, power_on=False, name="关闭时间",
|
|
122
|
+
)
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
`timer` uses the app's `T,<hour>,<minute>,<weekmask>` format. The leading
|
|
126
|
+
`T` / `F` is the enabled flag — pass `enabled=False` to disable an
|
|
127
|
+
existing schedule, because the cloud has **no delete call** (`clearTimer`
|
|
128
|
+
returns 404 and `setTimer` rejects an empty command).
|
|
129
|
+
|
|
113
130
|
### HA climate entity mapping
|
|
114
131
|
|
|
115
132
|
| Suning App | `xiaobiu` API | `C_*` field | HA climate field |
|
|
116
133
|
|------------|---------------|------------|------------------|
|
|
117
134
|
| 电源开关 | `turn_on/off` | `C_POWER` | `hvac_mode = off` when off |
|
|
118
|
-
|
|
|
119
|
-
|
|
|
120
|
-
|
|
|
121
|
-
|
|
|
122
|
-
|
|
|
123
|
-
| 一键通 | `set_hvac_mode(QUICK)` | `C_MODE=5` | `hvac_mode = auto` (map) |
|
|
135
|
+
| 制热 | `set_hvac_mode(HEAT)` | `C_MODE=1` | `hvac_mode = heat` |
|
|
136
|
+
| 制冷 | `set_hvac_mode(COOL)` | `C_MODE=2` | `hvac_mode = cool` |
|
|
137
|
+
| 除湿 | `set_hvac_mode(DRY)` | `C_MODE=3` | `hvac_mode = dry` |
|
|
138
|
+
| 送风 | `set_hvac_mode(FAN_ONLY)` | `C_MODE=4` (或 `5`) | `hvac_mode = fan_only` |
|
|
139
|
+
| 一键通/自动 | `set_hvac_mode(AUTO)` / `set_hvac_mode(QUICK)` | `C_MODE=6` | `hvac_mode = auto` |
|
|
124
140
|
| 微风/低/中/高/强风 | `set_fan_mode(SILENT/LOW/MEDIUM/HIGH/TURBO)` | `C_FANSPEED=1..5` | `fan_mode` |
|
|
125
141
|
| 上下摆风 | `set_vertical_swing(on=)` | `C_AIRVERTICAL` | `swing_mode` (HA 把 `swing_mode` 默认指垂直) |
|
|
126
142
|
| 左右摆风 | `set_horizontal_swing(on=)` | `C_AIRHORIZONTAL` | `swing_horizontal_mode` |
|
|
@@ -128,6 +144,11 @@ client.get_device_panel_template(family_id=37790, device_id="...")
|
|
|
128
144
|
| 空气清新 | `set_fresh_air(on=)` | `C_FRESHAIR` | `preset_mode = fresh_air` |
|
|
129
145
|
| 电辅热 | `set_aux_heat(on=)` | `C_ELECHEATING` | `preset_mode = aux_heat` |
|
|
130
146
|
|
|
147
|
+
> **读/写编码不同**:上表是**写侧**(`C_MODE` 控制值)。设备**上报状态**用的是另一套 `SN_MODE` 值:
|
|
148
|
+
> `SN_MODE=1`(一键通/自动)、`2`(制冷)、`3`(制热)、`4`(送风)、`5`(除湿)。
|
|
149
|
+
> `infer_hvac_mode` 读状态时默认按 `SN_MODE` 解码;下发命令时 `set_hvac_mode` 用 `C_MODE`。
|
|
150
|
+
> 两套编码不一致(如 `C_MODE=1` 是制热,但 `SN_MODE=1` 是一键通),库内部已拆成两张表分别处理。
|
|
151
|
+
|
|
131
152
|
### `swing_mode` 集成注意事项
|
|
132
153
|
|
|
133
154
|
按 Home Assistant climate entity 惯例:
|
|
@@ -209,19 +230,21 @@ xiaobiucli set-fresh-air --family-id 37790 --device-id <id> --on|--off
|
|
|
209
230
|
xiaobiucli set-aux-heat --family-id 37790 --device-id <id> --on|--off
|
|
210
231
|
xiaobiucli timers --family-id 37790 --device-id <id>
|
|
211
232
|
xiaobiucli panel --family-id 37790 --device-id <id>
|
|
233
|
+
xiaobiucli raw-oper --family-id 37790 --device-id <id> --cmd C_MODE=1 [--cmd KEY=VALUE ...]
|
|
212
234
|
```
|
|
213
235
|
|
|
214
236
|
## Notes
|
|
215
237
|
|
|
216
|
-
- **`C_MODE
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
- **`SN_CLOUD_TIMER` writes** are not implemented
|
|
238
|
+
- **`C_MODE` / `SN_MODE` 编码不同**(2026-06-17 真机实测确认):
|
|
239
|
+
- 写侧 `C_MODE`:`1`=制热、`2`=制冷、`3`=除湿、`4`=送风、`5`=送风(同 4)、`6`=一键通(≈自动)
|
|
240
|
+
- 读侧 `SN_MODE`:`1`=一键通(自动)、`2`=制冷、`3`=制热、`4`=送风、`5`=除湿
|
|
241
|
+
- 库内部用 `C_FIELD_TO_HVAC`(写)和 `SN_FIELD_TO_HVAC`(读)两张表分别处理。
|
|
242
|
+
- **一键通 ≈ 自动**:这台设备没有独立的 AUTO 模式,`C_MODE=6`(一键通)在语义上最接近,
|
|
243
|
+
暴露为 `HvacMode.AUTO`;`HvacMode.QUICK` 也指向 `C_MODE=6`。
|
|
244
|
+
- **`C_ELECHEATING` (电辅热)** 值域已实测确认为 `0/1`。`set_aux_heat(on=True)` 在客户端
|
|
245
|
+
强制 App 的"仅制热时生效"规则(当前模式非 HEAT 时 raise `SuningError`)。
|
|
246
|
+
- **`SN_CLOUD_TIMER` writes** are not implemented; cloud timers go through
|
|
247
|
+
`set_device_timer` instead, and cannot be deleted (only disabled).
|
|
225
248
|
- **Unknown `C_MODE` values** (e.g. `7`, which neither the App nor the
|
|
226
249
|
capture expose) collapse to `hvac_mode = None` so Home Assistant can
|
|
227
250
|
render `unavailable` rather than guessing.
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
xiaobiu/__init__.py,sha256=vuubbRNBH7hN-QW8_-aYQcOjj10OQp26w_7imNU9KO8,837
|
|
2
|
-
xiaobiu/ac_control.py,sha256=
|
|
3
|
-
xiaobiu/ac_status.py,sha256=
|
|
2
|
+
xiaobiu/ac_control.py,sha256=JK9anHEPbvSr50nq2oqfTZbxZTlwwWRSPpcCCSm9nP0,25940
|
|
3
|
+
xiaobiu/ac_status.py,sha256=62ecNZyeUm9SUz0NhVCVj4mcTB3KB78lLQgNNf1P4yY,14915
|
|
4
4
|
xiaobiu/app_api.py,sha256=gJLa-iq60s_YEEM00E4lMcTsBKoV60GtaaqBsWWOWio,4729
|
|
5
5
|
xiaobiu/captcha_bridge.py,sha256=l8c3HnspQt1JDM1sDKnvcM4yvf7NZosSQ7x2AlO-kEA,12920
|
|
6
|
-
xiaobiu/cli.py,sha256=
|
|
7
|
-
xiaobiu/client.py,sha256=
|
|
6
|
+
xiaobiu/cli.py,sha256=rKbvt7rsV_OcNr5N62JIRhveKzyDwtu2MApSdeDj_fA,18810
|
|
7
|
+
xiaobiu/client.py,sha256=o-1ks6mlH5wUMksGYBDJpoPdSRVngggp7pNmCxJv-UY,23969
|
|
8
8
|
xiaobiu/crypto.py,sha256=C0Lcp2Cfy-075hv65b1RYfn6UbiHneLhp4PhUftzzOk,2424
|
|
9
9
|
xiaobiu/exceptions.py,sha256=RKaity_UctboUGeC8QE0iF0KcqfYqlVHnfOQ2yXQT7c,1036
|
|
10
10
|
xiaobiu/har_templates.py,sha256=clatrCsn4_AxlSrpy99mJVThI34bFQpQQMoM-4H9e08,5562
|
|
@@ -12,7 +12,7 @@ xiaobiu/models.py,sha256=h6lhH0GQIgH9zUwmQLBBAY-SJBZjYr5LMxXqiRVrDOI,6223
|
|
|
12
12
|
xiaobiu/parsers.py,sha256=5Cb90sN5rw_SNv2BukOoiLmeG9Mxegq-XGkgE8YkxvU,3046
|
|
13
13
|
xiaobiu/persistence.py,sha256=k9ZES5DyE-OkptlLLw0jnBWwGtdDxgrn0YiVhAQ1V8c,887
|
|
14
14
|
xiaobiu/sms_login.py,sha256=5zQS_lhFvADdp6BnoenvSLdOSK1hWaT35rQQ4K3Ig-w,16394
|
|
15
|
-
python_xiaobiu-0.2.
|
|
16
|
-
python_xiaobiu-0.2.
|
|
17
|
-
python_xiaobiu-0.2.
|
|
18
|
-
python_xiaobiu-0.2.
|
|
15
|
+
python_xiaobiu-0.2.3.dist-info/METADATA,sha256=pMTeNbfjzG2Ccmqmeg-tAljPON24Xx87gNK9c3Z1yyo,13198
|
|
16
|
+
python_xiaobiu-0.2.3.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
17
|
+
python_xiaobiu-0.2.3.dist-info/entry_points.txt,sha256=w1z8h63RRusoSGAbbSMpNcq4qbN3HOedsMlxwuFH3U8,44
|
|
18
|
+
python_xiaobiu-0.2.3.dist-info/RECORD,,
|
xiaobiu/ac_control.py
CHANGED
|
@@ -15,6 +15,7 @@ true for :class:`xiaobiu.SuningSmartHomeClient`.
|
|
|
15
15
|
from __future__ import annotations
|
|
16
16
|
|
|
17
17
|
import json
|
|
18
|
+
from urllib.parse import quote
|
|
18
19
|
from typing import TYPE_CHECKING, Any, Mapping, Sequence
|
|
19
20
|
|
|
20
21
|
from .exceptions import SuningError
|
|
@@ -36,20 +37,51 @@ if TYPE_CHECKING: # pragma: no cover - only for type hints
|
|
|
36
37
|
|
|
37
38
|
APP_OPER_URL = "https://itapig.suning.com/api/trade/shsys/appOper"
|
|
38
39
|
QUERY_TIMER_URL = "https://itapig.suning.com/api/trade/shsys/queryTimer"
|
|
40
|
+
SET_TIMER_URL = "https://itapig.suning.com/api/trade/shsys/setTimer"
|
|
39
41
|
PANEL_QUERY_URL = "https://shcss.suning.com/shcss-web/api/panel/queryTemplate.do"
|
|
40
42
|
|
|
41
43
|
TEMP_MIN_C = 16.0
|
|
42
44
|
TEMP_MAX_C = 32.0
|
|
43
45
|
|
|
46
|
+
# ---------------------------------------------------------------------------
|
|
47
|
+
# Mode mapping tables
|
|
48
|
+
# ---------------------------------------------------------------------------
|
|
49
|
+
#
|
|
50
|
+
# Suning encodes the HVAC mode with *two different* value sets:
|
|
51
|
+
#
|
|
52
|
+
# * ``C_MODE`` (control) — the value you send in an ``appOper`` command.
|
|
53
|
+
# * ``SN_MODE`` (status) — the value the device reports back in its status.
|
|
54
|
+
#
|
|
55
|
+
# They are NOT the same encoding, so reads and writes need separate tables.
|
|
56
|
+
# Values below were confirmed by live-device testing (2026-06-17) plus the
|
|
57
|
+
# ``queryTemplate.do`` panel definition:
|
|
58
|
+
#
|
|
59
|
+
# C_MODE (write): 1=制热 2=制冷 3=除湿 4=送风 5=送风 6=一键通(=自动)
|
|
60
|
+
# SN_MODE (read): 1=一键通 2=制冷 3=制热 4=送风 5=除湿
|
|
61
|
+
#
|
|
62
|
+
# Note: this device has no dedicated AUTO mode; ``C_MODE=6`` (一键通) is the
|
|
63
|
+
# closest semantic match and is exposed as ``HvacMode.AUTO``. ``C_MODE=5``
|
|
64
|
+
# behaves the same as ``4`` (送风) on the tested device.
|
|
65
|
+
|
|
66
|
+
# Write side: C_MODE control value → HvacMode
|
|
44
67
|
C_FIELD_TO_HVAC: dict[str, HvacMode] = {
|
|
45
|
-
"1": HvacMode.
|
|
46
|
-
"2": HvacMode.
|
|
47
|
-
"3": HvacMode.
|
|
48
|
-
"4": HvacMode.
|
|
49
|
-
"5": HvacMode.
|
|
68
|
+
"1": HvacMode.HEAT,
|
|
69
|
+
"2": HvacMode.COOL,
|
|
70
|
+
"3": HvacMode.DRY,
|
|
71
|
+
"4": HvacMode.FAN_ONLY,
|
|
72
|
+
"5": HvacMode.FAN_ONLY,
|
|
50
73
|
"6": HvacMode.AUTO,
|
|
51
74
|
}
|
|
52
75
|
|
|
76
|
+
# Read side: SN_MODE status value → HvacMode
|
|
77
|
+
SN_FIELD_TO_HVAC: dict[str, HvacMode] = {
|
|
78
|
+
"1": HvacMode.AUTO,
|
|
79
|
+
"2": HvacMode.COOL,
|
|
80
|
+
"3": HvacMode.HEAT,
|
|
81
|
+
"4": HvacMode.FAN_ONLY,
|
|
82
|
+
"5": HvacMode.DRY,
|
|
83
|
+
}
|
|
84
|
+
|
|
53
85
|
C_FIELD_TO_FAN: dict[str, FanSpeed] = {
|
|
54
86
|
"0": FanSpeed.AUTO,
|
|
55
87
|
"1": FanSpeed.SILENT,
|
|
@@ -59,7 +91,16 @@ C_FIELD_TO_FAN: dict[str, FanSpeed] = {
|
|
|
59
91
|
"5": FanSpeed.TURBO,
|
|
60
92
|
}
|
|
61
93
|
|
|
62
|
-
|
|
94
|
+
# HvacMode → preferred C_MODE control value (first write-table hit wins).
|
|
95
|
+
# QUICK shares C_MODE=6 with AUTO on the tested device (一键通 ≈ 自动).
|
|
96
|
+
HVAC_TO_C_FIELD: dict[HvacMode, str] = {
|
|
97
|
+
HvacMode.HEAT: "1",
|
|
98
|
+
HvacMode.COOL: "2",
|
|
99
|
+
HvacMode.DRY: "3",
|
|
100
|
+
HvacMode.FAN_ONLY: "4",
|
|
101
|
+
HvacMode.AUTO: "6",
|
|
102
|
+
HvacMode.QUICK: "6",
|
|
103
|
+
}
|
|
63
104
|
FAN_TO_C_FIELD: dict[FanSpeed, str] = {speed: raw for raw, speed in C_FIELD_TO_FAN.items()}
|
|
64
105
|
|
|
65
106
|
SWING_TO_CMD: dict[SwingMode, dict[str, str]] = {
|
|
@@ -172,6 +213,7 @@ def get_device_panel_template(
|
|
|
172
213
|
model_id: str,
|
|
173
214
|
*,
|
|
174
215
|
category_id: str = "0002",
|
|
216
|
+
template_id: str = "PANEL_AC",
|
|
175
217
|
) -> DeviceCapabilities | None:
|
|
176
218
|
"""Fetch the device's :class:`DeviceCapabilities`.
|
|
177
219
|
|
|
@@ -180,14 +222,24 @@ def get_device_panel_template(
|
|
|
180
222
|
name for backward compatibility — the returned object's
|
|
181
223
|
:class:`DeviceCapabilities` includes a ``raw`` payload carrying the
|
|
182
224
|
unparsed template.
|
|
225
|
+
|
|
226
|
+
The panel endpoint (``queryTemplate.do``) is queried with ``modelId``
|
|
227
|
+
and ``templateId`` (confirmed from a live HAR capture). A ``userid``
|
|
228
|
+
header carrying the logged-in user's ``custno`` cookie value is sent
|
|
229
|
+
so the server returns the full template instead of a login redirect.
|
|
183
230
|
"""
|
|
184
231
|
|
|
185
|
-
query =
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
232
|
+
query = f"{PANEL_QUERY_URL}?modelId={model_id}&templateId={template_id}"
|
|
233
|
+
headers: dict[str, str] = {}
|
|
234
|
+
custno = None
|
|
235
|
+
try:
|
|
236
|
+
custno = client.session.cookies.get("custno")
|
|
237
|
+
except Exception:
|
|
238
|
+
pass
|
|
239
|
+
if custno:
|
|
240
|
+
headers["userid"] = str(custno)
|
|
189
241
|
try:
|
|
190
|
-
response = client.session.get(query, timeout=client.timeout)
|
|
242
|
+
response = client.session.get(query, timeout=client.timeout, headers=headers)
|
|
191
243
|
response.raise_for_status()
|
|
192
244
|
payload = response.json()
|
|
193
245
|
except Exception:
|
|
@@ -261,20 +313,24 @@ def build_capabilities_from_template(
|
|
|
261
313
|
|
|
262
314
|
has = set(fields)
|
|
263
315
|
hvac_modes: list[str] = []
|
|
264
|
-
#
|
|
265
|
-
#
|
|
266
|
-
#
|
|
316
|
+
# Build the hvac_modes list from the C_MODE control values the panel
|
|
317
|
+
# actually advertises (its ``k`` array), mapped through the write table.
|
|
318
|
+
# ``off`` is always offered (power toggle). Unknown C_MODE values that
|
|
319
|
+
# have no HvacMode mapping are simply skipped. When the panel template
|
|
320
|
+
# lacks a ``k`` array for C_MODE (e.g. no ``raw`` was supplied), fall back
|
|
321
|
+
# to the full set of known modes so callers still get a usable list.
|
|
267
322
|
if "C_MODE" in has:
|
|
268
|
-
hvac_modes = [
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
323
|
+
hvac_modes = [HvacMode.OFF.value]
|
|
324
|
+
seen: set[str] = {HvacMode.OFF.value}
|
|
325
|
+
mode_field = field_map.get("C_MODE")
|
|
326
|
+
advertised = mode_field.raw_values if mode_field is not None else []
|
|
327
|
+
if not advertised:
|
|
328
|
+
advertised = list(C_FIELD_TO_HVAC.keys())
|
|
329
|
+
for raw_val in advertised:
|
|
330
|
+
mapped = C_FIELD_TO_HVAC.get(str(raw_val).strip())
|
|
331
|
+
if mapped is not None and mapped.value not in seen:
|
|
332
|
+
hvac_modes.append(mapped.value)
|
|
333
|
+
seen.add(mapped.value)
|
|
278
334
|
fan_modes: list[str] = []
|
|
279
335
|
if "C_FANSPEED" in has:
|
|
280
336
|
fan_modes = [
|
|
@@ -320,12 +376,26 @@ def build_capabilities_from_template(
|
|
|
320
376
|
)
|
|
321
377
|
|
|
322
378
|
|
|
379
|
+
def _timer_enabled(schedule: Any, state: Any) -> bool:
|
|
380
|
+
"""A timer is enabled when its schedule starts with ``T``.
|
|
381
|
+
|
|
382
|
+
The cloud sends both a ``T``/``F`` prefix and a ``state`` string. The
|
|
383
|
+
prefix is what the app writes back (``replaceFirst("T", "F")``), so it
|
|
384
|
+
is authoritative; ``state`` is only a fallback.
|
|
385
|
+
"""
|
|
386
|
+
|
|
387
|
+
text = str(schedule or "")
|
|
388
|
+
if text[:1] in ("T", "F"):
|
|
389
|
+
return text[0] == "T"
|
|
390
|
+
return str(state or "") == "1"
|
|
391
|
+
|
|
392
|
+
|
|
323
393
|
def list_device_timers(client: Any, device_id: str) -> list[Timer]:
|
|
324
394
|
"""Fetch the cloud timer list for ``device_id``.
|
|
325
395
|
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
396
|
+
The cloud mirrors the enabled flag both in ``state`` (``"1"`` enabled,
|
|
397
|
+
``"0"`` disabled) and in the first character of ``timer`` (``T`` / ``F``).
|
|
398
|
+
There is no delete endpoint: the app toggles ``T`` / ``F`` only.
|
|
329
399
|
"""
|
|
330
400
|
|
|
331
401
|
body = json.dumps(
|
|
@@ -354,20 +424,116 @@ def list_device_timers(client: Any, device_id: str) -> list[Timer]:
|
|
|
354
424
|
Timer(
|
|
355
425
|
name=str(item.get("timerName") or ""),
|
|
356
426
|
schedule=str(item.get("timer") or ""),
|
|
357
|
-
enabled=
|
|
427
|
+
enabled=_timer_enabled(item.get("timer"), item.get("state")),
|
|
358
428
|
command={str(k): str(v) for k, v in (item.get("timerCmd") or {}).items()},
|
|
359
429
|
)
|
|
360
430
|
)
|
|
361
431
|
return timers
|
|
362
432
|
|
|
363
433
|
|
|
364
|
-
def
|
|
434
|
+
def encode_timer_weekdays(weekdays: Sequence[bool]) -> int:
|
|
435
|
+
"""Pack the seven day checkboxes the way the app does.
|
|
436
|
+
|
|
437
|
+
The app builds an eight bit binary string out of the selection: a
|
|
438
|
+
leading ``1`` sentinel, the first day bit, then the remaining six day
|
|
439
|
+
bits in reverse order. An empty selection stays at ``0`` so only the
|
|
440
|
+
time matters. Mirrors ``TimingStepTwoActivity.getTimer``.
|
|
441
|
+
"""
|
|
442
|
+
|
|
443
|
+
if len(weekdays) != 7:
|
|
444
|
+
raise ValueError("weekdays 必须是 7 个布尔值(周一到周日)")
|
|
445
|
+
bits = "".join("1" if day else "0" for day in weekdays)
|
|
446
|
+
if bits == "0000000":
|
|
447
|
+
return 0
|
|
448
|
+
return int("1" + bits[0] + bits[:0:-1], 2)
|
|
449
|
+
|
|
450
|
+
|
|
451
|
+
def build_timer_schedule(
|
|
452
|
+
*, hour: int, minute: int, weekdays: Sequence[bool] | None = None
|
|
453
|
+
) -> str:
|
|
454
|
+
"""Build the ``T,<hour>,<minute>,<mask>`` schedule string."""
|
|
455
|
+
|
|
456
|
+
if not 0 <= hour <= 23:
|
|
457
|
+
raise ValueError("hour 必须在 0..23 之间")
|
|
458
|
+
if not 0 <= minute <= 59:
|
|
459
|
+
raise ValueError("minute 必须在 0..59 之间")
|
|
460
|
+
days = list(weekdays) if weekdays is not None else [True] * 7
|
|
461
|
+
return f"T,{hour},{minute},{encode_timer_weekdays(days)}"
|
|
462
|
+
|
|
463
|
+
|
|
464
|
+
def set_device_timer(
|
|
465
|
+
client: Any,
|
|
466
|
+
device_id: str,
|
|
467
|
+
*,
|
|
468
|
+
hour: int,
|
|
469
|
+
minute: int,
|
|
470
|
+
weekdays: Sequence[bool] | None = None,
|
|
471
|
+
power_on: bool = True,
|
|
472
|
+
enabled: bool = True,
|
|
473
|
+
name: str | None = None,
|
|
474
|
+
command: Mapping[str, Any] | None = None,
|
|
475
|
+
) -> dict[str, Any]:
|
|
476
|
+
"""Create a cloud timer for ``device_id`` and return the decoded reply.
|
|
477
|
+
|
|
478
|
+
``timer`` mirrors the app's ``<T|F>,hour,minute,weekmask`` format where
|
|
479
|
+
the leading flag is the enabled state (the cloud has no delete call,
|
|
480
|
+
disabling is the only way to retire a timer). ``cmd`` is a JSON string
|
|
481
|
+
of the operation to run (``{"C_POWER": "1"}`` by default) and
|
|
482
|
+
``timerName`` is URL encoded exactly like the app does.
|
|
483
|
+
"""
|
|
484
|
+
|
|
485
|
+
schedule = build_timer_schedule(
|
|
486
|
+
hour=hour, minute=minute, weekdays=weekdays
|
|
487
|
+
)
|
|
488
|
+
schedule = ("T" if enabled else "F") + schedule[1:]
|
|
489
|
+
payload = dict(command) if command else {
|
|
490
|
+
"C_POWER": "1" if power_on else "0"
|
|
491
|
+
}
|
|
492
|
+
timer_name = name or ("开启时间" if power_on else "关闭时间")
|
|
493
|
+
body = json.dumps(
|
|
494
|
+
{
|
|
495
|
+
"deviceId": device_id,
|
|
496
|
+
"timer": schedule,
|
|
497
|
+
"cmd": json.dumps(payload, separators=(",", ":"), ensure_ascii=False),
|
|
498
|
+
"timerName": quote(timer_name, safe=""),
|
|
499
|
+
},
|
|
500
|
+
separators=(",", ":"),
|
|
501
|
+
ensure_ascii=False,
|
|
502
|
+
)
|
|
503
|
+
response = client._request_app_api(SET_TIMER_URL, body=body)
|
|
504
|
+
try:
|
|
505
|
+
data = response.json()
|
|
506
|
+
except ValueError as error:
|
|
507
|
+
raise SuningError(f"setTimer 返回了无法解析的 JSON 响应: {error}") from error
|
|
508
|
+
if str(data.get("responseCode") or "") != "0":
|
|
509
|
+
raise SuningError(data.get("responseMsg") or "setTimer 调用失败")
|
|
510
|
+
return data
|
|
511
|
+
|
|
512
|
+
|
|
513
|
+
def infer_hvac_mode(
|
|
514
|
+
*,
|
|
515
|
+
power_on: bool | None,
|
|
516
|
+
mode_raw: Any,
|
|
517
|
+
field_kind: str = "sn",
|
|
518
|
+
) -> HvacMode | None:
|
|
365
519
|
"""Translate raw status fields into a typed HVAC mode.
|
|
366
520
|
|
|
367
521
|
``power_on is False`` always wins and yields ``HvacMode.OFF``; only an
|
|
368
522
|
explicitly powered-on device is mapped to a running mode. Unknown
|
|
369
|
-
mode values
|
|
370
|
-
``
|
|
523
|
+
mode values collapse to ``None`` so the caller can render an
|
|
524
|
+
``unavailable`` preview.
|
|
525
|
+
|
|
526
|
+
``field_kind`` selects the encoding table:
|
|
527
|
+
|
|
528
|
+
* ``"sn"`` (default) — ``mode_raw`` is an ``SN_MODE`` *status* value
|
|
529
|
+
(read from the device status payload); uses :data:`SN_FIELD_TO_HVAC`.
|
|
530
|
+
* ``"c"`` — ``mode_raw`` is a ``C_MODE`` *control* value (the value
|
|
531
|
+
you would send in an ``appOper`` command); uses
|
|
532
|
+
:data:`C_FIELD_TO_HVAC`.
|
|
533
|
+
|
|
534
|
+
The two encodings differ on this device (e.g. ``C_MODE=1`` is 制热 but
|
|
535
|
+
``SN_MODE=1`` is 一键通/自动), so callers reading device status should
|
|
536
|
+
keep the default ``"sn"``.
|
|
371
537
|
"""
|
|
372
538
|
|
|
373
539
|
if power_on is False:
|
|
@@ -376,7 +542,8 @@ def infer_hvac_mode(*, power_on: bool | None, mode_raw: Any) -> HvacMode | None:
|
|
|
376
542
|
return None
|
|
377
543
|
if mode_raw is None:
|
|
378
544
|
return None
|
|
379
|
-
|
|
545
|
+
table = SN_FIELD_TO_HVAC if field_kind != "c" else C_FIELD_TO_HVAC
|
|
546
|
+
return table.get(str(mode_raw).strip())
|
|
380
547
|
|
|
381
548
|
|
|
382
549
|
def infer_fan_speed(speed_raw: Any) -> FanSpeed | None:
|
|
@@ -420,11 +587,13 @@ def infer_hvac_action(
|
|
|
420
587
|
return HvacAction.FAN
|
|
421
588
|
if current_temp is None or target_temp is None:
|
|
422
589
|
return HvacAction.IDLE
|
|
423
|
-
if mode_value
|
|
590
|
+
if mode_value == HvacMode.HEAT.value:
|
|
424
591
|
return HvacAction.HEATING if current_temp < target_temp else HvacAction.IDLE
|
|
425
592
|
if mode_value == HvacMode.COOL.value:
|
|
426
593
|
return HvacAction.COOLING if current_temp > target_temp else HvacAction.IDLE
|
|
427
|
-
|
|
594
|
+
# AUTO and QUICK (一键通) both behave like HEAT_COOL: pick the side
|
|
595
|
+
# that has work to do.
|
|
596
|
+
if mode_value in (HvacMode.AUTO.value, HvacMode.QUICK.value, HvacMode.HEAT_COOL.value):
|
|
428
597
|
if current_temp < target_temp:
|
|
429
598
|
return HvacAction.HEATING
|
|
430
599
|
if current_temp > target_temp:
|
|
@@ -632,6 +801,11 @@ __all__ = [
|
|
|
632
801
|
"PRESET_ON_CMD",
|
|
633
802
|
"PanelTemplate",
|
|
634
803
|
"QUERY_TIMER_URL",
|
|
804
|
+
"SET_TIMER_URL",
|
|
805
|
+
"build_timer_schedule",
|
|
806
|
+
"encode_timer_weekdays",
|
|
807
|
+
"set_device_timer",
|
|
808
|
+
"SN_FIELD_TO_HVAC",
|
|
635
809
|
"SWING_TO_CMD",
|
|
636
810
|
"TEMP_MAX_C",
|
|
637
811
|
"TEMP_MIN_C",
|
xiaobiu/ac_status.py
CHANGED
|
@@ -228,13 +228,23 @@ def _normalize_air_conditioner_status(device: dict[str, Any]) -> AirConditionerS
|
|
|
228
228
|
_coalesce(raw_status.get("SN_AIRVERTICAL"), raw_status.get("C_AIRVERTICAL"))
|
|
229
229
|
)
|
|
230
230
|
eco_enabled = _parse_bool_flag(_coalesce(raw_status.get("SN_ECO"), raw_status.get("C_ECO")))
|
|
231
|
-
purify_enabled = _parse_bool_flag(
|
|
232
|
-
|
|
231
|
+
purify_enabled = _parse_bool_flag(
|
|
232
|
+
_coalesce(raw_status.get("SN_PURIFY"), raw_status.get("C_FRESHAIR"))
|
|
233
|
+
)
|
|
234
|
+
fresh_air_enabled = _parse_bool_flag(
|
|
235
|
+
_coalesce(raw_status.get("C_FRESHAIR"), raw_status.get("SN_PURIFY"))
|
|
236
|
+
)
|
|
233
237
|
electric_heating_enabled = _parse_bool_flag(
|
|
234
238
|
_coalesce(raw_status.get("SN_ELECHEATING"), raw_status.get("C_ELECHEATING"))
|
|
235
239
|
)
|
|
236
|
-
|
|
237
|
-
|
|
240
|
+
sn_mode_raw = _coalesce(raw_status.get("SN_MODE"))
|
|
241
|
+
mode_raw = _coalesce(sn_mode_raw, raw_status.get("C_MODE"))
|
|
242
|
+
mode_field_kind = "sn" if sn_mode_raw is not None else "c"
|
|
243
|
+
hvac_mode = (
|
|
244
|
+
infer_hvac_mode(power_on=power_on, mode_raw=mode_raw, field_kind=mode_field_kind)
|
|
245
|
+
if online
|
|
246
|
+
else None
|
|
247
|
+
)
|
|
238
248
|
hvac_action = (
|
|
239
249
|
ac_control.infer_hvac_action(
|
|
240
250
|
power_on=power_on,
|
|
@@ -282,12 +292,19 @@ def _normalize_air_conditioner_status(device: dict[str, Any]) -> AirConditionerS
|
|
|
282
292
|
)
|
|
283
293
|
|
|
284
294
|
|
|
285
|
-
def infer_hvac_mode(
|
|
295
|
+
def infer_hvac_mode(
|
|
296
|
+
*,
|
|
297
|
+
power_on: bool | None,
|
|
298
|
+
mode_raw: Any,
|
|
299
|
+
field_kind: str = "sn",
|
|
300
|
+
) -> HvacMode | None:
|
|
286
301
|
"""Translate raw status fields into a typed :class:`HvacMode`."""
|
|
287
302
|
|
|
288
303
|
from . import ac_control
|
|
289
304
|
|
|
290
|
-
return ac_control.infer_hvac_mode(
|
|
305
|
+
return ac_control.infer_hvac_mode(
|
|
306
|
+
power_on=power_on, mode_raw=mode_raw, field_kind=field_kind,
|
|
307
|
+
)
|
|
291
308
|
|
|
292
309
|
|
|
293
310
|
def _is_air_conditioner_device(device: dict[str, Any]) -> bool:
|
xiaobiu/cli.py
CHANGED
|
@@ -159,6 +159,21 @@ def _build_parser() -> argparse.ArgumentParser:
|
|
|
159
159
|
add_shared_arguments(panel_cmd)
|
|
160
160
|
panel_cmd.add_argument("--family-id", required=True)
|
|
161
161
|
panel_cmd.add_argument("--device-id", required=True)
|
|
162
|
+
|
|
163
|
+
raw_oper = subparsers.add_parser(
|
|
164
|
+
"raw-oper",
|
|
165
|
+
help="直接下发任意 C_*/SN_* 字段到 appOper,绕开模式映射表(用于协议实测)",
|
|
166
|
+
)
|
|
167
|
+
add_shared_arguments(raw_oper)
|
|
168
|
+
raw_oper.add_argument("--family-id", required=True)
|
|
169
|
+
raw_oper.add_argument("--device-id", required=True)
|
|
170
|
+
raw_oper.add_argument(
|
|
171
|
+
"--cmd",
|
|
172
|
+
action="append",
|
|
173
|
+
required=True,
|
|
174
|
+
metavar="KEY=VALUE",
|
|
175
|
+
help="要下发的字段,可多次指定,例如 --cmd C_MODE=1 --cmd C_FANSPEED=0",
|
|
176
|
+
)
|
|
162
177
|
return parser
|
|
163
178
|
|
|
164
179
|
|
|
@@ -488,6 +503,28 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
488
503
|
template.model_dump(mode="json") if template is not None else None,
|
|
489
504
|
)
|
|
490
505
|
return 0
|
|
506
|
+
if args.command == "raw-oper":
|
|
507
|
+
cmd: dict[str, str] = {}
|
|
508
|
+
for piece in args.cmd:
|
|
509
|
+
if "=" not in piece:
|
|
510
|
+
raise SuningError(f"--cmd 必须是 KEY=VALUE 形式,收到: {piece!r}")
|
|
511
|
+
key, value = piece.split("=", 1)
|
|
512
|
+
cmd[key.strip()] = value.strip()
|
|
513
|
+
target_device, model_id = client._resolve_ac_target(
|
|
514
|
+
args.family_id, args.device_id,
|
|
515
|
+
)
|
|
516
|
+
payload = client.app_oper(target_device, model_id, cmd)
|
|
517
|
+
_print_payload(
|
|
518
|
+
{
|
|
519
|
+
"status": "ok",
|
|
520
|
+
"command": "raw-oper",
|
|
521
|
+
"device_id": target_device,
|
|
522
|
+
"model_id": model_id,
|
|
523
|
+
"cmd": cmd,
|
|
524
|
+
"response": payload,
|
|
525
|
+
},
|
|
526
|
+
)
|
|
527
|
+
return 0
|
|
491
528
|
except CaptchaRequiredError as error:
|
|
492
529
|
_print_payload(
|
|
493
530
|
{
|
xiaobiu/client.py
CHANGED
|
@@ -19,7 +19,7 @@ from __future__ import annotations
|
|
|
19
19
|
import json
|
|
20
20
|
import time
|
|
21
21
|
from pathlib import Path
|
|
22
|
-
from typing import TYPE_CHECKING, Any, Mapping
|
|
22
|
+
from typing import TYPE_CHECKING, Any, Mapping, Sequence
|
|
23
23
|
|
|
24
24
|
import requests
|
|
25
25
|
from requests.cookies import create_cookie
|
|
@@ -366,8 +366,12 @@ class SuningSmartHomeClient:
|
|
|
366
366
|
def _build_ha_climate_preview(self, status: AirConditionerStatus) -> Any:
|
|
367
367
|
return ac_status._build_ha_climate_preview(status)
|
|
368
368
|
|
|
369
|
-
def _infer_hvac_mode(
|
|
370
|
-
|
|
369
|
+
def _infer_hvac_mode(
|
|
370
|
+
self, *, power_on: bool | None, mode_raw: Any, field_kind: str = "sn",
|
|
371
|
+
) -> HvacMode | None:
|
|
372
|
+
return ac_status.infer_hvac_mode(
|
|
373
|
+
power_on=power_on, mode_raw=mode_raw, field_kind=field_kind,
|
|
374
|
+
)
|
|
371
375
|
|
|
372
376
|
# SMS-login private helpers (re-exported for the test suite).
|
|
373
377
|
def _captcha_fields(self, captcha: CaptchaSolution) -> dict[str, str]:
|
|
@@ -641,6 +645,38 @@ class SuningSmartHomeClient:
|
|
|
641
645
|
target_device, _ = self._resolve_ac_target(family_id, device_id)
|
|
642
646
|
return ac_control.list_device_timers(self, target_device)
|
|
643
647
|
|
|
648
|
+
def set_device_timer(
|
|
649
|
+
self,
|
|
650
|
+
family_id: str | int,
|
|
651
|
+
device_id: str | int,
|
|
652
|
+
*,
|
|
653
|
+
hour: int,
|
|
654
|
+
minute: int,
|
|
655
|
+
weekdays: Sequence[bool] | None = None,
|
|
656
|
+
power_on: bool = True,
|
|
657
|
+
enabled: bool = True,
|
|
658
|
+
name: str | None = None,
|
|
659
|
+
command: Mapping[str, Any] | None = None,
|
|
660
|
+
) -> dict[str, Any]:
|
|
661
|
+
"""Create a cloud timer, or update one by re-sending its schedule.
|
|
662
|
+
|
|
663
|
+
The cloud has no delete call: a timer's ``T`` / ``F`` prefix is the
|
|
664
|
+
enabled flag, so ``enabled=False`` disables an existing schedule.
|
|
665
|
+
"""
|
|
666
|
+
|
|
667
|
+
target_device, _ = self._resolve_ac_target(family_id, device_id)
|
|
668
|
+
return ac_control.set_device_timer(
|
|
669
|
+
self,
|
|
670
|
+
target_device,
|
|
671
|
+
hour=hour,
|
|
672
|
+
minute=minute,
|
|
673
|
+
weekdays=weekdays,
|
|
674
|
+
power_on=power_on,
|
|
675
|
+
enabled=enabled,
|
|
676
|
+
name=name,
|
|
677
|
+
command=command,
|
|
678
|
+
)
|
|
679
|
+
|
|
644
680
|
def get_device_panel_template(
|
|
645
681
|
self,
|
|
646
682
|
family_id: str | int,
|
|
File without changes
|