dimplex-controller 0.12.0__tar.gz → 0.13.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dimplex-controller
3
- Version: 0.12.0
3
+ Version: 0.13.0
4
4
  Summary: Python client for Dimplex heating controllers (GDHV IoT)
5
5
  License: MIT
6
6
  License-File: LICENSE
@@ -27,12 +27,12 @@ Description-Content-Type: text/markdown
27
27
 
28
28
  # Dimplex Controller Python Client
29
29
 
30
- [![PyPI version](https://img.shields.io/pypi/v/dimplex-controller.svg)](https://pypi.org/project/dimplex-controller/)
31
- [![Python versions](https://img.shields.io/badge/python-3.10%2B-blue.svg)](https://www.python.org/downloads/)
30
+ [![PyPI version](https://img.shields.io/pypi/v/dimplex-controller)](https://pypi.org/project/dimplex-controller/)
31
+ [![Python versions](https://img.shields.io/badge/python-3.10%2B-blue)](https://www.python.org/downloads/)
32
32
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
33
- [![CI Tests](https://img.shields.io/github/actions/workflow/status/KRoperUK/dimplex-controller-py/test.yml?branch=main&label=CI)](https://github.com/KRoperUK/dimplex-controller-py/actions/workflows/test.yml)
34
- [![Downloads](https://img.shields.io/pypi/dm/dimplex-controller.svg)](https://pypi.org/project/dimplex-controller/)
35
- [![Buy me a coffee](https://img.shields.io/badge/buy%20me%20a%20coffee-donate-yellow.svg)](https://buymeacoffee.com/kroperukc)
33
+ [![CI](https://img.shields.io/github/actions/workflow/status/KRoperUK/dimplex-controller-py/test.yml?branch=main&label=CI)](https://github.com/KRoperUK/dimplex-controller-py/actions/workflows/test.yml)
34
+ [![Downloads](https://img.shields.io/pypi/dm/dimplex-controller)](https://pypi.org/project/dimplex-controller/)
35
+ [![Buy me a coffee](https://img.shields.io/badge/buy%20me%20a%20coffee-donate-yellow)](https://buymeacoffee.com/kroperukc)
36
36
 
37
37
  <p align="center">
38
38
  <strong>Async Python client for controlling Glen Dimplex Heating &amp; Ventilation (GDHV) appliances via the Dimplex cloud API.</strong>
@@ -177,21 +177,44 @@ for status in status_list:
177
177
  ### Sending control commands
178
178
 
179
179
  ```python
180
- from dimplex_controller.models import ApplianceModeSettings
181
-
182
180
  # Enable EcoStart
183
181
  await client.set_eco_start(hub_id, [appliance_id], True)
184
182
 
185
183
  # Enable Open Window Detection
186
184
  await client.set_open_window_detection(hub_id, [appliance_id], True)
187
185
 
188
- # Activate Boost
186
+ # Timed Boost (ApplianceModes=2, Time = minutes)
189
187
  await client.set_boost(hub_id, [appliance_id], temperature=25.0, duration_minutes=60)
190
188
 
191
- # Set target temperature (rewrites timer period setpoints)
192
- await client.set_target_temperature(hub_id, appliance_id, 21.5)
189
+ # Away until a given moment (ApplianceModes=4). Away is a settable 7–30 °C
190
+ # setback and defaults to the 7 °C anti-freeze floor.
191
+ from datetime import datetime, timedelta, timezone
192
+
193
+ await client.set_away(
194
+ hub_id,
195
+ [appliance_id],
196
+ temperature=12.0,
197
+ until=datetime.now(timezone.utc) + timedelta(days=3),
198
+ )
199
+
200
+ # Set the target temperature — dedicated endpoint, leaves the schedule alone
201
+ await client.set_appliance_setpoint_temperature(hub_id, [appliance_id], 21.5)
202
+
203
+ # Turn off the way the app does: frost protection at 7 °C
204
+ await client.turn_off(hub_id, [appliance_id])
193
205
  ```
194
206
 
207
+ > **Mode flag values matter.** `EApplianceModes` is a bitfield where Boost is `2`
208
+ > and Away is `4`; `16` is Advance and `32` is FrostProtect. Releases before
209
+ > 0.13.0 had these wrong, so Boost silently became Advance and Away became a
210
+ > fixed 7 °C frost hold. If you hand-build `ApplianceModeSettings`, use
211
+ > `ApplianceModeFlag`. See
212
+ > [docs/decompiled-api-reference.md](docs/decompiled-api-reference.md).
213
+ >
214
+ > **Avoid `SetTimerMode` for control.** `set_mode()` and the deprecated
215
+ > `set_target_temperature()` rewrite the schedule; Quantum rejects that with
216
+ > HTTP 403. Use `set_appliance_setpoint_temperature()` and `turn_off()`.
217
+
195
218
  ### Energy reports
196
219
 
197
220
  ```python
@@ -233,16 +256,23 @@ Main client class. Construct with an `aiohttp.ClientSession` and a `refresh_toke
233
256
  | `get_user_context()` | Returns `UserContext`. |
234
257
  | `get_product_models()` | Returns `list[ProductModel]` (cacheable). |
235
258
  | `get_schedule(hub_id, appliance_id)` | Returns `TimerModeSettings` (timer + periods). |
236
- | `set_mode(hub_id, appliance_id, mode)` | Change timer/operation mode. |
237
- | `set_target_temperature(hub_id, appliance_id, temp)` | Rewrite all period setpoints or install full-week schedule. |
259
+ | `set_mode(hub_id, appliance_id, mode)` | Rewrite `TimerMode`. **403 on Quantum** — prefer `turn_off`. |
260
+ | `set_target_temperature(hub_id, appliance_id, temp)` | Deprecated: rewrites period setpoints. Prefer `set_appliance_setpoint_temperature`. |
261
+ | `set_appliance_setpoint_temperature(hub_id, appliance_ids, temperature)` | Preferred setpoint path; non-destructive. |
238
262
  | `set_period_setpoint(...)` | Update one timer period without clobbering siblings. |
239
263
  | `update_period(...)` | Replace a timer period matched by day + start time. |
240
- | `set_boost(hub_id, appliance_ids, *, temperature, duration_minutes, enable)` | Enable/disable Boost. |
264
+ | `copy_schedule_to_appliances(...)` | Copy one appliance's schedule onto others. |
265
+ | `set_boost(hub_id, appliance_ids, *, temperature, duration_minutes, enable)` | Timed Boost (`ApplianceModes=2`). |
241
266
  | `clear_boost(hub_id, appliance_ids)` | Disable Boost. |
242
- | `set_away(hub_id, appliance_ids, *, temperature, enable, number_of_days)` | Enable/disable Away. |
267
+ | `set_away(hub_id, appliance_ids, *, temperature, enable, until, number_of_days)` | Away setback (`ApplianceModes=4`). |
243
268
  | `clear_away(hub_id, appliance_ids)` | Disable Away. |
269
+ | `set_frost_protect(...)` / `turn_off(...)` | Frost protection at 7 °C — the app's "off". |
270
+ | `set_advance(...)` | Advance to the next schedule period. |
271
+ | `set_manual(...)` / `set_eco_mode(...)` | Manual / Eco mode holds. |
272
+ | `set_setback_temperature(...)` | Write the setback temperature (untested). |
244
273
  | `set_eco_start(hub_id, appliance_ids, enable)` | Toggle EcoStart. |
245
274
  | `set_open_window_detection(hub_id, appliance_ids, enable)` | Toggle Open Window Detection. |
275
+ | `set_hot_water_*(...)` / `*_heat_pump_hot_water_schedule(...)` | Hot-water cylinder surface (untested — no hardware). |
246
276
  | `get_tsi_energy_report(hub_id, ...)` | Returns `TsiEnergyReport`. |
247
277
  | `capabilities_for(appliance, *, status, product)` | Derive an `ApplianceCapabilities` matrix. |
248
278
  | `export_tokens()` / `apply_tokens(bundle)` | Token persistence helpers. |
@@ -1,11 +1,11 @@
1
1
  # Dimplex Controller Python Client
2
2
 
3
- [![PyPI version](https://img.shields.io/pypi/v/dimplex-controller.svg)](https://pypi.org/project/dimplex-controller/)
4
- [![Python versions](https://img.shields.io/badge/python-3.10%2B-blue.svg)](https://www.python.org/downloads/)
3
+ [![PyPI version](https://img.shields.io/pypi/v/dimplex-controller)](https://pypi.org/project/dimplex-controller/)
4
+ [![Python versions](https://img.shields.io/badge/python-3.10%2B-blue)](https://www.python.org/downloads/)
5
5
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
6
- [![CI Tests](https://img.shields.io/github/actions/workflow/status/KRoperUK/dimplex-controller-py/test.yml?branch=main&label=CI)](https://github.com/KRoperUK/dimplex-controller-py/actions/workflows/test.yml)
7
- [![Downloads](https://img.shields.io/pypi/dm/dimplex-controller.svg)](https://pypi.org/project/dimplex-controller/)
8
- [![Buy me a coffee](https://img.shields.io/badge/buy%20me%20a%20coffee-donate-yellow.svg)](https://buymeacoffee.com/kroperukc)
6
+ [![CI](https://img.shields.io/github/actions/workflow/status/KRoperUK/dimplex-controller-py/test.yml?branch=main&label=CI)](https://github.com/KRoperUK/dimplex-controller-py/actions/workflows/test.yml)
7
+ [![Downloads](https://img.shields.io/pypi/dm/dimplex-controller)](https://pypi.org/project/dimplex-controller/)
8
+ [![Buy me a coffee](https://img.shields.io/badge/buy%20me%20a%20coffee-donate-yellow)](https://buymeacoffee.com/kroperukc)
9
9
 
10
10
  <p align="center">
11
11
  <strong>Async Python client for controlling Glen Dimplex Heating &amp; Ventilation (GDHV) appliances via the Dimplex cloud API.</strong>
@@ -150,21 +150,44 @@ for status in status_list:
150
150
  ### Sending control commands
151
151
 
152
152
  ```python
153
- from dimplex_controller.models import ApplianceModeSettings
154
-
155
153
  # Enable EcoStart
156
154
  await client.set_eco_start(hub_id, [appliance_id], True)
157
155
 
158
156
  # Enable Open Window Detection
159
157
  await client.set_open_window_detection(hub_id, [appliance_id], True)
160
158
 
161
- # Activate Boost
159
+ # Timed Boost (ApplianceModes=2, Time = minutes)
162
160
  await client.set_boost(hub_id, [appliance_id], temperature=25.0, duration_minutes=60)
163
161
 
164
- # Set target temperature (rewrites timer period setpoints)
165
- await client.set_target_temperature(hub_id, appliance_id, 21.5)
162
+ # Away until a given moment (ApplianceModes=4). Away is a settable 7–30 °C
163
+ # setback and defaults to the 7 °C anti-freeze floor.
164
+ from datetime import datetime, timedelta, timezone
165
+
166
+ await client.set_away(
167
+ hub_id,
168
+ [appliance_id],
169
+ temperature=12.0,
170
+ until=datetime.now(timezone.utc) + timedelta(days=3),
171
+ )
172
+
173
+ # Set the target temperature — dedicated endpoint, leaves the schedule alone
174
+ await client.set_appliance_setpoint_temperature(hub_id, [appliance_id], 21.5)
175
+
176
+ # Turn off the way the app does: frost protection at 7 °C
177
+ await client.turn_off(hub_id, [appliance_id])
166
178
  ```
167
179
 
180
+ > **Mode flag values matter.** `EApplianceModes` is a bitfield where Boost is `2`
181
+ > and Away is `4`; `16` is Advance and `32` is FrostProtect. Releases before
182
+ > 0.13.0 had these wrong, so Boost silently became Advance and Away became a
183
+ > fixed 7 °C frost hold. If you hand-build `ApplianceModeSettings`, use
184
+ > `ApplianceModeFlag`. See
185
+ > [docs/decompiled-api-reference.md](docs/decompiled-api-reference.md).
186
+ >
187
+ > **Avoid `SetTimerMode` for control.** `set_mode()` and the deprecated
188
+ > `set_target_temperature()` rewrite the schedule; Quantum rejects that with
189
+ > HTTP 403. Use `set_appliance_setpoint_temperature()` and `turn_off()`.
190
+
168
191
  ### Energy reports
169
192
 
170
193
  ```python
@@ -206,16 +229,23 @@ Main client class. Construct with an `aiohttp.ClientSession` and a `refresh_toke
206
229
  | `get_user_context()` | Returns `UserContext`. |
207
230
  | `get_product_models()` | Returns `list[ProductModel]` (cacheable). |
208
231
  | `get_schedule(hub_id, appliance_id)` | Returns `TimerModeSettings` (timer + periods). |
209
- | `set_mode(hub_id, appliance_id, mode)` | Change timer/operation mode. |
210
- | `set_target_temperature(hub_id, appliance_id, temp)` | Rewrite all period setpoints or install full-week schedule. |
232
+ | `set_mode(hub_id, appliance_id, mode)` | Rewrite `TimerMode`. **403 on Quantum** — prefer `turn_off`. |
233
+ | `set_target_temperature(hub_id, appliance_id, temp)` | Deprecated: rewrites period setpoints. Prefer `set_appliance_setpoint_temperature`. |
234
+ | `set_appliance_setpoint_temperature(hub_id, appliance_ids, temperature)` | Preferred setpoint path; non-destructive. |
211
235
  | `set_period_setpoint(...)` | Update one timer period without clobbering siblings. |
212
236
  | `update_period(...)` | Replace a timer period matched by day + start time. |
213
- | `set_boost(hub_id, appliance_ids, *, temperature, duration_minutes, enable)` | Enable/disable Boost. |
237
+ | `copy_schedule_to_appliances(...)` | Copy one appliance's schedule onto others. |
238
+ | `set_boost(hub_id, appliance_ids, *, temperature, duration_minutes, enable)` | Timed Boost (`ApplianceModes=2`). |
214
239
  | `clear_boost(hub_id, appliance_ids)` | Disable Boost. |
215
- | `set_away(hub_id, appliance_ids, *, temperature, enable, number_of_days)` | Enable/disable Away. |
240
+ | `set_away(hub_id, appliance_ids, *, temperature, enable, until, number_of_days)` | Away setback (`ApplianceModes=4`). |
216
241
  | `clear_away(hub_id, appliance_ids)` | Disable Away. |
242
+ | `set_frost_protect(...)` / `turn_off(...)` | Frost protection at 7 °C — the app's "off". |
243
+ | `set_advance(...)` | Advance to the next schedule period. |
244
+ | `set_manual(...)` / `set_eco_mode(...)` | Manual / Eco mode holds. |
245
+ | `set_setback_temperature(...)` | Write the setback temperature (untested). |
217
246
  | `set_eco_start(hub_id, appliance_ids, enable)` | Toggle EcoStart. |
218
247
  | `set_open_window_detection(hub_id, appliance_ids, enable)` | Toggle Open Window Detection. |
248
+ | `set_hot_water_*(...)` / `*_heat_pump_hot_water_schedule(...)` | Hot-water cylinder surface (untested — no hardware). |
219
249
  | `get_tsi_energy_report(hub_id, ...)` | Returns `TsiEnergyReport`. |
220
250
  | `capabilities_for(appliance, *, status, product)` | Derive an `ApplianceCapabilities` matrix. |
221
251
  | `export_tokens()` / `apply_tokens(bundle)` | Token persistence helpers. |
@@ -14,6 +14,15 @@ need a stable id → status mapping.
14
14
  from .auth import TokenBundle, TokenListener
15
15
  from .capabilities import ApplianceCapabilities, capabilities_for
16
16
  from .client import DimplexControl
17
+ from .const import (
18
+ DEFAULT_AWAY_TEMPERATURE,
19
+ DEFAULT_BOOST_TEMPERATURE,
20
+ FROST_TEMPERATURE,
21
+ MODE_TEMP_MAX,
22
+ MODE_TEMP_MIN,
23
+ NO_SETPOINT_SENTINEL,
24
+ NULL_DATETIME,
25
+ )
17
26
  from .exceptions import (
18
27
  DimplexApiError,
19
28
  DimplexAuthError,
@@ -28,10 +37,14 @@ from .models import (
28
37
  Appliance,
29
38
  ApplianceModeFlag,
30
39
  ApplianceModeSettings,
40
+ ApplianceModeStatus,
31
41
  ApplianceStatus,
32
42
  AutomaticProvisioning,
33
43
  Hub,
44
+ HygieneFrequency,
34
45
  ProductModel,
46
+ ScheduleProfile,
47
+ SetbackStatus,
35
48
  TimerMode,
36
49
  TimerModeSettings,
37
50
  TimerPeriod,
@@ -59,12 +72,23 @@ __all__ = [
59
72
  "ApplianceStatus",
60
73
  "ApplianceModeSettings",
61
74
  "ApplianceModeFlag",
75
+ "ApplianceModeStatus",
76
+ "HygieneFrequency",
77
+ "ScheduleProfile",
78
+ "SetbackStatus",
62
79
  "TimerMode",
63
80
  "TimerModeSettings",
64
81
  "TimerPeriod",
65
82
  "AutomaticProvisioning",
66
83
  "ProductModel",
67
84
  "TsiEnergyReport",
85
+ "DEFAULT_AWAY_TEMPERATURE",
86
+ "DEFAULT_BOOST_TEMPERATURE",
87
+ "FROST_TEMPERATURE",
88
+ "MODE_TEMP_MIN",
89
+ "MODE_TEMP_MAX",
90
+ "NO_SETPOINT_SENTINEL",
91
+ "NULL_DATETIME",
68
92
  "parse_telemetry_points",
69
93
  "filter_telemetry_points",
70
94
  "summarise_energy",
@@ -309,12 +309,23 @@ class AuthManager:
309
309
 
310
310
  Uses direct HTTP credential submission so users don't need to
311
311
  manually extract auth codes from browser network traffic.
312
+
313
+ A separate :class:`aiohttp.ClientSession` is used because the B2C
314
+ flow requires a dedicated cookie jar for state tracking across
315
+ redirects (using the shared session would pollute its cookies).
316
+ The session inherits the caller's **connector** (TLS/proxy config)
317
+ and the configured timeout so network behaviour is consistent.
312
318
  """
313
319
  jar = aiohttp.CookieJar(unsafe=True)
314
320
  start_url = self.get_login_url()
321
+ # Inherit the caller's connector (TLS cert, proxy, DNS resolver) so
322
+ # headless login respects the same network configuration as API calls.
323
+ connector = self._session.connector
315
324
 
316
325
  try:
317
- async with aiohttp.ClientSession(cookie_jar=jar, timeout=self._timeout) as session:
326
+ async with aiohttp.ClientSession(
327
+ cookie_jar=jar, timeout=self._timeout, connector=connector, connector_owner=False
328
+ ) as session:
318
329
  # Step 1: GET the auth URI, follow redirects to B2C login page
319
330
  _LOGGER.debug("Fetching B2C login page")
320
331
  try:
@@ -374,6 +385,9 @@ class AuthManager:
374
385
  # re-injected with quoted values on the next request.
375
386
  async with aiohttp.ClientSession(
376
387
  cookie_jar=aiohttp.DummyCookieJar(),
388
+ timeout=self._timeout,
389
+ connector=connector,
390
+ connector_owner=False,
377
391
  ) as raw_session:
378
392
  try:
379
393
  async with raw_session.post(
@@ -9,6 +9,7 @@ from __future__ import annotations
9
9
  from dataclasses import dataclass
10
10
  from typing import Any
11
11
 
12
+ from .const import FROST_TEMPERATURE, MODE_TEMP_MAX, MODE_TEMP_MIN
12
13
  from .models import Appliance, ApplianceStatus, AutomaticProvisioning, ProductModel
13
14
 
14
15
  # Default boost lengths (minutes) offered by the mobile app for most heaters.
@@ -27,18 +28,26 @@ class ApplianceCapabilities:
27
28
 
28
29
  boost: bool = True
29
30
  away: bool = True
31
+ advance: bool = True
30
32
  open_window: bool = True
31
33
  eco_start: bool = True
32
34
  setback_read: bool = True
33
- setback_write: bool = False # no confirmed write API yet
34
- frost: bool = True # TimerMode.FROST_PROTECTION
35
+ setback_write: bool = True # POST /RemoteControl/SetSetbackTemperature
36
+ frost: bool = True # ApplianceModeFlag.FROST_PROTECT (the app's "off")
35
37
  timer: bool = True
38
+ # POST /RemoteControl/SetApplianceSetpointTemperature — the non-destructive
39
+ # setpoint path. Preferred over rewriting the schedule via SetTimerMode,
40
+ # which Quantum rejects with HTTP 403.
41
+ setpoint_write: bool = True
36
42
  energy_meter: bool = False
37
43
  storage: bool = False
38
44
  hot_water: bool = False
45
+ heat_pump: bool = False
46
+ hygiene: bool = False
39
47
  climate: bool = True
40
- min_temp: float = 5.0
41
- max_temp: float = 30.0
48
+ min_temp: float = MODE_TEMP_MIN
49
+ max_temp: float = MODE_TEMP_MAX
50
+ frost_temp: float = FROST_TEMPERATURE
42
51
  default_boost_minutes: int = DEFAULT_BOOST_MINUTES
43
52
  boost_durations: tuple[int, ...] = DEFAULT_BOOST_DURATIONS
44
53
 
@@ -58,18 +67,23 @@ class ApplianceCapabilities:
58
67
  return {
59
68
  "boost": self.boost,
60
69
  "away": self.away,
70
+ "advance": self.advance,
61
71
  "open_window": self.open_window,
62
72
  "eco_start": self.eco_start,
63
73
  "setback_read": self.setback_read,
64
74
  "setback_write": self.setback_write,
65
75
  "frost": self.frost,
66
76
  "timer": self.timer,
77
+ "setpoint_write": self.setpoint_write,
67
78
  "energy_meter": self.energy_meter,
68
79
  "storage": self.storage,
69
80
  "hot_water": self.hot_water,
81
+ "heat_pump": self.heat_pump,
82
+ "hygiene": self.hygiene,
70
83
  "climate": self.climate,
71
84
  "min_temp": self.min_temp,
72
85
  "max_temp": self.max_temp,
86
+ "frost_temp": self.frost_temp,
73
87
  "default_boost_minutes": self.default_boost_minutes,
74
88
  "boost_durations": list(self.boost_durations),
75
89
  "climate_presets": self.climate_presets(),
@@ -125,6 +139,7 @@ def capabilities_for(
125
139
  storage = False
126
140
  energy_meter = False
127
141
  hot_water = False
142
+ heat_pump = False
128
143
  if prov is not None:
129
144
  if prov.charge_capacity is not None and prov.charge_capacity > 0:
130
145
  storage = True
@@ -134,11 +149,15 @@ def capabilities_for(
134
149
  if any(k in tokens for k in ("quantum", "storage", "qrad", "charge")):
135
150
  storage = True
136
151
  energy_meter = True
137
- if any(k in tokens for k in ("hot water", "hotwater", "cylinder", "dhw")):
152
+ if any(k in tokens for k in ("hot water", "hotwater", "cylinder", "dhw", "waterheater")):
153
+ hot_water = True
154
+ if any(k in tokens for k in ("ashw", "heat pump", "heatpump")):
155
+ heat_pump = True
138
156
  hot_water = True
139
157
 
140
158
  boost = True
141
159
  away = True
160
+ advance = True
142
161
  open_window = True
143
162
  eco_start = True
144
163
  setback_read = True
@@ -162,17 +181,26 @@ def capabilities_for(
162
181
  if status.RoomTemperature is not None or status.ActiveSetPointTemperature is not None:
163
182
  climate = True
164
183
 
184
+ # Advance only means something for a scheduled room heater; a cylinder has
185
+ # no "next comfort period" to jump to.
186
+ if hot_water and not climate:
187
+ advance = False
188
+
165
189
  return ApplianceCapabilities(
166
190
  boost=boost,
167
191
  away=away,
192
+ advance=advance,
168
193
  open_window=open_window,
169
194
  eco_start=eco_start,
170
195
  setback_read=setback_read,
171
- setback_write=False,
196
+ setback_write=True,
172
197
  frost=frost,
173
198
  timer=timer,
199
+ setpoint_write=True,
174
200
  energy_meter=energy_meter,
175
201
  storage=storage,
176
202
  hot_water=hot_water,
203
+ heat_pump=heat_pump,
204
+ hygiene=hot_water,
177
205
  climate=climate,
178
206
  )
@@ -18,6 +18,7 @@ import contextlib
18
18
  import json
19
19
  import os
20
20
  import sys
21
+ from collections.abc import Awaitable, Callable
21
22
  from pathlib import Path
22
23
  from typing import Any
23
24
 
@@ -25,7 +26,11 @@ import aiohttp
25
26
 
26
27
  from .auth import TokenBundle
27
28
  from .client import DimplexControl
29
+ from .const import DEFAULT_AWAY_TEMPERATURE, DEFAULT_BOOST_TEMPERATURE
28
30
  from .exceptions import DimplexError
31
+ from .models import SetbackStatus
32
+
33
+ _CoroFactory = Callable[[DimplexControl], Awaitable[int]]
29
34
 
30
35
 
31
36
  def _load_tokens(path: Path | None) -> TokenBundle:
@@ -57,7 +62,7 @@ def _redact(value: str | None, *, show: bool) -> str:
57
62
 
58
63
  async def _with_client(
59
64
  args: argparse.Namespace,
60
- coro_factory: Any,
65
+ coro_factory: _CoroFactory,
61
66
  ) -> int:
62
67
  tokens = _load_tokens(Path(args.tokens_file) if args.tokens_file else None)
63
68
  if not tokens.refresh_token and not tokens.access_token:
@@ -139,7 +144,11 @@ async def cmd_status(client: DimplexControl, args: argparse.Namespace) -> int:
139
144
  print("(no status — appliance offline or empty overview)")
140
145
  return 0
141
146
  status = overview[0]
142
- print(json.dumps(status.model_dump(mode="json"), indent=2, default=str))
147
+ payload = status.model_dump(mode="json")
148
+ # Decoded views the raw payload does not give you.
149
+ payload["_active_modes"] = status.active_modes
150
+ payload["_active_setpoint_temperature"] = status.active_setpoint_temperature
151
+ print(json.dumps(payload, indent=2, default=str))
143
152
  return 0
144
153
 
145
154
 
@@ -177,6 +186,8 @@ async def cmd_away(client: DimplexControl, args: argparse.Namespace) -> int:
177
186
  [args.appliance],
178
187
  temperature=args.temperature,
179
188
  enable=not args.clear,
189
+ until=args.until,
190
+ number_of_days=args.days,
180
191
  )
181
192
  print("ok")
182
193
  return 0
@@ -191,6 +202,54 @@ async def cmd_eco(client: DimplexControl, args: argparse.Namespace) -> int:
191
202
  return 0
192
203
 
193
204
 
205
+ async def cmd_setpoint(client: DimplexControl, args: argparse.Namespace) -> int:
206
+ """Set the active setpoint via the dedicated (non-destructive) endpoint."""
207
+ if not args.yes:
208
+ print("error: control commands require --yes", file=sys.stderr)
209
+ return 2
210
+ await client.set_appliance_setpoint_temperature(args.hub, [args.appliance], args.temperature)
211
+ print("ok")
212
+ return 0
213
+
214
+
215
+ async def cmd_off(client: DimplexControl, args: argparse.Namespace) -> int:
216
+ """Turn the appliance off the way the app does — frost protection at 7 °C."""
217
+ if not args.yes:
218
+ print("error: control commands require --yes", file=sys.stderr)
219
+ return 2
220
+ await client.set_frost_protect(args.hub, [args.appliance], enable=not args.clear)
221
+ print("ok")
222
+ return 0
223
+
224
+
225
+ async def cmd_advance(client: DimplexControl, args: argparse.Namespace) -> int:
226
+ if not args.yes:
227
+ print("error: control commands require --yes", file=sys.stderr)
228
+ return 2
229
+ await client.set_advance(
230
+ args.hub,
231
+ [args.appliance],
232
+ enable=not args.clear,
233
+ temperature=args.temperature,
234
+ )
235
+ print("ok")
236
+ return 0
237
+
238
+
239
+ async def cmd_setback(client: DimplexControl, args: argparse.Namespace) -> int:
240
+ if not args.yes:
241
+ print("error: control commands require --yes", file=sys.stderr)
242
+ return 2
243
+ await client.set_setback_temperature(
244
+ args.hub,
245
+ [args.appliance],
246
+ temperature=args.temperature,
247
+ status=SetbackStatus.INACTIVE if args.clear else SetbackStatus.ACTIVE,
248
+ )
249
+ print("ok")
250
+ return 0
251
+
252
+
194
253
  def build_parser() -> argparse.ArgumentParser:
195
254
  parser = argparse.ArgumentParser(
196
255
  prog="dimplex",
@@ -233,21 +292,54 @@ def build_parser() -> argparse.ArgumentParser:
233
292
  p_energy.add_argument("--days", type=int, default=30)
234
293
  p_energy.set_defaults(func=cmd_energy)
235
294
 
236
- for name, help_text, defaults in (
237
- ("boost", "Enable or clear boost (--yes required)", {"minutes": 60, "temperature": 25.0}),
238
- ("away", "Enable or clear away (--yes required)", {"temperature": 16.0}),
295
+ _CONTROL_COMMANDS: dict[str, Callable[..., Awaitable[int]]] = {
296
+ "boost": cmd_boost,
297
+ "away": cmd_away,
298
+ "eco": cmd_eco,
299
+ "setpoint": cmd_setpoint,
300
+ "off": cmd_off,
301
+ "advance": cmd_advance,
302
+ "setback": cmd_setback,
303
+ }
304
+
305
+ for name, help_text, opts in (
306
+ (
307
+ "boost",
308
+ "Enable or clear timed Boost (--yes required)",
309
+ {"temperature": DEFAULT_BOOST_TEMPERATURE, "minutes": 60},
310
+ ),
311
+ (
312
+ "away",
313
+ "Enable or clear Away setback, 7-30 °C (--yes required)",
314
+ {"temperature": DEFAULT_AWAY_TEMPERATURE, "away_until": True},
315
+ ),
239
316
  ("eco", "Enable or clear EcoStart (--yes required)", {}),
317
+ (
318
+ "setpoint",
319
+ "Set the active setpoint, non-destructive (--yes required)",
320
+ {"temperature": 21.0},
321
+ ),
322
+ ("off", "Turn off via frost protection at 7 °C (--yes required)", {}),
323
+ ("advance", "Advance to the next schedule period (--yes required)", {"temperature": None}),
324
+ (
325
+ "setback",
326
+ "Write the setback temperature (--yes required; untested)",
327
+ {"temperature": 16.0},
328
+ ),
240
329
  ):
241
330
  p = sub.add_parser(name, help=help_text)
242
331
  p.add_argument("hub")
243
332
  p.add_argument("appliance")
244
333
  p.add_argument("--yes", action="store_true", help="Confirm control write")
245
334
  p.add_argument("--clear", action="store_true", help="Disable the mode")
246
- if "temperature" in defaults:
247
- p.add_argument("--temperature", type=float, default=defaults["temperature"])
248
- if "minutes" in defaults:
249
- p.add_argument("--minutes", type=int, default=defaults["minutes"])
250
- p.set_defaults(func={"boost": cmd_boost, "away": cmd_away, "eco": cmd_eco}[name])
335
+ if "temperature" in opts:
336
+ p.add_argument("--temperature", type=float, default=opts["temperature"])
337
+ if "minutes" in opts:
338
+ p.add_argument("--minutes", type=int, default=opts["minutes"])
339
+ if opts.get("away_until"):
340
+ p.add_argument("--days", type=int, default=0, help="Away duration in days (converted to a date)")
341
+ p.add_argument("--until", help="Away-until datetime, ISO-8601 (overrides --days)")
342
+ p.set_defaults(func=_CONTROL_COMMANDS[name])
251
343
 
252
344
  return parser
253
345
 
@@ -257,7 +349,8 @@ def main(argv: list[str] | None = None) -> int:
257
349
  args = parser.parse_args(argv)
258
350
 
259
351
  async def run(client: DimplexControl) -> int:
260
- return await args.func(client, args)
352
+ func: Callable[..., Awaitable[int]] = args.func
353
+ return await func(client, args)
261
354
 
262
355
  return asyncio.run(_with_client(args, run))
263
356