-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathopentherm_app.py
More file actions
695 lines (544 loc) · 24.5 KB
/
opentherm_app.py
File metadata and controls
695 lines (544 loc) · 24.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
import asyncio
from lib import s8, s16, f88, send_syslog
try:
from opentherm_rp2 import opentherm_exchange
except ImportError:
# dummy implementation so it loads on non-pico for unit tests
async def opentherm_exchange(msg_type: int, data_id: int, data_value: int, timeout_ms: int = 1000) -> tuple[int, int, int]:
raise NotImplementedError("await opentherm_exchange not implemented on this platform") # pragma: nocover
MSG_TYPE_READ_DATA = 0
MSG_TYPE_WRITE_DATA = 1
MSG_TYPE_INVALID_DATA = 2
MSG_TYPE_READ_ACK = 4
MSG_TYPE_WRITE_ACK = 5
MSG_TYPE_DATA_INVALID = 6
MSG_TYPE_UNKNOWN_DATA_ID = 7
DATA_ID_STATUS = 0
DATA_ID_TSET = 1
DATA_ID_PRIMARY_CONFIG = 2
DATA_ID_SECONDARY_CONFIG = 3
DATA_ID_COMMAND = 4
DATA_ID_ASF_FAULT = 5
DATA_ID_RBP_FLAGS = 6
DATA_ID_COOLING_CONTROL = 7
DATA_ID_TSETCH2 = 8
DATA_ID_TROVERRIDE = 9
DATA_ID_TSP_COUNT = 10
DATA_ID_TSP_DATA = 11
DATA_ID_FHB_COUNT = 12
DATA_ID_FHB_DATA = 13
DATA_ID_MAX_REL_MODULATION = 14
DATA_ID_MAX_CAPACITY_MIN_MODULATION = 15
DATA_ID_TRSET = 16
DATA_ID_REL_MOD_LEVEL = 17
DATA_ID_CH_PRESSURE = 18
DATA_ID_DHW_FLOW_RATE = 19
DATA_ID_DAY_TIME = 20
DATA_ID_DATE = 21
DATA_ID_YEAR = 22
DATA_ID_TRSETCH2 = 23
DATA_ID_TR = 24
DATA_ID_TBOILER = 25
DATA_ID_TDHW = 26
DATA_ID_TOUTSIDE = 27
DATA_ID_TRET = 28
DATA_ID_TSTORAGE = 29
DATA_ID_TCOLLECTOR = 30
DATA_ID_TFLOWCH2 = 31
DATA_ID_TDHW2 = 32
DATA_ID_TEXHAUST = 33
# ID 35 not in OT v2.2 but defined in v4.2 spec section 5.3.3:
# HB: fan speed setpoint in Hz (RPM/60), LB: actual fan speed in Hz (RPM/60)
DATA_ID_BOILER_FAN_SPEED = 35
DATA_ID_TDHWSET_BOUNDS = 48
DATA_ID_MAXTSET_BOUNDS = 49
DATA_ID_HCRATIO_BOUNDS = 50
DATA_ID_TDHWSET = 56
DATA_ID_MAXTSET = 57
DATA_ID_HCRATIO = 58
DATA_ID_REMOTE_OVERRIDE_FUNCTION = 100
DATA_ID_OEM_DIAGNOSTIC_CODE = 115
DATA_ID_POWER_CYCLES = 97
DATA_ID_BURNER_STARTS = 116
DATA_ID_CH_PUMP_STARTS = 117
DATA_ID_DHW_PUMP_STARTS = 118
DATA_ID_DHW_BURNER_STARTS = 119
DATA_ID_BURNER_OPERATION_HOURS = 120
DATA_ID_CH_PUMP_OPERATION_HOURS = 121
DATA_ID_DHW_PUMP_OPERATION_HOURS = 122
DATA_ID_DHW_BURNER_OPERATION_HOURS = 123
DATA_ID_OPENTHERM_VERSION_PRIMARY = 124
DATA_ID_OPENTHERM_VERSION_SECONDARY = 125
DATA_ID_PRIMARY_VERSION = 126
DATA_ID_SECONDARY_VERSION = 127
REMOTE_COMAND_BLOR = 1 # boiler lock out reset command
REMOTE_COMAND_CHWF = 2 # CH water filling command
# Custom exceptions for OpenTherm protocol responses
class DataInvalidError(Exception):
"""Raised when the boiler responds with DATA-INVALID (msg_type=6).
This indicates the data ID is recognized but the data is unavailable or invalid."""
pass
class UnknownDataIdError(Exception):
"""Raised when the boiler responds with UNKNOWN-DATAID (msg_type=7).
This indicates the boiler does not support or recognize this data ID."""
pass
async def opentherm_exchange_retry(msg_type: int, data_id: int, data_value: int, timeout_ms: int = 1000, max_retries: int = 10):
"""Attempt an OpenTherm exchange with retry logic.
OT spec 4.3.1: master must wait 100ms minimum between conversations.
The inter-message delay is applied after each exchange completes.
"""
retry_count = 0
while True:
try:
result = await opentherm_exchange(msg_type, data_id, data_value, timeout_ms)
# OT spec 4.3.1: 100ms minimum gap after conversation ends
await asyncio.sleep_ms(100)
return result
except (DataInvalidError, UnknownDataIdError):
# Valid protocol responses per OT spec 4.4.1/4.4.2 - do not retry
await asyncio.sleep_ms(100)
raise
except Exception:
# OT spec 4.3.1: 100ms gap even after failed conversation
await asyncio.sleep_ms(100)
if retry_count >= max_retries:
raise
retry_count += 1
def _check_response_type(r_msg_type: int, expected_type: int, r_data_id: int, expected_data_id: int):
"""Check response message type and data ID, raising appropriate exceptions for errors.
Per OpenTherm spec sections 4.4.1/4.4.2, DATA-INVALID and UNKNOWN-DATAID are
valid protocol responses that should not be retried.
Args:
r_msg_type: Received message type from boiler
expected_type: Expected message type (e.g., MSG_TYPE_READ_ACK)
r_data_id: Received data ID from boiler
expected_data_id: Expected data ID that was requested
"""
if r_msg_type == MSG_TYPE_DATA_INVALID:
raise DataInvalidError(f"Boiler returned DATA-INVALID for data ID {expected_data_id}")
elif r_msg_type == MSG_TYPE_UNKNOWN_DATA_ID:
raise UnknownDataIdError(f"Boiler does not support data ID {expected_data_id}")
if r_msg_type != expected_type:
msg = f"Expected msg_type {expected_type}, got {r_msg_type} for data ID {expected_data_id}"
send_syslog(f"ERROR: {msg}")
raise ValueError(msg)
if r_data_id != expected_data_id:
msg = f"Expected data_id {expected_data_id}, got {r_data_id}"
send_syslog(f"ERROR: {msg}")
raise ValueError(msg)
async def status_exchange(
ch_enabled=False,
dhw_enabled=False,
cooling_enabled=False,
otc_enabled=False,
ch2_enabled=False,
) -> dict:
data = 0
data |= 0x0100 if ch_enabled else 0
data |= 0x0200 if dhw_enabled else 0
data |= 0x0400 if cooling_enabled else 0
data |= 0x0800 if otc_enabled else 0
data |= 0x1000 if ch2_enabled else 0
r_msg_type, r_data_id, r_data = await opentherm_exchange_retry(
MSG_TYPE_READ_DATA, DATA_ID_STATUS, data
)
_check_response_type(r_msg_type, MSG_TYPE_READ_ACK, r_data_id, DATA_ID_STATUS)
result = dict(
fault=True if r_data & 0x01 else False,
ch_active=True if r_data & 0x02 else False,
dhw_active=True if r_data & 0x04 else False,
flame_active=True if r_data & 0x08 else False,
cooling_active=True if r_data & 0x10 else False,
ch2_active=True if r_data & 0x20 else False,
diagnostic_event=True if r_data & 0x40 else False,
)
return result
async def send_primary_configuration(memberid_code: int):
r_msg_type, r_data_id, r_data = await opentherm_exchange_retry(
MSG_TYPE_WRITE_DATA, DATA_ID_PRIMARY_CONFIG, memberid_code & 0xFF
)
_check_response_type(r_msg_type, MSG_TYPE_WRITE_ACK, r_data_id, DATA_ID_PRIMARY_CONFIG)
async def send_primary_opentherm_version(version: float):
r_msg_type, r_data_id, r_data = await opentherm_exchange_retry(
MSG_TYPE_WRITE_DATA, DATA_ID_OPENTHERM_VERSION_PRIMARY, int(version * 256)
)
_check_response_type(r_msg_type, MSG_TYPE_WRITE_ACK, r_data_id, DATA_ID_OPENTHERM_VERSION_PRIMARY)
async def send_primary_product_version(type: int, version: int):
r_msg_type, r_data_id, r_data = await opentherm_exchange_retry(
MSG_TYPE_WRITE_DATA, DATA_ID_PRIMARY_VERSION, ((type & 0xff) << 8) | (version & 0xff)
)
_check_response_type(r_msg_type, MSG_TYPE_WRITE_ACK, r_data_id, DATA_ID_PRIMARY_VERSION)
async def read_secondary_configuration() -> dict:
r_msg_type, r_data_id, r_data = await opentherm_exchange_retry(
MSG_TYPE_READ_DATA, DATA_ID_SECONDARY_CONFIG, 0
)
_check_response_type(r_msg_type, MSG_TYPE_READ_ACK, r_data_id, DATA_ID_SECONDARY_CONFIG)
result = dict(
dhw_present=True if r_data & 0x0100 else False,
control_type="onoff" if r_data & 0x0200 else "modulating",
cooling_config=True if r_data & 0x0400 else False,
dhw_config="storage" if r_data & 0x0800 else "instantaneous",
low_off_and_pump_control=True if not (r_data & 0x1000) else False,
ch2_supported=True if r_data & 0x2000 else False,
memberid_code=r_data & 0xFF,
)
return result
async def read_secondary_opentherm_version() -> float:
r_msg_type, r_data_id, r_data = await opentherm_exchange_retry(
MSG_TYPE_READ_DATA, DATA_ID_OPENTHERM_VERSION_SECONDARY, 0
)
_check_response_type(r_msg_type, MSG_TYPE_READ_ACK, r_data_id, DATA_ID_OPENTHERM_VERSION_SECONDARY)
return f88(r_data)
async def read_secondary_product_version() -> tuple[int, int]:
r_msg_type, r_data_id, r_data = await opentherm_exchange_retry(
MSG_TYPE_READ_DATA, DATA_ID_SECONDARY_VERSION, 0
)
_check_response_type(r_msg_type, MSG_TYPE_READ_ACK, r_data_id, DATA_ID_SECONDARY_VERSION)
return r_data >> 8, r_data & 0xff
async def control_ch_setpoint(setpoint: float):
if not (setpoint >= 0 and setpoint <= 100):
msg = f"Invalid CH setpoint {setpoint}, must be 0-100"
send_syslog(f"ERROR: {msg}")
raise ValueError(msg)
r_msg_type, r_data_id, r_data = await opentherm_exchange_retry(
MSG_TYPE_WRITE_DATA, DATA_ID_TSET, int(setpoint * 256)
)
_check_response_type(r_msg_type, MSG_TYPE_WRITE_ACK, r_data_id, DATA_ID_TSET)
async def read_ch_setpoint() -> float:
r_msg_type, r_data_id, r_data = await opentherm_exchange_retry(
MSG_TYPE_READ_DATA, DATA_ID_TSET, 0
)
_check_response_type(r_msg_type, MSG_TYPE_READ_ACK, r_data_id, DATA_ID_TSET)
return f88(r_data)
async def control_ch2_setpoint(setpoint: float):
if not (setpoint >= 0 and setpoint <= 100):
msg = f"Invalid CH2 setpoint {setpoint}, must be 0-100"
send_syslog(f"ERROR: {msg}")
raise ValueError(msg)
r_msg_type, r_data_id, r_data = await opentherm_exchange_retry(
MSG_TYPE_WRITE_DATA, DATA_ID_TSETCH2, int(setpoint * 256)
)
_check_response_type(r_msg_type, MSG_TYPE_WRITE_ACK, r_data_id, DATA_ID_TSETCH2)
async def read_dhw_setpoint_range() -> tuple[int, int]:
r_msg_type, r_data_id, r_data = await opentherm_exchange_retry(
MSG_TYPE_READ_DATA, DATA_ID_TDHWSET_BOUNDS, 0
)
_check_response_type(r_msg_type, MSG_TYPE_READ_ACK, r_data_id, DATA_ID_TDHWSET_BOUNDS)
return s8(r_data & 0xFF), s8(r_data >> 8)
async def control_dhw_setpoint(setpoint: float):
if not (setpoint >= 0 and setpoint <= 100):
msg = f"Invalid DHW setpoint {setpoint}, must be 0-100"
send_syslog(f"ERROR: {msg}")
raise ValueError(msg)
r_msg_type, r_data_id, r_data = await opentherm_exchange_retry(
MSG_TYPE_WRITE_DATA, DATA_ID_TDHWSET, int(setpoint * 256)
)
_check_response_type(r_msg_type, MSG_TYPE_WRITE_ACK, r_data_id, DATA_ID_TDHWSET)
async def read_dhw_setpoint() -> float:
r_msg_type, r_data_id, r_data = await opentherm_exchange_retry(
MSG_TYPE_READ_DATA, DATA_ID_TDHWSET, 0
)
_check_response_type(r_msg_type, MSG_TYPE_READ_ACK, r_data_id, DATA_ID_TDHWSET)
return f88(r_data)
async def control_room_setpoint(setpoint: float):
if not (setpoint >= -40 and setpoint <= 127):
msg = f"Invalid room setpoint {setpoint}, must be -40 to 127"
send_syslog(f"ERROR: {msg}")
raise ValueError(msg)
r_msg_type, r_data_id, r_data = await opentherm_exchange_retry(
MSG_TYPE_WRITE_DATA, DATA_ID_TRSET, int(setpoint * 256)
)
_check_response_type(r_msg_type, MSG_TYPE_WRITE_ACK, r_data_id, DATA_ID_TRSET)
async def read_room_setpoint() -> float:
r_msg_type, r_data_id, r_data = await opentherm_exchange_retry(
MSG_TYPE_READ_DATA, DATA_ID_TRSET, 0
)
_check_response_type(r_msg_type, MSG_TYPE_READ_ACK, r_data_id, DATA_ID_TRSET)
return f88(r_data)
async def control_room_setpoint_ch2(setpoint: float):
if not (setpoint >= -40 and setpoint <= 127):
msg = f"Invalid room setpoint CH2 {setpoint}, must be -40 to 127"
send_syslog(f"ERROR: {msg}")
raise ValueError(msg)
r_msg_type, r_data_id, r_data = await opentherm_exchange_retry(
MSG_TYPE_WRITE_DATA, DATA_ID_TRSETCH2, int(setpoint * 256)
)
_check_response_type(r_msg_type, MSG_TYPE_WRITE_ACK, r_data_id, DATA_ID_TRSETCH2)
async def control_room_temperature(setpoint: float):
if not (setpoint >= -40 and setpoint <= 127):
msg = f"Invalid room temperature {setpoint}, must be -40 to 127"
send_syslog(f"ERROR: {msg}")
raise ValueError(msg)
r_msg_type, r_data_id, r_data = await opentherm_exchange_retry(
MSG_TYPE_WRITE_DATA, DATA_ID_TR, int(setpoint * 256)
)
_check_response_type(r_msg_type, MSG_TYPE_WRITE_ACK, r_data_id, DATA_ID_TR)
async def read_room_temperature() -> float:
r_msg_type, r_data_id, r_data = await opentherm_exchange_retry(
MSG_TYPE_READ_DATA, DATA_ID_TR, 0
)
_check_response_type(r_msg_type, MSG_TYPE_READ_ACK, r_data_id, DATA_ID_TR)
return f88(r_data)
async def control_cooling(signal: float):
if not (signal >= 0 and signal <= 100):
msg = f"Invalid cooling signal {signal}, must be 0-100"
send_syslog(f"ERROR: {msg}")
raise ValueError(msg)
r_msg_type, r_data_id, r_data = await opentherm_exchange_retry(
MSG_TYPE_WRITE_DATA, DATA_ID_COOLING_CONTROL, int(signal * 256)
)
_check_response_type(r_msg_type, MSG_TYPE_WRITE_ACK, r_data_id, DATA_ID_COOLING_CONTROL)
async def read_maxch_setpoint_range() -> tuple[int, int]:
r_msg_type, r_data_id, r_data = await opentherm_exchange_retry(
MSG_TYPE_READ_DATA, DATA_ID_MAXTSET_BOUNDS, 0
)
_check_response_type(r_msg_type, MSG_TYPE_READ_ACK, r_data_id, DATA_ID_MAXTSET_BOUNDS)
return s8(r_data & 0xFF), s8(r_data >> 8)
async def control_maxch_setpoint(setpoint: float):
if not (setpoint >= 0 and setpoint <= 100):
msg = f"Invalid max CH setpoint {setpoint}, must be 0-100"
send_syslog(f"ERROR: {msg}")
raise ValueError(msg)
r_msg_type, r_data_id, r_data = await opentherm_exchange_retry(
MSG_TYPE_WRITE_DATA, DATA_ID_MAXTSET, int(setpoint * 256)
)
_check_response_type(r_msg_type, MSG_TYPE_WRITE_ACK, r_data_id, DATA_ID_MAXTSET)
async def read_maxch_setpoint() -> float:
r_msg_type, r_data_id, r_data = await opentherm_exchange_retry(
MSG_TYPE_READ_DATA, DATA_ID_MAXTSET, 0
)
_check_response_type(r_msg_type, MSG_TYPE_READ_ACK, r_data_id, DATA_ID_MAXTSET)
return f88(r_data)
async def read_extra_boiler_params_support() -> dict:
r_msg_type, r_data_id, r_data = await opentherm_exchange_retry(
MSG_TYPE_READ_DATA, DATA_ID_RBP_FLAGS, 0
)
_check_response_type(r_msg_type, MSG_TYPE_READ_ACK, r_data_id, DATA_ID_RBP_FLAGS)
dhw_setpoint = None
if r_data & 0x0100:
if r_data & 0x01:
dhw_setpoint = "rw"
else:
dhw_setpoint = "ro"
maxch_setpoint = None
if r_data & 0x200:
if r_data & 0x02:
maxch_setpoint = "rw"
else:
maxch_setpoint = "ro"
result = dict(dhw_setpoint=dhw_setpoint, maxch_setpoint=maxch_setpoint)
return result
async def read_fault_flags() -> dict:
r_msg_type, r_data_id, r_data = await opentherm_exchange_retry(
MSG_TYPE_READ_DATA, DATA_ID_ASF_FAULT, 0
)
_check_response_type(r_msg_type, MSG_TYPE_READ_ACK, r_data_id, DATA_ID_ASF_FAULT)
result = dict(
service_required=True if r_data & 0x0100 else False,
blor_enabled=True if r_data & 0x0200 else False,
low_water_pressure=True if r_data & 0x0400 else False,
flame_fault=True if r_data & 0x0800 else False,
air_pressure_fault=True if r_data & 0x1000 else False,
water_over_temp=True if r_data & 0x2000 else False,
oem_code=r_data & 0xFF,
)
return result
async def read_oem_long_code() -> int:
r_msg_type, r_data_id, r_data = await opentherm_exchange_retry(
MSG_TYPE_READ_DATA, DATA_ID_OEM_DIAGNOSTIC_CODE, 0
)
_check_response_type(r_msg_type, MSG_TYPE_READ_ACK, r_data_id, DATA_ID_OEM_DIAGNOSTIC_CODE)
return r_data
async def read_relative_modulation_level() -> float:
r_msg_type, r_data_id, r_data = await opentherm_exchange_retry(
MSG_TYPE_READ_DATA, DATA_ID_REL_MOD_LEVEL, 0
)
_check_response_type(r_msg_type, MSG_TYPE_READ_ACK, r_data_id, DATA_ID_REL_MOD_LEVEL)
return f88(r_data)
async def read_ch_water_pressure() -> float:
r_msg_type, r_data_id, r_data = await opentherm_exchange_retry(
MSG_TYPE_READ_DATA, DATA_ID_CH_PRESSURE, 0
)
_check_response_type(r_msg_type, MSG_TYPE_READ_ACK, r_data_id, DATA_ID_CH_PRESSURE)
return f88(r_data)
async def read_dhw_flow_rate() -> float:
r_msg_type, r_data_id, r_data = await opentherm_exchange_retry(
MSG_TYPE_READ_DATA, DATA_ID_DHW_FLOW_RATE, 0
)
_check_response_type(r_msg_type, MSG_TYPE_READ_ACK, r_data_id, DATA_ID_DHW_FLOW_RATE)
return f88(r_data)
async def read_boiler_flow_temperature() -> float:
r_msg_type, r_data_id, r_data = await opentherm_exchange_retry(
MSG_TYPE_READ_DATA, DATA_ID_TBOILER, 0
)
_check_response_type(r_msg_type, MSG_TYPE_READ_ACK, r_data_id, DATA_ID_TBOILER)
return f88(r_data)
async def read_boiler_flow_temperature_ch2() -> float:
r_msg_type, r_data_id, r_data = await opentherm_exchange_retry(
MSG_TYPE_READ_DATA, DATA_ID_TFLOWCH2, 0
)
_check_response_type(r_msg_type, MSG_TYPE_READ_ACK, r_data_id, DATA_ID_TFLOWCH2)
return f88(r_data)
async def read_dhw_temperature() -> float:
r_msg_type, r_data_id, r_data = await opentherm_exchange_retry(
MSG_TYPE_READ_DATA, DATA_ID_TDHW, 0
)
_check_response_type(r_msg_type, MSG_TYPE_READ_ACK, r_data_id, DATA_ID_TDHW)
return f88(r_data)
async def read_dhw2_temperature() -> float:
r_msg_type, r_data_id, r_data = await opentherm_exchange_retry(
MSG_TYPE_READ_DATA, DATA_ID_TDHW2, 0
)
_check_response_type(r_msg_type, MSG_TYPE_READ_ACK, r_data_id, DATA_ID_TDHW2)
return f88(r_data)
async def read_exhaust_temperature() -> float:
r_msg_type, r_data_id, r_data = await opentherm_exchange_retry(
MSG_TYPE_READ_DATA, DATA_ID_TEXHAUST, 0
)
_check_response_type(r_msg_type, MSG_TYPE_READ_ACK, r_data_id, DATA_ID_TEXHAUST)
return s16(r_data)
async def read_fan_speed() -> float:
r_msg_type, r_data_id, r_data = await opentherm_exchange_retry(
MSG_TYPE_READ_DATA, DATA_ID_BOILER_FAN_SPEED, 0
)
_check_response_type(r_msg_type, MSG_TYPE_READ_ACK, r_data_id, DATA_ID_BOILER_FAN_SPEED)
return (r_data & 0xff) * 60
async def read_outside_temperature() -> float:
r_msg_type, r_data_id, r_data = await opentherm_exchange_retry(
MSG_TYPE_READ_DATA, DATA_ID_TOUTSIDE, 0
)
_check_response_type(r_msg_type, MSG_TYPE_READ_ACK, r_data_id, DATA_ID_TOUTSIDE)
return f88(r_data)
async def read_boiler_return_water_temperature() -> float:
r_msg_type, r_data_id, r_data = await opentherm_exchange_retry(
MSG_TYPE_READ_DATA, DATA_ID_TRET, 0
)
_check_response_type(r_msg_type, MSG_TYPE_READ_ACK, r_data_id, DATA_ID_TRET)
return f88(r_data)
async def read_power_cycles() -> int:
r_msg_type, r_data_id, r_data = await opentherm_exchange_retry(
MSG_TYPE_READ_DATA, DATA_ID_POWER_CYCLES, 0
)
_check_response_type(r_msg_type, MSG_TYPE_READ_ACK, r_data_id, DATA_ID_POWER_CYCLES)
return r_data
async def read_burner_starts() -> int:
r_msg_type, r_data_id, r_data = await opentherm_exchange_retry(
MSG_TYPE_READ_DATA, DATA_ID_BURNER_STARTS, 0
)
_check_response_type(r_msg_type, MSG_TYPE_READ_ACK, r_data_id, DATA_ID_BURNER_STARTS)
return r_data
async def read_ch_pump_starts() -> int:
r_msg_type, r_data_id, r_data = await opentherm_exchange_retry(
MSG_TYPE_READ_DATA, DATA_ID_CH_PUMP_STARTS, 0
)
_check_response_type(r_msg_type, MSG_TYPE_READ_ACK, r_data_id, DATA_ID_CH_PUMP_STARTS)
return r_data
async def read_dhw_pump_starts() -> int:
r_msg_type, r_data_id, r_data = await opentherm_exchange_retry(
MSG_TYPE_READ_DATA, DATA_ID_DHW_PUMP_STARTS, 0
)
_check_response_type(r_msg_type, MSG_TYPE_READ_ACK, r_data_id, DATA_ID_DHW_PUMP_STARTS)
return r_data
async def read_dhw_burner_starts() -> int:
r_msg_type, r_data_id, r_data = await opentherm_exchange_retry(
MSG_TYPE_READ_DATA, DATA_ID_DHW_BURNER_STARTS, 0
)
_check_response_type(r_msg_type, MSG_TYPE_READ_ACK, r_data_id, DATA_ID_DHW_BURNER_STARTS)
return r_data
async def read_burner_operation_hours() -> int:
r_msg_type, r_data_id, r_data = await opentherm_exchange_retry(
MSG_TYPE_READ_DATA, DATA_ID_BURNER_OPERATION_HOURS, 0
)
_check_response_type(r_msg_type, MSG_TYPE_READ_ACK, r_data_id, DATA_ID_BURNER_OPERATION_HOURS)
return r_data
async def read_ch_pump_operation_hours() -> int:
r_msg_type, r_data_id, r_data = await opentherm_exchange_retry(
MSG_TYPE_READ_DATA, DATA_ID_CH_PUMP_OPERATION_HOURS, 0
)
_check_response_type(r_msg_type, MSG_TYPE_READ_ACK, r_data_id, DATA_ID_CH_PUMP_OPERATION_HOURS)
return r_data
async def read_dhw_pump_operation_hours() -> int:
r_msg_type, r_data_id, r_data = await opentherm_exchange_retry(
MSG_TYPE_READ_DATA, DATA_ID_DHW_PUMP_OPERATION_HOURS, 0
)
_check_response_type(r_msg_type, MSG_TYPE_READ_ACK, r_data_id, DATA_ID_DHW_PUMP_OPERATION_HOURS)
return r_data
async def read_dhw_burner_operation_hours() -> int:
r_msg_type, r_data_id, r_data = await opentherm_exchange_retry(
MSG_TYPE_READ_DATA, DATA_ID_DHW_BURNER_OPERATION_HOURS, 0
)
_check_response_type(r_msg_type, MSG_TYPE_READ_ACK, r_data_id, DATA_ID_DHW_BURNER_OPERATION_HOURS)
return r_data
async def read_tsp_count() -> int:
r_msg_type, r_data_id, r_data = await opentherm_exchange_retry(
MSG_TYPE_READ_DATA, DATA_ID_TSP_COUNT, 0
)
_check_response_type(r_msg_type, MSG_TYPE_READ_ACK, r_data_id, DATA_ID_TSP_COUNT)
return r_data >> 8
async def read_tsp(index: int) -> int:
r_msg_type, r_data_id, r_data = await opentherm_exchange_retry(
MSG_TYPE_READ_DATA, DATA_ID_TSP_DATA, (index << 8)
)
_check_response_type(r_msg_type, MSG_TYPE_READ_ACK, r_data_id, DATA_ID_TSP_DATA)
if r_data >> 8 != index:
msg = f"TSP index mismatch: expected {index}, got {r_data >> 8}"
send_syslog(f"ERROR: {msg}")
raise ValueError(msg)
return r_data & 0xff
async def read_fhb_count() -> int:
r_msg_type, r_data_id, r_data = await opentherm_exchange_retry(
MSG_TYPE_READ_DATA, DATA_ID_FHB_COUNT, 0
)
_check_response_type(r_msg_type, MSG_TYPE_READ_ACK, r_data_id, DATA_ID_FHB_COUNT)
return r_data >> 8
async def read_fhb(index: int) -> int:
r_msg_type, r_data_id, r_data = await opentherm_exchange_retry(
MSG_TYPE_READ_DATA, DATA_ID_FHB_DATA, (index << 8)
)
_check_response_type(r_msg_type, MSG_TYPE_READ_ACK, r_data_id, DATA_ID_FHB_DATA)
if r_data >> 8 != index:
msg = f"FHB index mismatch: expected {index}, got {r_data >> 8}"
send_syslog(f"ERROR: {msg}")
raise ValueError(msg)
return r_data & 0xff
async def control_remote_command(command: int):
r_msg_type, r_data_id, r_data = await opentherm_exchange_retry(
MSG_TYPE_WRITE_DATA, DATA_ID_COMMAND, command << 8
)
_check_response_type(r_msg_type, MSG_TYPE_WRITE_ACK, r_data_id, DATA_ID_COMMAND)
if r_data >> 8 != command:
msg = f"Remote command mismatch: expected {command}, got {r_data >> 8}"
send_syslog(f"ERROR: {msg}")
raise ValueError(msg)
return r_data & 0xff
async def read_remote_override_room_setpoint():
r_msg_type, r_data_id, r_data = await opentherm_exchange_retry(
MSG_TYPE_READ_DATA, DATA_ID_TROVERRIDE, 0
)
_check_response_type(r_msg_type, MSG_TYPE_READ_ACK, r_data_id, DATA_ID_TROVERRIDE)
return f88(r_data)
async def read_remote_override_function():
r_msg_type, r_data_id, r_data = await opentherm_exchange_retry(
MSG_TYPE_READ_DATA, DATA_ID_REMOTE_OVERRIDE_FUNCTION, 0
)
_check_response_type(r_msg_type, MSG_TYPE_READ_ACK, r_data_id, DATA_ID_REMOTE_OVERRIDE_FUNCTION)
result = dict(manual_change_priority=True if r_data & 0x01 else False,
program_change_priority=True if r_data & 0x02 else False)
return result
async def read_capacity_and_min_modulation():
r_msg_type, r_data_id, r_data = await opentherm_exchange_retry(
MSG_TYPE_READ_DATA, DATA_ID_MAX_CAPACITY_MIN_MODULATION, 0
)
_check_response_type(r_msg_type, MSG_TYPE_READ_ACK, r_data_id, DATA_ID_MAX_CAPACITY_MIN_MODULATION)
return r_data >> 8, r_data & 0xff
async def control_max_relative_modulation_level(l: float):
r_msg_type, r_data_id, r_data = await opentherm_exchange_retry(
MSG_TYPE_WRITE_DATA, DATA_ID_MAX_REL_MODULATION, int(l * 256)
)
_check_response_type(r_msg_type, MSG_TYPE_WRITE_ACK, r_data_id, DATA_ID_MAX_REL_MODULATION)
async def read_max_relative_modulation_level() -> float:
r_msg_type, r_data_id, r_data = await opentherm_exchange_retry(
MSG_TYPE_READ_DATA, DATA_ID_MAX_REL_MODULATION, 0
)
_check_response_type(r_msg_type, MSG_TYPE_READ_ACK, r_data_id, DATA_ID_MAX_REL_MODULATION)
return f88(r_data)