python-xiaobiu 0.2.2__tar.gz → 0.2.3__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.
- {python_xiaobiu-0.2.2 → python_xiaobiu-0.2.3}/CHANGELOG.md +20 -0
- {python_xiaobiu-0.2.2 → python_xiaobiu-0.2.3}/PKG-INFO +19 -3
- {python_xiaobiu-0.2.2 → python_xiaobiu-0.2.3}/README.md +17 -1
- {python_xiaobiu-0.2.2 → python_xiaobiu-0.2.3}/pyproject.toml +1 -1
- {python_xiaobiu-0.2.2 → python_xiaobiu-0.2.3}/src/xiaobiu/ac_control.py +103 -4
- {python_xiaobiu-0.2.2 → python_xiaobiu-0.2.3}/src/xiaobiu/client.py +33 -1
- {python_xiaobiu-0.2.2 → python_xiaobiu-0.2.3}/tests/test_ac_control.py +52 -1
- {python_xiaobiu-0.2.2 → python_xiaobiu-0.2.3}/.github/workflows/python-publish.yml +0 -0
- {python_xiaobiu-0.2.2 → python_xiaobiu-0.2.3}/.gitignore +0 -0
- {python_xiaobiu-0.2.2 → python_xiaobiu-0.2.3}/docs/plans/2026-06-01-ac-control-design/bdd-specs.md +0 -0
- {python_xiaobiu-0.2.2 → python_xiaobiu-0.2.3}/docs/plans/2026-06-01-ac-control-plan/_index.md +0 -0
- {python_xiaobiu-0.2.2 → python_xiaobiu-0.2.3}/docs/plans/2026-06-01-ac-control-plan/task-001-ac-enums-impl.md +0 -0
- {python_xiaobiu-0.2.2 → python_xiaobiu-0.2.3}/docs/plans/2026-06-01-ac-control-plan/task-001-ac-enums-test.md +0 -0
- {python_xiaobiu-0.2.2 → python_xiaobiu-0.2.3}/docs/plans/2026-06-01-ac-control-plan/task-002-ac-cmd-mappings-impl.md +0 -0
- {python_xiaobiu-0.2.2 → python_xiaobiu-0.2.3}/docs/plans/2026-06-01-ac-control-plan/task-002-ac-cmd-mappings-test.md +0 -0
- {python_xiaobiu-0.2.2 → python_xiaobiu-0.2.3}/docs/plans/2026-06-01-ac-control-plan/task-003-ac-app-oper-impl.md +0 -0
- {python_xiaobiu-0.2.2 → python_xiaobiu-0.2.3}/docs/plans/2026-06-01-ac-control-plan/task-003-ac-app-oper-test.md +0 -0
- {python_xiaobiu-0.2.2 → python_xiaobiu-0.2.3}/docs/plans/2026-06-01-ac-control-plan/task-004-ac-highlevel-impl.md +0 -0
- {python_xiaobiu-0.2.2 → python_xiaobiu-0.2.3}/docs/plans/2026-06-01-ac-control-plan/task-004-ac-highlevel-test.md +0 -0
- {python_xiaobiu-0.2.2 → python_xiaobiu-0.2.3}/docs/plans/2026-06-01-ac-control-plan/task-005-ac-panel-template-impl.md +0 -0
- {python_xiaobiu-0.2.2 → python_xiaobiu-0.2.3}/docs/plans/2026-06-01-ac-control-plan/task-005-ac-panel-template-test.md +0 -0
- {python_xiaobiu-0.2.2 → python_xiaobiu-0.2.3}/docs/plans/2026-06-01-ac-control-plan/task-006-ac-timers-impl.md +0 -0
- {python_xiaobiu-0.2.2 → python_xiaobiu-0.2.3}/docs/plans/2026-06-01-ac-control-plan/task-006-ac-timers-test.md +0 -0
- {python_xiaobiu-0.2.2 → python_xiaobiu-0.2.3}/docs/plans/2026-06-01-ac-control-plan/task-007-ac-state-hvac-impl.md +0 -0
- {python_xiaobiu-0.2.2 → python_xiaobiu-0.2.3}/docs/plans/2026-06-01-ac-control-plan/task-007-ac-state-hvac-test.md +0 -0
- {python_xiaobiu-0.2.2 → python_xiaobiu-0.2.3}/docs/plans/2026-06-01-ac-control-plan/task-008-cli-ac-control-impl.md +0 -0
- {python_xiaobiu-0.2.2 → python_xiaobiu-0.2.3}/docs/plans/2026-06-01-ac-control-plan/task-008-cli-ac-control-test.md +0 -0
- {python_xiaobiu-0.2.2 → python_xiaobiu-0.2.3}/docs/plans/2026-06-01-ac-control-plan/task-009-docs-readme-impl.md +0 -0
- {python_xiaobiu-0.2.2 → python_xiaobiu-0.2.3}/docs/plans/2026-06-02-ac-control-align-ha-design/bdd-specs.md +0 -0
- {python_xiaobiu-0.2.2 → python_xiaobiu-0.2.3}/docs/plans/2026-06-02-ac-control-align-ha-plan/_index.md +0 -0
- {python_xiaobiu-0.2.2 → python_xiaobiu-0.2.3}/src/xiaobiu/__init__.py +0 -0
- {python_xiaobiu-0.2.2 → python_xiaobiu-0.2.3}/src/xiaobiu/ac_status.py +0 -0
- {python_xiaobiu-0.2.2 → python_xiaobiu-0.2.3}/src/xiaobiu/app_api.py +0 -0
- {python_xiaobiu-0.2.2 → python_xiaobiu-0.2.3}/src/xiaobiu/captcha_bridge.py +0 -0
- {python_xiaobiu-0.2.2 → python_xiaobiu-0.2.3}/src/xiaobiu/cli.py +0 -0
- {python_xiaobiu-0.2.2 → python_xiaobiu-0.2.3}/src/xiaobiu/crypto.py +0 -0
- {python_xiaobiu-0.2.2 → python_xiaobiu-0.2.3}/src/xiaobiu/exceptions.py +0 -0
- {python_xiaobiu-0.2.2 → python_xiaobiu-0.2.3}/src/xiaobiu/har_templates.py +0 -0
- {python_xiaobiu-0.2.2 → python_xiaobiu-0.2.3}/src/xiaobiu/models.py +0 -0
- {python_xiaobiu-0.2.2 → python_xiaobiu-0.2.3}/src/xiaobiu/parsers.py +0 -0
- {python_xiaobiu-0.2.2 → python_xiaobiu-0.2.3}/src/xiaobiu/persistence.py +0 -0
- {python_xiaobiu-0.2.2 → python_xiaobiu-0.2.3}/src/xiaobiu/sms_login.py +0 -0
- {python_xiaobiu-0.2.2 → python_xiaobiu-0.2.3}/tests/__init__.py +0 -0
- {python_xiaobiu-0.2.2 → python_xiaobiu-0.2.3}/tests/test_ac_status.py +0 -0
- {python_xiaobiu-0.2.2 → python_xiaobiu-0.2.3}/tests/test_app_api.py +0 -0
- {python_xiaobiu-0.2.2 → python_xiaobiu-0.2.3}/tests/test_captcha_bridge.py +0 -0
- {python_xiaobiu-0.2.2 → python_xiaobiu-0.2.3}/tests/test_cli.py +0 -0
- {python_xiaobiu-0.2.2 → python_xiaobiu-0.2.3}/tests/test_client.py +0 -0
- {python_xiaobiu-0.2.2 → python_xiaobiu-0.2.3}/tests/test_crypto.py +0 -0
- {python_xiaobiu-0.2.2 → python_xiaobiu-0.2.3}/tests/test_har_templates.py +0 -0
- {python_xiaobiu-0.2.2 → python_xiaobiu-0.2.3}/tests/test_models.py +0 -0
- {python_xiaobiu-0.2.2 → python_xiaobiu-0.2.3}/tests/test_parsers.py +0 -0
- {python_xiaobiu-0.2.2 → python_xiaobiu-0.2.3}/tests/test_persistence.py +0 -0
- {python_xiaobiu-0.2.2 → python_xiaobiu-0.2.3}/tests/test_sms_login.py +0 -0
- {python_xiaobiu-0.2.2 → python_xiaobiu-0.2.3}/uv.lock +0 -0
|
@@ -4,6 +4,26 @@ 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.3] - 2026-11-25
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
- `set_device_timer()` on the client and `ac_control.set_device_timer()`:
|
|
11
|
+
create cloud timers with `T,<hour>,<minute>,<weekmask>`, mirroring
|
|
12
|
+
`TimingStepTwoActivity` from 苏宁 AI家 7.0.2.
|
|
13
|
+
- `build_timer_schedule()` and `encode_timer_weekdays()` helpers for the
|
|
14
|
+
app's odd weekday bit packing (`1` + first bit + reversed remaining six).
|
|
15
|
+
|
|
16
|
+
### Fixed
|
|
17
|
+
- `list_device_timers()` enabled flag now follows the `T` / `F` prefix of
|
|
18
|
+
the schedule string. The cloud reports `state="1"` for enabled and
|
|
19
|
+
`state="0"` for disabled; the previous mapping treated `"0"` as enabled.
|
|
20
|
+
|
|
21
|
+
### Notes
|
|
22
|
+
- The cloud exposes **no delete endpoint**: `clearTimer` returns 404 on
|
|
23
|
+
every host, and `setTimer` rejects an empty command with `1009 命令为空`.
|
|
24
|
+
Disabling a timer (`enabled=False`) is the only supported way to retire
|
|
25
|
+
one.
|
|
26
|
+
|
|
7
27
|
## [0.2.2] - 2026-06-24
|
|
8
28
|
|
|
9
29
|
### Added
|
|
@@ -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
|
|
@@ -112,6 +112,21 @@ client.list_device_timers(family_id=37790, device_id="...")
|
|
|
112
112
|
client.get_device_panel_template(family_id=37790, device_id="...")
|
|
113
113
|
```
|
|
114
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
|
+
|
|
115
130
|
### HA climate entity mapping
|
|
116
131
|
|
|
117
132
|
| Suning App | `xiaobiu` API | `C_*` field | HA climate field |
|
|
@@ -228,7 +243,8 @@ xiaobiucli raw-oper --family-id 37790 --device-id <id> --cmd C_MODE=
|
|
|
228
243
|
暴露为 `HvacMode.AUTO`;`HvacMode.QUICK` 也指向 `C_MODE=6`。
|
|
229
244
|
- **`C_ELECHEATING` (电辅热)** 值域已实测确认为 `0/1`。`set_aux_heat(on=True)` 在客户端
|
|
230
245
|
强制 App 的"仅制热时生效"规则(当前模式非 HEAT 时 raise `SuningError`)。
|
|
231
|
-
- **`SN_CLOUD_TIMER` writes** are not implemented
|
|
246
|
+
- **`SN_CLOUD_TIMER` writes** are not implemented; cloud timers go through
|
|
247
|
+
`set_device_timer` instead, and cannot be deleted (only disabled).
|
|
232
248
|
- **Unknown `C_MODE` values** (e.g. `7`, which neither the App nor the
|
|
233
249
|
capture expose) collapse to `hvac_mode = None` so Home Assistant can
|
|
234
250
|
render `unavailable` rather than guessing.
|
|
@@ -91,6 +91,21 @@ client.list_device_timers(family_id=37790, device_id="...")
|
|
|
91
91
|
client.get_device_panel_template(family_id=37790, device_id="...")
|
|
92
92
|
```
|
|
93
93
|
|
|
94
|
+
### Timers
|
|
95
|
+
|
|
96
|
+
```python
|
|
97
|
+
timers = client.list_device_timers(family_id=37790, device_id="...")
|
|
98
|
+
client.set_device_timer(
|
|
99
|
+
family_id=37790, device_id="...",
|
|
100
|
+
hour=23, minute=0, power_on=False, name="关闭时间",
|
|
101
|
+
)
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
`timer` uses the app's `T,<hour>,<minute>,<weekmask>` format. The leading
|
|
105
|
+
`T` / `F` is the enabled flag — pass `enabled=False` to disable an
|
|
106
|
+
existing schedule, because the cloud has **no delete call** (`clearTimer`
|
|
107
|
+
returns 404 and `setTimer` rejects an empty command).
|
|
108
|
+
|
|
94
109
|
### HA climate entity mapping
|
|
95
110
|
|
|
96
111
|
| Suning App | `xiaobiu` API | `C_*` field | HA climate field |
|
|
@@ -207,7 +222,8 @@ xiaobiucli raw-oper --family-id 37790 --device-id <id> --cmd C_MODE=
|
|
|
207
222
|
暴露为 `HvacMode.AUTO`;`HvacMode.QUICK` 也指向 `C_MODE=6`。
|
|
208
223
|
- **`C_ELECHEATING` (电辅热)** 值域已实测确认为 `0/1`。`set_aux_heat(on=True)` 在客户端
|
|
209
224
|
强制 App 的"仅制热时生效"规则(当前模式非 HEAT 时 raise `SuningError`)。
|
|
210
|
-
- **`SN_CLOUD_TIMER` writes** are not implemented
|
|
225
|
+
- **`SN_CLOUD_TIMER` writes** are not implemented; cloud timers go through
|
|
226
|
+
`set_device_timer` instead, and cannot be deleted (only disabled).
|
|
211
227
|
- **Unknown `C_MODE` values** (e.g. `7`, which neither the App nor the
|
|
212
228
|
capture expose) collapse to `hvac_mode = None` so Home Assistant can
|
|
213
229
|
render `unavailable` rather than guessing.
|
|
@@ -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,6 +37,7 @@ 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
|
|
@@ -374,12 +376,26 @@ def build_capabilities_from_template(
|
|
|
374
376
|
)
|
|
375
377
|
|
|
376
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
|
+
|
|
377
393
|
def list_device_timers(client: Any, device_id: str) -> list[Timer]:
|
|
378
394
|
"""Fetch the cloud timer list for ``device_id``.
|
|
379
395
|
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
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.
|
|
383
399
|
"""
|
|
384
400
|
|
|
385
401
|
body = json.dumps(
|
|
@@ -408,13 +424,92 @@ def list_device_timers(client: Any, device_id: str) -> list[Timer]:
|
|
|
408
424
|
Timer(
|
|
409
425
|
name=str(item.get("timerName") or ""),
|
|
410
426
|
schedule=str(item.get("timer") or ""),
|
|
411
|
-
enabled=
|
|
427
|
+
enabled=_timer_enabled(item.get("timer"), item.get("state")),
|
|
412
428
|
command={str(k): str(v) for k, v in (item.get("timerCmd") or {}).items()},
|
|
413
429
|
)
|
|
414
430
|
)
|
|
415
431
|
return timers
|
|
416
432
|
|
|
417
433
|
|
|
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
|
+
|
|
418
513
|
def infer_hvac_mode(
|
|
419
514
|
*,
|
|
420
515
|
power_on: bool | None,
|
|
@@ -706,6 +801,10 @@ __all__ = [
|
|
|
706
801
|
"PRESET_ON_CMD",
|
|
707
802
|
"PanelTemplate",
|
|
708
803
|
"QUERY_TIMER_URL",
|
|
804
|
+
"SET_TIMER_URL",
|
|
805
|
+
"build_timer_schedule",
|
|
806
|
+
"encode_timer_weekdays",
|
|
807
|
+
"set_device_timer",
|
|
709
808
|
"SN_FIELD_TO_HVAC",
|
|
710
809
|
"SWING_TO_CMD",
|
|
711
810
|
"TEMP_MAX_C",
|
|
@@ -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
|
|
@@ -645,6 +645,38 @@ class SuningSmartHomeClient:
|
|
|
645
645
|
target_device, _ = self._resolve_ac_target(family_id, device_id)
|
|
646
646
|
return ac_control.list_device_timers(self, target_device)
|
|
647
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
|
+
|
|
648
680
|
def get_device_panel_template(
|
|
649
681
|
self,
|
|
650
682
|
family_id: str | int,
|
|
@@ -382,7 +382,7 @@ TIMER_RESPONSE = {
|
|
|
382
382
|
"responseData": {
|
|
383
383
|
"data": [
|
|
384
384
|
{"timer": "F,00,30,0", "timerName": "关闭时间", "state": "-1", "timerCmd": {"C_POWER": "0"}},
|
|
385
|
-
{"timer": "
|
|
385
|
+
{"timer": "T,11,40,0", "timerName": "开启时间", "state": "1", "timerCmd": {"C_POWER": "1"}},
|
|
386
386
|
]
|
|
387
387
|
},
|
|
388
388
|
}
|
|
@@ -820,3 +820,54 @@ def test_build_capabilities_auto_appears_in_hvac_modes() -> None:
|
|
|
820
820
|
# 一键通 is exposed as AUTO on the tested device (C_MODE=6).
|
|
821
821
|
assert "auto" in caps.hvac_modes
|
|
822
822
|
|
|
823
|
+
|
|
824
|
+
|
|
825
|
+
from xiaobiu import ac_control
|
|
826
|
+
|
|
827
|
+
|
|
828
|
+
def test_encode_timer_weekdays_matches_app_bitpacking() -> None:
|
|
829
|
+
"""The app packs days as ``1`` + first bit + reversed remaining six."""
|
|
830
|
+
assert ac_control.encode_timer_weekdays([True] * 7) == 255
|
|
831
|
+
assert ac_control.encode_timer_weekdays([False] * 7) == 0
|
|
832
|
+
assert ac_control.encode_timer_weekdays([True] + [False] * 6) == 192
|
|
833
|
+
assert ac_control.encode_timer_weekdays([False] * 6 + [True]) == 160
|
|
834
|
+
|
|
835
|
+
|
|
836
|
+
def test_build_timer_schedule_prefix_and_bounds() -> None:
|
|
837
|
+
assert ac_control.build_timer_schedule(hour=9, minute=8) == "T,9,8,255"
|
|
838
|
+
with pytest.raises(ValueError):
|
|
839
|
+
ac_control.build_timer_schedule(hour=24, minute=0)
|
|
840
|
+
with pytest.raises(ValueError):
|
|
841
|
+
ac_control.build_timer_schedule(hour=1, minute=60)
|
|
842
|
+
with pytest.raises(ValueError):
|
|
843
|
+
ac_control.encode_timer_weekdays([True] * 6)
|
|
844
|
+
|
|
845
|
+
|
|
846
|
+
def test_set_device_timer_body_and_enabled_flag() -> None:
|
|
847
|
+
sent: list[str] = []
|
|
848
|
+
|
|
849
|
+
class StubResponse:
|
|
850
|
+
def json(self):
|
|
851
|
+
return {"responseCode": "0"}
|
|
852
|
+
|
|
853
|
+
class StubClient:
|
|
854
|
+
def _request_app_api(self, url, *, body):
|
|
855
|
+
sent.append(body)
|
|
856
|
+
assert url == ac_control.SET_TIMER_URL
|
|
857
|
+
return StubResponse()
|
|
858
|
+
|
|
859
|
+
ac_control.set_device_timer(
|
|
860
|
+
StubClient(), "dev", hour=7, minute=5, power_on=True, name="开启时间"
|
|
861
|
+
)
|
|
862
|
+
body = json.loads(sent[0])
|
|
863
|
+
assert body["deviceId"] == "dev"
|
|
864
|
+
assert body["timer"] == "T,7,5,255"
|
|
865
|
+
assert json.loads(body["cmd"]) == {"C_POWER": "1"}
|
|
866
|
+
assert body["timerName"] == "%E5%BC%80%E5%90%AF%E6%97%B6%E9%97%B4"
|
|
867
|
+
|
|
868
|
+
ac_control.set_device_timer(
|
|
869
|
+
StubClient(), "dev", hour=7, minute=5, power_on=False, enabled=False
|
|
870
|
+
)
|
|
871
|
+
disabled = json.loads(sent[1])
|
|
872
|
+
assert disabled["timer"].startswith("F,")
|
|
873
|
+
assert json.loads(disabled["cmd"]) == {"C_POWER": "0"}
|
|
File without changes
|
|
File without changes
|
{python_xiaobiu-0.2.2 → python_xiaobiu-0.2.3}/docs/plans/2026-06-01-ac-control-design/bdd-specs.md
RENAMED
|
File without changes
|
{python_xiaobiu-0.2.2 → python_xiaobiu-0.2.3}/docs/plans/2026-06-01-ac-control-plan/_index.md
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|