MBusinoLibPy 0.10.0__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.
@@ -0,0 +1,68 @@
1
+ # -*- coding: utf-8 -*-
2
+ """MBusinoLibPy - Python port of the Arduino library **MBusinoLib**.
3
+
4
+ This library decodes M-Bus (Meterbus) RSP_UD telegrams - the answer a
5
+ slave sends to the master - entirely in pure Python
6
+ (standard library only, no runtime dependencies).
7
+
8
+ The port follows the C++ original ``MBusinoLib`` (version 0.10.0, GPL-3.0)
9
+ function by function; every Python function refers in its comment to
10
+ the corresponding C++ function including the line number.
11
+
12
+ Schnellstart::
13
+
14
+ from MBusinoLibPy import MBusinoLib
15
+
16
+ telegram = bytes.fromhex(
17
+ "68 C1 C1 68 08 00 72 09 34 75 73 C5 14 00 0D 43 00 00 00"
18
+ "04 78 41 63 65 04 04 06 AA 29 00 00 ... 75 16"
19
+ )
20
+ decode = MBusinoLib()
21
+ result = decode.decode_telegram(telegram)
22
+ print(result["header"]["manufacturer"], result["records"][0])
23
+
24
+ All public names:
25
+
26
+ * ``MBusinoLib`` - the decoder class
27
+ * ``MBUS_CODE`` - enum of the supported record codes (identical to C++)
28
+ * ``MBUS_ERROR`` - enum of the error codes (identical to C++)
29
+ * ``VIF_DEFS`` / ``MBUS_VIF_DEF_NUM`` - the VIF definition table
30
+ * ``CODE_NAME`` / ``CODE_UNITS`` / ``DEVICE_CLASS`` / ``STATE_CLASS`` /
31
+ ``MEDIUM_NAMES`` - the four lookup tables from the C++ original
32
+ """
33
+
34
+ from .enums import (
35
+ ARDUINO_FLOAT_DECIMALS,
36
+ ARDUINO_FLOAT_MIN,
37
+ MBUS_DEFAULT_BUFFER_SIZE,
38
+ MBUS_CODE,
39
+ MBUS_ERROR,
40
+ )
41
+ from .lookup_tables import (
42
+ CODE_NAME,
43
+ CODE_UNITS,
44
+ DEVICE_CLASS,
45
+ MEDIUM_NAMES,
46
+ STATE_CLASS,
47
+ )
48
+ from .mbusino_lib import MBusinoLib
49
+ from .vif_defs import MBUS_VIF_DEF_NUM, VIF_DEFS
50
+
51
+ __version__ = "0.10.0" # corresponds to the version of the C++ original (library.json)
52
+
53
+ __all__ = [
54
+ "MBusinoLib",
55
+ "MBUS_CODE",
56
+ "MBUS_ERROR",
57
+ "VIF_DEFS",
58
+ "MBUS_VIF_DEF_NUM",
59
+ "CODE_NAME",
60
+ "CODE_UNITS",
61
+ "DEVICE_CLASS",
62
+ "STATE_CLASS",
63
+ "MEDIUM_NAMES",
64
+ "MBUS_DEFAULT_BUFFER_SIZE",
65
+ "ARDUINO_FLOAT_MIN",
66
+ "ARDUINO_FLOAT_DECIMALS",
67
+ "__version__",
68
+ ]
MBusinoLibPy/enums.py ADDED
@@ -0,0 +1,170 @@
1
+ # -*- coding: utf-8 -*-
2
+ """Enumerations and constants - 1:1 port from MBusinoLib.h.
3
+
4
+ The order of the MBUS_CODE members is identical to the C++ enum in
5
+ MBusinoLib.h (line 37-165): C++ numbers them 0,1,2,... in declaration
6
+ order and Python's IntEnum does exactly the same. Therefore all
7
+ numeric values (and with them vif_defs + getCodeName & Co.) match.
8
+ """
9
+
10
+ from enum import IntEnum
11
+
12
+ # Constants from MBusinoLib.h line 31-33
13
+ MBUS_DEFAULT_BUFFER_SIZE = 254 # size of the internal C++ buffer (dropped in Python, see spec item 4)
14
+ ARDUINO_FLOAT_MIN = 1e-6 # "Assume 0 if less than this" - never used in the C++ code, documentation only
15
+ ARDUINO_FLOAT_DECIMALS = 6 # "6 decimals is just below the limit for Arduino float maths" -
16
+ # corresponds to the tolerance of the golden tests for value_scaled
17
+
18
+
19
+ class MBUS_CODE(IntEnum):
20
+ """Supported VIF codes - corresponds to `enum MBUS_CODE` in MBusinoLib.h line 37.
21
+
22
+ The value is the internal record identifier ("code" field of the JSON output),
23
+ NOT the VIF byte value. The latter lives in the vif_defs table.
24
+ """
25
+ # unknown VIF - the original uses it as a failure hint (VIF 0x7E is not used in the Slave -> Master direction)
26
+ UNKNOWN_VIF = 0
27
+
28
+ # without VIFE: physical quantities straight from table 8.4.1 (EN 13757)
29
+ ENERGY_WH = 1
30
+ ENERGY_J = 2
31
+ VOLUME_M3 = 3
32
+ MASS_KG = 4
33
+ ON_TIME_S = 5
34
+ ON_TIME_MIN = 6
35
+ ON_TIME_H = 7
36
+ ON_TIME_DAYS = 8
37
+ OPERATING_TIME_S = 9
38
+ OPERATING_TIME_MIN = 10
39
+ OPERATING_TIME_H = 11
40
+ OPERATING_TIME_DAYS = 12
41
+ POWER_W = 13
42
+ POWER_J_H = 14
43
+ VOLUME_FLOW_M3_H = 15
44
+ VOLUME_FLOW_M3_MIN = 16
45
+ VOLUME_FLOW_M3_S = 17
46
+ MASS_FLOW_KG_H = 18
47
+ FLOW_TEMPERATURE_C = 19
48
+ RETURN_TEMPERATURE_C = 20
49
+ TEMPERATURE_DIFF_K = 21
50
+ EXTERNAL_TEMPERATURE_C = 22
51
+ PRESSURE_BAR = 23
52
+ TIME_POINT_DATE = 24
53
+ TIME_POINT_DATETIME = 25
54
+ AVG_DURATION_S = 26
55
+ AVG_DURATION_MIN = 27
56
+ AVG_DURATION_H = 28
57
+ AVG_DURATION_DAYS = 29
58
+ ACTUAL_DURATION_S = 30
59
+ ACTUAL_DURATION_MIN = 31
60
+ ACTUAL_DURATION_H = 32
61
+ ACTUAL_DURATION_DAYS = 33
62
+ FABRICATION_NUMBER = 34
63
+ BUS_ADDRESS = 35
64
+
65
+ # VIFE 0xFD: operating and counter data
66
+ CREDIT = 36
67
+ DEBIT = 37
68
+ ACCESS_NUMBER = 38
69
+ MANUFACTURER = 39
70
+ PARAMETER_SET_ID = 40
71
+ MODEL_VERSION = 41
72
+ HARDWARE_VERSION = 42
73
+ FIRMWARE_VERSION = 43
74
+ SOFTWARE_VERSION = 44
75
+ CUSTOMER_LOCATION = 45
76
+ CUSTOMER = 46
77
+ ERROR_FLAGS = 47
78
+ ERROR_MASK = 48
79
+ DIGITAL_OUTPUT = 49
80
+ DIGITAL_INPUT = 50
81
+ BAUDRATE_BPS = 51
82
+ RESPONSE_DELAY_TIME = 52
83
+ RETRY = 53
84
+ SIZE_OF_STORAGE_BLOCK = 54
85
+ STORAGE_INTERVAL_MONTH = 55
86
+ GENERIC = 56
87
+ VOLTS = 57
88
+ AMPERES = 58
89
+ RESET_COUNTER = 59
90
+ CUMULATION_COUNTER = 60
91
+ SPECIAL_SUPPLIER_INFO = 61
92
+
93
+ # VIFE 0xFDFD: double extension (VIFE on VIFE)
94
+ CURRENT_SELECTED_APL = 62
95
+ SUB_DEVICES = 63
96
+ REMAIN_BAT_LIFE_MONTH = 64
97
+ CARBON_DIOXIDE_PPM = 65
98
+ CARBON_MONOXIDE_PPM = 66
99
+ VOLATILE_ORG_COMP_ppb = 67
100
+ VOLATILE_ORG_COMP_UG_M3 = 68
101
+ PARTICLES_UNSPEC_UG_M3 = 69
102
+ PARTICLES_PM1_UG_M3 = 70
103
+ PARTICLES_PM2_5_UG_M3 = 71
104
+ PARTICLES_PM10_UG_M3 = 72
105
+ PARTICLES_UNSPEC_1M3 = 73
106
+ PARTICLES_PM1_1M3 = 74
107
+ PARTICLES_PM2_5_1M3 = 75
108
+ PARTICLES_PM10_1M3 = 76
109
+ ILLUMINANCE_LUX = 77
110
+ LUMINOUS_INTENSITY_CD = 78
111
+ RADIANT_FLUX_DENS = 79
112
+ WIND_SPEED_M_S = 80
113
+ RAINFALL_L_MM = 81
114
+ FORMAZIN_NEPHELOMETER_U = 82
115
+ POTENTIAL_HYDROGEN_PH = 83
116
+ DISMOUNTS_COUNTER = 84
117
+ TEST_BUTTON_COUNTER = 85
118
+ ALARM_COUNTER = 86
119
+ ALARM_MUTE_COUNTER = 87
120
+ OBSTACLE_DETECT_COUNTER = 88
121
+ SMOKE_ENTRIES_COUNTER = 89
122
+ SMOKE_CHAMBER_DEFECTS = 90
123
+ SELF_TEST_COUNTER = 91
124
+ SOUNDER_DEFECT_COUNTER = 92
125
+ DECIBEL_A = 93
126
+ BATTERY_PERCENTAGE = 94
127
+ CHAMBER_POLLUTION_LEVEL = 95
128
+ DISTANCE_MM = 96
129
+ MOISTURE_LEVEL_PERCENT = 97
130
+ PRESSURE_SENS_STATUS = 98
131
+ SMOKE_ALARM_STATUS = 99
132
+ CO_ALARM_STATUS = 100
133
+ HEAT_ALARM_STATUS = 101
134
+ DOOR_WINDOW_SENS_STATUS = 102
135
+
136
+ # VIFE 0xFB: international units / different scaling
137
+ REACTIVE_ENERGY = 103
138
+ REACTIVE_POWER = 104
139
+ RELATIVE_HUMIDITY = 105
140
+ VOLUME_FT3 = 106
141
+ VOLUME_GAL = 107
142
+ VOLUME_FLOW_GAL_M = 108
143
+ VOLUME_FLOW_GAL_H = 109
144
+ APPARENT_POWER = 110
145
+ FLOW_TEMPERATURE_F = 111
146
+ RETURN_TEMPERATURE_F = 112
147
+ TEMPERATURE_DIFF_F = 113
148
+ EXTERNAL_TEMPERATURE_F = 114
149
+ TEMPERATURE_LIMIT_F = 115
150
+ TEMPERATURE_LIMIT_C = 116
151
+ MAX_POWER_W = 117
152
+ PHASE_VOLT_DEG = 118
153
+ PHASE_CURR_DEG = 119
154
+ FREQUENCY = 120
155
+
156
+ # VIFE 0xFC: benutzerdefinierter VIF als ASCII-String
157
+ CUSTOMIZED_VIF = 121
158
+
159
+ # VIFE 0xFF: manufacturer specific (never scaled)
160
+ MANUFACTURER_SPECIFIC = 122
161
+
162
+
163
+ class MBUS_ERROR(IntEnum):
164
+ """Error codes - corresponds to `enum MBUS_ERROR` in MBusinoLib.h line 168-176."""
165
+ NO_ERROR = 0
166
+ BUFFER_OVERFLOW = 1
167
+ UNSUPPORTED_CODING = 2
168
+ UNSUPPORTED_RANGE = 3
169
+ UNSUPPORTED_VIF = 4
170
+ NEGATIVE_VALUE = 5