forked from Bouni/python-luxtronik
-
Notifications
You must be signed in to change notification settings - Fork 0
/
datatypes.py
executable file
·651 lines (469 loc) · 14.7 KB
/
datatypes.py
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
"""datatype conversions."""
import datetime
import socket
import struct
from functools import total_ordering
@total_ordering
class Base:
"""Base datatype, no conversions."""
datatype_class = None
datatype_unit = None
def __init__(self, name, writeable=False):
"""Initialize the base data field class. Set the initial raw value to None"""
# save the raw value only since the user value
# could be build at any time
self._raw = None
self.name = name
self.writeable = writeable
@classmethod
def to_heatpump(cls, value):
"""Converts value into heatpump units."""
return value
@classmethod
def from_heatpump(cls, value):
"""Converts value from heatpump units."""
return value
@property
def value(self):
"""Return the stored value converted from heatpump units."""
return self.from_heatpump(self._raw)
@value.setter
def value(self, value):
"""Converts the value into heatpump units and store it."""
self._raw = self.to_heatpump(value)
@property
def raw(self):
"""Return the stored raw data."""
return self._raw
@raw.setter
def raw(self, raw):
"""Store the raw data."""
self._raw = raw
def __repr__(self):
"""Returns a printable representation of the datatype object"""
return (
f"{self.__class__.__name__} "
f"("
f"name: {self.name}, "
f"writeable: {self.writeable}, "
f"value: {self.value}, "
f"raw: {self._raw}, "
f"class: {self.datatype_class}, "
f"unit: {self.datatype_unit}"
f")"
)
def __str__(self):
"""Returns a human-readable string representation of the datatype object"""
value = self.value
if value is not None:
return str(value)
return str(self.raw)
def __eq__(self, other):
"""Tests for equality of two datatype objects"""
if not isinstance(other, Base):
return False
return (
self.value == other.value
and self.datatype_class == other.datatype_class
and self.datatype_unit == other.datatype_unit
)
def __lt__(self, other):
"""Compares two datatype objects and returns which one contains the lower value"""
return (
self.value < other.value
and self.datatype_class == other.datatype_class
and self.datatype_unit == other.datatype_unit
)
class SelectionBase(Base):
"""Selection base datatype, converts from and to list of codes."""
datatype_class = "selection"
codes = {}
@classmethod
def options(cls):
"""Return list of all available options."""
return [value for _, value in cls.codes.items()]
@classmethod
def from_heatpump(cls, value):
if value in cls.codes:
return cls.codes.get(value)
return None
@classmethod
def to_heatpump(cls, value):
for index, code in cls.codes.items():
if code == value:
return index
return None
class ScalingBase(Base):
"""Scaling base datatype, converts via a scaling factor."""
datatype_class = "scaling"
scaling_factor = 1
@classmethod
def from_heatpump(cls, value):
if value is None:
return None
value = value * cls.scaling_factor
return value
@classmethod
def to_heatpump(cls, value):
raw = int(float(value) / cls.scaling_factor)
return raw
class Celsius(ScalingBase):
"""Celsius datatype, converts from and to Celsius."""
datatype_class = "temperature"
datatype_unit = "°C"
scaling_factor = 0.1
class Bool(Base):
"""Boolean datatype, converts from and to Boolean."""
datatype_class = "boolean"
@classmethod
def from_heatpump(cls, value):
return bool(value)
@classmethod
def to_heatpump(cls, value):
return int(value)
class Frequency(Base):
"""Frequency datatype, converts from and to Frequency in Hz."""
datatype_class = "frequency"
datatype_unit = "Hz"
class Seconds(Base):
"""Seconds datatype, converts from and to Seconds."""
datatype_class = "timespan"
datatype_unit = "s"
class IPv4Address(Base):
"""IPv4 address datatype, converts from and to an IPv4 address."""
datatype_class = "ipv4_address"
@classmethod
def from_heatpump(cls, value):
return socket.inet_ntoa(struct.pack(">i", value))
@classmethod
def to_heatpump(cls, value):
return struct.unpack(">i", socket.inet_aton(value))[0]
class Timestamp(Base):
"""Timestamp datatype, converts from and to Timestamp."""
datatype_class = "timestamp"
@classmethod
def from_heatpump(cls, value):
if value is None:
return None
if value <= 0:
return datetime.datetime.fromtimestamp(0)
return datetime.datetime.fromtimestamp(value)
@classmethod
def to_heatpump(cls, value):
return datetime.datetime.timestamp(value)
class Errorcode(Base):
"""Errorcode datatype, converts from and to Errorcode."""
datatype_class = "errorcode"
class Kelvin(ScalingBase):
"""Kelvin datatype, converts from and to Kelvin."""
datatype_class = "temperature"
datatype_unit = "K"
scaling_factor = 0.1
class Pressure(ScalingBase):
"""Pressure datatype, converts from and to Pressure."""
datatype_class = "pressure"
datatype_unit = "bar"
scaling_factor = 0.01
class Percent(ScalingBase):
"""Percent datatype, converts from and to Percent."""
datatype_class = "percent"
datatype_unit = "%"
scaling_factor = 0.1
class Percent2(Base):
"""Percent datatype, converts from and to Percent with a different scaling factor."""
datatype_class = "percent"
datatype_unit = "%"
class Speed(Base):
"""Speed datatype, converts from and to Speed."""
datatype_class = "speed"
datatype_unit = "rpm"
class Power(Base):
"""Power datatype, converts from and to Power."""
datatype_class = "power"
datatype_unit = "W"
class Energy(ScalingBase):
"""Energy datatype, converts from and to Energy."""
datatype_class = "energy"
datatype_unit = "kWh"
scaling_factor = 0.1
class Voltage(ScalingBase):
"""Voltage datatype, converts from and to Voltage."""
datatype_class = "voltage"
datatype_unit = "V"
scaling_factor = 0.1
class Hours(ScalingBase):
"""Hours datatype, converts from and to Hours."""
datatype_class = "timespan"
datatype_unit = "h"
scaling_factor = 0.1
class Hours2(Base):
"""Hours datatype, converts from and to Hours with a different scaling factor."""
datatype_class = "timespan"
datatype_unit = "h"
@classmethod
def from_heatpump(cls, value):
if value is None:
return None
return 1 + value / 2
@classmethod
def to_heatpump(cls, value):
return int((value - 1) * 2)
class Minutes(Base):
"""Minutes datatype, converts from and to Minutes."""
datatype_class = "timespan"
datatype_unit = "min"
class Flow(Base):
"""Flow datatype, converts from and to Flow."""
datatype_class = "flow"
datatype_unit = "l/h"
class Level(Base):
"""Level datatype, converts from and to Level."""
datatype_class = "level"
class Count(Base):
"""Count datatype, converts from and to Count."""
datatype_class = "count"
class Character(Base):
"""Character datatype, converts from and to a Character."""
datatype_class = "character"
@classmethod
def from_heatpump(cls, value):
if value == 0:
return ""
return chr(value)
class MajorMinorVersion(Base):
"""MajorMinorVersion datatype, converts from and to a RBEVersion"""
datatype_class = "version"
@classmethod
def from_heatpump(cls, value):
if value > 0:
major = value // 100
minor = value % 100
return f"{major}.{minor}"
return "0"
class Icon(Base):
"""Icon datatype, converts from and to Icon."""
datatype_class = "icon"
class HeatingMode(SelectionBase):
"""HeatingMode datatype, converts from and to list of HeatingMode codes."""
datatype_class = "selection"
codes = {
0: "Automatic",
1: "Second heatsource",
2: "Party",
3: "Holidays",
4: "Off",
}
class CoolingMode(SelectionBase):
"""CoolingMode datatype, converts from and to list of CoolingMode codes."""
datatype_class = "selection"
codes = {0: "Off", 1: "Automatic"}
class HotWaterMode(SelectionBase):
"""HotWaterMode datatype, converts from and to list of HotWaterMode codes."""
datatype_class = "selection"
codes = {
0: "Automatic",
1: "Second heatsource",
2: "Party",
3: "Holidays",
4: "Off",
}
class PoolMode(SelectionBase):
"""PoolMode datatype, converts from and to list of PoolMode codes."""
datatype_class = "selection"
codes = {0: "Automatic", 2: "Party", 3: "Holidays", 4: "Off"}
class MixedCircuitMode(SelectionBase):
"""MixCircuitMode datatype, converts from and to list of MixCircuitMode codes."""
datatype_class = "selection"
codes = {0: "Automatic", 2: "Party", 3: "Holidays", 4: "Off"}
class SolarMode(SelectionBase):
"""SolarMode datatype, converts from and to list of SolarMode codes."""
datatype_class = "selection"
codes = {
0: "Automatic",
1: "Second heatsource",
2: "Party",
3: "Holidays",
4: "Off",
}
class VentilationMode(SelectionBase):
"""VentilationMode datatype, converts from and to list of VentilationMode codes."""
datatype_class = "selection"
codes = {0: "Automatic", 1: "Party", 2: "Holidays", 3: "Off"}
class HeatpumpCode(SelectionBase):
"""HeatpumpCode datatype, converts from and to list of Heatpump codes."""
datatype_class = "selection"
codes = {
0: "ERC",
1: "SW1",
2: "SW2",
3: "WW1",
4: "WW2",
5: "L1I",
6: "L2I",
7: "L1A",
8: "L2A",
9: "KSW",
10: "KLW",
11: "SWC",
12: "LWC",
13: "L2G",
14: "WZS",
15: "L1I407",
16: "L2I407",
17: "L1A407",
18: "L2A407",
19: "L2G407",
20: "LWC407",
21: "L1AREV",
22: "L2AREV",
23: "WWC1",
24: "WWC2",
25: "L2G404",
26: "WZW",
27: "L1S",
28: "L1H",
29: "L2H",
30: "WZWD",
31: "ERC",
40: "WWB_20",
41: "LD5",
42: "LD7",
43: "SW 37_45",
44: "SW 58_69",
45: "SW 29_56",
46: "LD5 (230V)",
47: "LD7 (230 V)",
48: "LD9",
49: "LD5 REV",
50: "LD7 REV",
51: "LD5 REV 230V",
52: "LD7 REV 230V",
53: "LD9 REV 230V",
54: "SW 291",
55: "LW SEC",
56: "HMD 2",
57: "MSW 4",
58: "MSW 6",
59: "MSW 8",
60: "MSW 10",
61: "MSW 12",
62: "MSW 14",
63: "MSW 17",
64: "MSW 19",
65: "MSW 23",
66: "MSW 26",
67: "MSW 30",
68: "MSW 4S",
69: "MSW 6S",
70: "MSW 8S",
71: "MSW 10S",
72: "MSW 13S",
73: "MSW 16S",
74: "MSW2-6S",
75: "MSW4-16",
}
class BivalenceLevel(SelectionBase):
"""BivalanceLevel datatype, converts from and to list of BivalanceLevel codes."""
datatype_class = "selection"
codes = {
1: "one compressor allowed to run",
2: "two compressors allowed to run",
3: "additional heat generator allowed to run",
}
class OperationMode(SelectionBase):
"""OperationMode datatype, converts from and to list of OperationMode codes."""
datatype_class = "selection"
codes = {
0: "heating",
1: "hot water",
2: "swimming pool/solar",
3: "evu",
4: "defrost",
5: "no request",
6: "heating external source",
7: "cooling",
}
class SwitchoffFile(SelectionBase):
"""SwitchOff datatype, converts from and to list of SwitchOff codes."""
datatype_class = "selection"
codes = {
1: "heatpump error",
2: "system error",
3: "evu lock",
4: "operation mode second heat generator",
5: "air defrost",
6: "maximal usage temperature",
7: "minimal usage temperature",
8: "lower usage limit",
9: "no request",
11: "flow rate",
19: "PV max",
}
class MainMenuStatusLine1(SelectionBase):
"""MenuStatusLine datatype, converts from and to list of MenuStatusLine codes."""
datatype_class = "selection"
codes = {
0: "heatpump running",
1: "heatpump idle",
2: "heatpump coming",
3: "errorcode slot 0",
4: "defrost",
5: "waiting on LIN connection",
6: "compressor heating up",
7: "pump forerun",
}
class MainMenuStatusLine2(SelectionBase):
"""MenuStatusLine datatype, converts from and to list of MenuStatusLine codes."""
datatype_class = "selection"
codes = {0: "since", 1: "in"}
class MainMenuStatusLine3(SelectionBase):
"""MenuStatusLine datatype, converts from and to list of MenuStatusLine codes."""
datatype_class = "selection"
codes = {
0: "heating",
1: "no request",
2: "grid switch on delay",
3: "cycle lock",
4: "lock time",
5: "domestic water",
6: "info bake out program",
7: "defrost",
8: "pump forerun",
9: "thermal desinfection",
10: "cooling",
12: "swimming pool/solar",
13: "heating external energy source",
14: "domestic water external energy source",
16: "flow monitoring",
17: "second heat generator 1 active",
}
class SecOperationMode(SelectionBase):
"""SecOperationMode datatype, converts from and to list of SecOperationMode codes."""
datatype_class = "selection"
codes = {
0: "off",
1: "cooling",
2: "heating",
3: "fault",
4: "transition",
5: "defrost",
6: "waiting",
7: "waiting",
8: "transition",
9: "stop",
10: "manual",
11: "simulation start",
12: "evu lock",
}
class AccessLevel(SelectionBase):
"""AccessLevel datatype, converts from and to list of AccessLevel codes"""
datatype_class = "selection"
codes = {
0: "user",
1: "after sales service",
2: "manufacturer",
3: "installer",
}
class Unknown(Base):
"""Unknown datatype, fallback for unknown data."""
datatype_class = None