diff --git a/dsmr_parser/clients/protocol.py b/dsmr_parser/clients/protocol.py index a7fb74f..ba38fe5 100644 --- a/dsmr_parser/clients/protocol.py +++ b/dsmr_parser/clients/protocol.py @@ -51,6 +51,9 @@ def _create_dsmr_protocol(dsmr_version, telegram_callback, protocol, loop=None, elif dsmr_version == 'ISKRA_IE': specification = telegram_specifications.ISKRA_IE serial_settings = SERIAL_SETTINGS_V5 + elif dsmr_version == '5EONHU': + specification = telegram_specifications.EON_HUNGARY + serial_settings = SERIAL_SETTINGS_V5 else: raise NotImplementedError("No telegram parser found for version: %s", dsmr_version) diff --git a/dsmr_parser/clients/socket_.py b/dsmr_parser/clients/socket_.py index b7490ec..8ee16fa 100644 --- a/dsmr_parser/clients/socket_.py +++ b/dsmr_parser/clients/socket_.py @@ -43,7 +43,12 @@ def read(self): continue for data in lines: - self.telegram_buffer.append(data.decode('ascii')) + try: + self.telegram_buffer.append(data.decode('ascii')) + except UnicodeDecodeError: + # Some garbage came through the channel + # E.g.: Happens at EON_HUNGARY, but only once at the start of the socket. + logger.error('Failed to parse telegram due to unicode decode error') for telegram in self.telegram_buffer.get_all(): try: diff --git a/dsmr_parser/obis_name_mapping.py b/dsmr_parser/obis_name_mapping.py index 44ebb82..95f1016 100644 --- a/dsmr_parser/obis_name_mapping.py +++ b/dsmr_parser/obis_name_mapping.py @@ -92,7 +92,29 @@ obis.Q3D_EQUIPMENT_IDENTIFIER: 'Q3D_EQUIPMENT_IDENTIFIER', obis.Q3D_EQUIPMENT_STATE: 'Q3D_EQUIPMENT_STATE', obis.Q3D_EQUIPMENT_SERIALNUMBER: 'Q3D_EQUIPMENT_SERIALNUMBER', - obis.BELGIUM_MBUS2_DEVICE_TYPE: 'BELGIUM_MBUS2_DEVICE_TYPE' + obis.BELGIUM_MBUS2_DEVICE_TYPE: 'BELGIUM_MBUS2_DEVICE_TYPE', + obis.EON_HU_ELECTRICITY_DELIVERED_TARIFF_3: 'EON_HU_ELECTRICITY_DELIVERED_TARIFF_3', + obis.EON_HU_ELECTRICITY_DELIVERED_TARIFF_4: 'EON_HU_ELECTRICITY_DELIVERED_TARIFF_4', + obis.EON_HU_ELECTRICITY_USED_TARIFF_3: 'EON_HU_ELECTRICITY_USED_TARIFF_3', + obis.EON_HU_ELECTRICITY_USED_TARIFF_4: 'EON_HU_ELECTRICITY_USED_TARIFF_4', + obis.EON_HU_ELECTRICITY_REACTIVE_TOTAL_Q1: 'EON_HU_ELECTRICITY_REACTIVE_TOTAL_Q1', + obis.EON_HU_ELECTRICITY_REACTIVE_TOTAL_Q2: 'EON_HU_ELECTRICITY_REACTIVE_TOTAL_Q2', + obis.EON_HU_ELECTRICITY_REACTIVE_TOTAL_Q3: 'EON_HU_ELECTRICITY_REACTIVE_TOTAL_Q3', + obis.EON_HU_ELECTRICITY_REACTIVE_TOTAL_Q4: 'EON_HU_ELECTRICITY_REACTIVE_TOTAL_Q4', + obis.EON_HU_ELECTRICITY_COMBINED: 'EON_HU_ELECTRICITY_COMBINED', + obis.EON_HU_INSTANTANEOUS_POWER_FACTOR_TOTAL: 'EON_HU_INSTANTANEOUS_POWER_FACTOR_TOTAL', + obis.EON_HU_INSTANTANEOUS_POWER_FACTOR_L1: 'EON_HU_INSTANTANEOUS_POWER_FACTOR_L1', + obis.EON_HU_INSTANTANEOUS_POWER_FACTOR_L2: 'EON_HU_INSTANTANEOUS_POWER_FACTOR_L2', + obis.EON_HU_INSTANTANEOUS_POWER_FACTOR_L3: 'EON_HU_INSTANTANEOUS_POWER_FACTOR_L3', + obis.EON_HU_FREQUENCY: 'EON_HU_FREQUENCY', + obis.EON_HU_INSTANTANEOUS_REACTIVE_POWER_Q1: 'EON_HU_INSTANTANEOUS_REACTIVE_POWER_Q1', + obis.EON_HU_INSTANTANEOUS_REACTIVE_POWER_Q2: 'EON_HU_INSTANTANEOUS_REACTIVE_POWER_Q2', + obis.EON_HU_INSTANTANEOUS_REACTIVE_POWER_Q3: 'EON_HU_INSTANTANEOUS_REACTIVE_POWER_Q3', + obis.EON_HU_INSTANTANEOUS_REACTIVE_POWER_Q4: 'EON_HU_INSTANTANEOUS_REACTIVE_POWER_Q4', + obis.EON_HU_MAX_POWER_ON_L1: 'EON_HU_MAX_POWER_ON_L1', + obis.EON_HU_MAX_POWER_ON_L2: 'EON_HU_MAX_POWER_ON_L2', + obis.EON_HU_MAX_POWER_ON_L3: 'EON_HU_MAX_POWER_ON_L3', + obis.EON_HU_LAST_MONTH_DATA: 'EON_HU_LAST_MONTH_DATA' } REVERSE_EN = dict([(v, k) for k, v in EN.items()]) diff --git a/dsmr_parser/obis_references.py b/dsmr_parser/obis_references.py index c710504..920e39e 100644 --- a/dsmr_parser/obis_references.py +++ b/dsmr_parser/obis_references.py @@ -122,3 +122,27 @@ Q3D_EQUIPMENT_IDENTIFIER = r'^\d-\d:0\.0\.0.+?\r\n' # Logical device name Q3D_EQUIPMENT_STATE = r'^\d-\d:96\.5\.5.+?\r\n' # Device state (hexadecimal) Q3D_EQUIPMENT_SERIALNUMBER = r'^\d-\d:96\.1\.255.+?\r\n' # Device Serialnumber + +# EON Hungary +EON_HU_ELECTRICITY_USED_TARIFF_3 = r'^\d-\d:1\.8\.3.+?\r\n' +EON_HU_ELECTRICITY_USED_TARIFF_4 = r'^\d-\d:1\.8\.4.+?\r\n' +EON_HU_ELECTRICITY_DELIVERED_TARIFF_3 = r'^\d-\d:2\.8\.3.+?\r\n' +EON_HU_ELECTRICITY_DELIVERED_TARIFF_4 = r'^\d-\d:2\.8\.4.+?\r\n' +EON_HU_ELECTRICITY_REACTIVE_TOTAL_Q1 = r'^\d-\d:5\.8\.0.+?\r\n' +EON_HU_ELECTRICITY_REACTIVE_TOTAL_Q2 = r'^\d-\d:6\.8\.0.+?\r\n' +EON_HU_ELECTRICITY_REACTIVE_TOTAL_Q3 = r'^\d-\d:7\.8\.0.+?\r\n' +EON_HU_ELECTRICITY_REACTIVE_TOTAL_Q4 = r'^\d-\d:8\.8\.0.+?\r\n' +EON_HU_ELECTRICITY_COMBINED = r'^\d-\d:15\.8\.0.+?\r\n' +EON_HU_INSTANTANEOUS_POWER_FACTOR_TOTAL = r'^\d-\d:13\.7\.0.+?\r\n' +EON_HU_INSTANTANEOUS_POWER_FACTOR_L1 = r'^\d-\d:33\.7\.0.+?\r\n' +EON_HU_INSTANTANEOUS_POWER_FACTOR_L2 = r'^\d-\d:53\.7\.0.+?\r\n' +EON_HU_INSTANTANEOUS_POWER_FACTOR_L3 = r'^\d-\d:73\.7\.0.+?\r\n' +EON_HU_FREQUENCY = r'^\d-\d:14\.7\.0.+?\r\n' +EON_HU_INSTANTANEOUS_REACTIVE_POWER_Q1 = r'^\d-\d:5\.7\.0.+?\r\n' +EON_HU_INSTANTANEOUS_REACTIVE_POWER_Q2 = r'^\d-\d:6\.7\.0.+?\r\n' +EON_HU_INSTANTANEOUS_REACTIVE_POWER_Q3 = r'^\d-\d:7\.7\.0.+?\r\n' +EON_HU_INSTANTANEOUS_REACTIVE_POWER_Q4 = r'^\d-\d:8\.7\.0.+?\r\n' +EON_HU_MAX_POWER_ON_L1 = r'^\d-\d:31\.4\.0.+?\r\n' +EON_HU_MAX_POWER_ON_L2 = r'^\d-\d:51\.4\.0.+?\r\n' +EON_HU_MAX_POWER_ON_L3 = r'^\d-\d:71\.4\.0.+?\r\n' +EON_HU_LAST_MONTH_DATA = r'^\d-\d:98\.1\.0.+?\r\n' diff --git a/dsmr_parser/telegram_specifications.py b/dsmr_parser/telegram_specifications.py index f9f8a79..a5030a4 100644 --- a/dsmr_parser/telegram_specifications.py +++ b/dsmr_parser/telegram_specifications.py @@ -339,3 +339,60 @@ obis.EQUIPMENT_IDENTIFIER: CosemParser(ValueParser(str)), } } + +EON_HUNGARY = { + # Revision: 2023.02.10 + # Based on V5 + # Reference: https://www.eon.hu/content/dam/eon/eon-hungary/documents/Lakossagi/aram/muszaki-ugyek/p1_port%20felhaszn_interfesz_taj_%2020230210.pdf + 'checksum_support': True, + 'objects': { + obis.P1_MESSAGE_TIMESTAMP: CosemParser(ValueParser(timestamp)), + obis.LUXEMBOURG_EQUIPMENT_IDENTIFIER: CosemParser(ValueParser(str)), # "COSEM logical equipment name" + obis.EQUIPMENT_IDENTIFIER_GAS: CosemParser(ValueParser(str)), # This obis is already defined, so it is not possible to "rename" it to "EQUIPMENT_SERIAL_NUMBER" + obis.ELECTRICITY_ACTIVE_TARIFF: CosemParser(ValueParser(str)), + obis.ACTUAL_SWITCH_POSITION: CosemParser(ValueParser(str)), # This seems to be wrong in documentation, it's not 0-0:96.50.68, but 0-0:96.3.10 + obis.ACTUAL_TRESHOLD_ELECTRICITY: CosemParser(ValueParser(Decimal)), # This obis is already duplicated, so it will show up as "BELGIUM_MAX_POWER_PER_PHASE" + obis.ELECTRICITY_IMPORTED_TOTAL: CosemParser(ValueParser(Decimal)), + obis.ELECTRICITY_USED_TARIFF_1: CosemParser(ValueParser(Decimal)), + obis.ELECTRICITY_USED_TARIFF_2: CosemParser(ValueParser(Decimal)), + obis.EON_HU_ELECTRICITY_USED_TARIFF_3: CosemParser(ValueParser(Decimal)), + obis.EON_HU_ELECTRICITY_USED_TARIFF_4: CosemParser(ValueParser(Decimal)), + obis.ELECTRICITY_EXPORTED_TOTAL: CosemParser(ValueParser(Decimal)), + obis.ELECTRICITY_DELIVERED_TARIFF_1: CosemParser(ValueParser(Decimal)), + obis.ELECTRICITY_DELIVERED_TARIFF_2: CosemParser(ValueParser(Decimal)), + obis.EON_HU_ELECTRICITY_DELIVERED_TARIFF_3: CosemParser(ValueParser(Decimal)), + obis.EON_HU_ELECTRICITY_DELIVERED_TARIFF_4: CosemParser(ValueParser(Decimal)), + obis.ELECTRICITY_REACTIVE_IMPORTED_TOTAL: CosemParser(ValueParser(Decimal)), + obis.ELECTRICITY_REACTIVE_EXPORTED_TOTAL: CosemParser(ValueParser(Decimal)), + obis.EON_HU_ELECTRICITY_REACTIVE_TOTAL_Q1: CosemParser(ValueParser(Decimal)), + obis.EON_HU_ELECTRICITY_REACTIVE_TOTAL_Q2: CosemParser(ValueParser(Decimal)), + obis.EON_HU_ELECTRICITY_REACTIVE_TOTAL_Q3: CosemParser(ValueParser(Decimal)), + obis.EON_HU_ELECTRICITY_REACTIVE_TOTAL_Q4: CosemParser(ValueParser(Decimal)), + obis.EON_HU_ELECTRICITY_COMBINED: CosemParser(ValueParser(Decimal)), + obis.INSTANTANEOUS_VOLTAGE_L1: CosemParser(ValueParser(Decimal)), + obis.INSTANTANEOUS_VOLTAGE_L2: CosemParser(ValueParser(Decimal)), # Only with 3 phase meters + obis.INSTANTANEOUS_VOLTAGE_L3: CosemParser(ValueParser(Decimal)), # Only with 3 phase meters + obis.INSTANTANEOUS_CURRENT_L1: CosemParser(ValueParser(Decimal)), + obis.INSTANTANEOUS_CURRENT_L2: CosemParser(ValueParser(Decimal)), # Only with 3 phase meters + obis.INSTANTANEOUS_CURRENT_L3: CosemParser(ValueParser(Decimal)), # Only with 3 phase meters + obis.EON_HU_INSTANTANEOUS_POWER_FACTOR_TOTAL: CosemParser(ValueParser(Decimal)), + obis.EON_HU_INSTANTANEOUS_POWER_FACTOR_L1: CosemParser(ValueParser(Decimal)), + obis.EON_HU_INSTANTANEOUS_POWER_FACTOR_L2: CosemParser(ValueParser(Decimal)), # Only with 3 phase meters + obis.EON_HU_INSTANTANEOUS_POWER_FACTOR_L3: CosemParser(ValueParser(Decimal)), # Only with 3 phase meters + obis.EON_HU_FREQUENCY: CosemParser(ValueParser(Decimal)), + obis.CURRENT_ELECTRICITY_USAGE: CosemParser(ValueParser(Decimal)), + obis.CURRENT_ELECTRICITY_DELIVERY: CosemParser(ValueParser(Decimal)), + obis.EON_HU_INSTANTANEOUS_REACTIVE_POWER_Q1: CosemParser(ValueParser(Decimal)), + obis.EON_HU_INSTANTANEOUS_REACTIVE_POWER_Q2: CosemParser(ValueParser(Decimal)), + obis.EON_HU_INSTANTANEOUS_REACTIVE_POWER_Q3: CosemParser(ValueParser(Decimal)), + obis.EON_HU_INSTANTANEOUS_REACTIVE_POWER_Q4: CosemParser(ValueParser(Decimal)), + obis.EON_HU_MAX_POWER_ON_L1: CosemParser(ValueParser(Decimal)), + obis.EON_HU_MAX_POWER_ON_L2: CosemParser(ValueParser(Decimal)), # Only with 3 phase meters + obis.EON_HU_MAX_POWER_ON_L3: CosemParser(ValueParser(Decimal)), # Only with 3 phase meters + # This is a list of last month data (on last day of last month @ 23:59:59), + # But it is not clear that what are the elements of the list. + # This is not well documented enough, so it is ignored for now. + # obis.EON_HU_LAST_MONTH_DATA: + obis.TEXT_MESSAGE: CosemParser(ValueParser(str)) + } +} diff --git a/test/example_telegrams.py b/test/example_telegrams.py index d59ce83..55a3dae 100644 --- a/test/example_telegrams.py +++ b/test/example_telegrams.py @@ -311,3 +311,55 @@ '0-1:96.1.1()\r\n' '!AD3B\r\n' ) + +# V5 telegram of EON in Hungary +TELEGRAM_V5_EON_HU = ( + '/SAG5SAG-METER\r\n' + '\r\n' + '0-0:1.0.0(230724150730S)\r\n' + '0-0:42.0.0(53414733303832323030303032313630)\r\n' + '0-0:96.1.0(383930303832323030303032313630)\r\n' + '0-0:96.14.0(0001)\r\n' + '0-0:96.3.10(1)\r\n' + '0-0:17.0.0(90.000*kW)\r\n' + '1-0:1.8.0(000173.640*kWh)\r\n' + '1-0:1.8.1(000047.719*kWh)\r\n' + '1-0:1.8.2(000125.921*kWh)\r\n' + '1-0:1.8.3(000000.000*kWh)\r\n' + '1-0:1.8.4(000000.000*kWh)\r\n' + '1-0:2.8.0(000627.177*kWh)\r\n' + '1-0:2.8.1(000401.829*kWh)\r\n' + '1-0:2.8.2(000225.348*kWh)\r\n' + '1-0:2.8.3(000000.000*kWh)\r\n' + '1-0:2.8.4(000000.000*kWh)\r\n' + '1-0:3.8.0(000000.123*kvarh)\r\n' + '1-0:4.8.0(000303.131*kvarh)\r\n' + '1-0:5.8.0(000000.668*kvarh)\r\n' + '1-0:6.8.0(000000.071*kvarh)\r\n' + '1-0:7.8.0(000160.487*kvarh)\r\n' + '1-0:8.8.0(000143.346*kvarh)\r\n' + '1-0:15.8.0(000800.817*kWh)\r\n' + '1-0:32.7.0(240.4*V)\r\n' + '1-0:52.7.0(239.1*V)\r\n' + '1-0:72.7.0(241.2*V)\r\n' + '1-0:31.7.0(003*A)\r\n' + '1-0:51.7.0(004*A)\r\n' + '1-0:71.7.0(003*A)\r\n' + '1-0:13.7.0(4.556)\r\n' + '1-0:33.7.0(4.591)\r\n' + '1-0:53.7.0(4.542)\r\n' + '1-0:73.7.0(4.552)\r\n' + '1-0:14.7.0(50.00*Hz)\r\n' + '1-0:1.7.0(00.000*kW)\r\n' + '1-0:2.7.0(02.601*kW)\r\n' + '1-0:5.7.0(00.000*kvar)\r\n' + '1-0:6.7.0(00.000*kvar)\r\n' + '1-0:7.7.0(00.504*kvar)\r\n' + '1-0:8.7.0(00.000*kvar)\r\n' + '1-0:31.4.0(200.00*A)\r\n' + '1-0:51.4.0(200.00*A)\r\n' + '1-0:71.4.0(200.00*A)\r\n' + '0-0:98.1.0(230701000000S)(000040.777*kWh)(000008.950*kWh)(000031.827*kWh)(000142.250*kWh)(000111.164*kWh)(000031.086*kWh)(000000.030*kvarh)(000073.988*kvarh)(000000.205*kvarh)(000000.048*kvarh)(000039.199*kvarh)(000035.020*kvarh)(000183.027*kWh)(03.564*kW)(02.156*kW)(03.564*kW)(04.104*kW)(04.104*kW)(03.400*kW)\r\n' + '0-0:96.13.0()\r\n' + '!99DA\r\n' +) \ No newline at end of file diff --git a/test/test_parse_v5_eon_hungary.py b/test/test_parse_v5_eon_hungary.py new file mode 100644 index 0000000..401f3dd --- /dev/null +++ b/test/test_parse_v5_eon_hungary.py @@ -0,0 +1,308 @@ +from decimal import Decimal + +import datetime +import unittest + +import pytz + +from dsmr_parser import telegram_specifications +from dsmr_parser.exceptions import InvalidChecksumError, ParseError +from dsmr_parser.objects import CosemObject, MBusObject +from dsmr_parser.parsers import TelegramParser +from test.example_telegrams import TELEGRAM_V5_EON_HU + + +class TelegramParserV5EONHUTest(unittest.TestCase): + """ Test parsing of a DSMR v5 EON Hungary telegram. """ + + def test_parse(self): + parser = TelegramParser(telegram_specifications.EON_HUNGARY) + try: + telegram = parser.parse(TELEGRAM_V5_EON_HU, throw_ex=True) + except Exception as ex: + assert False, f"parse trigged an exception {ex}" + + # P1_MESSAGE_TIMESTAMP (0-0:1.0.0) + assert isinstance(telegram.P1_MESSAGE_TIMESTAMP, CosemObject) + assert telegram.P1_MESSAGE_TIMESTAMP.unit is None + assert isinstance(telegram.P1_MESSAGE_TIMESTAMP.value, datetime.datetime) + assert telegram.P1_MESSAGE_TIMESTAMP.value == \ + pytz.timezone("Europe/Budapest").localize(datetime.datetime(2023, 7, 24, 15, 7, 30)) + + # LUXEMBOURG_EQUIPMENT_IDENTIFIER (0-0:42.0.0) + assert isinstance(telegram.LUXEMBOURG_EQUIPMENT_IDENTIFIER, CosemObject) + assert telegram.LUXEMBOURG_EQUIPMENT_IDENTIFIER.unit is None + assert isinstance(telegram.LUXEMBOURG_EQUIPMENT_IDENTIFIER.value, str) + assert telegram.LUXEMBOURG_EQUIPMENT_IDENTIFIER.value == '53414733303832323030303032313630' + + # EQUIPMENT_IDENTIFIER_GAS (0-0:96.1.0) + assert isinstance(telegram.EQUIPMENT_IDENTIFIER_GAS, CosemObject) + assert telegram.EQUIPMENT_IDENTIFIER_GAS.unit is None + assert isinstance(telegram.EQUIPMENT_IDENTIFIER_GAS.value, str) + assert telegram.EQUIPMENT_IDENTIFIER_GAS.value == '383930303832323030303032313630' + + # ELECTRICITY_ACTIVE_TARIFF (0-0:96.14.0) + assert isinstance(telegram.ELECTRICITY_ACTIVE_TARIFF, CosemObject) + assert telegram.ELECTRICITY_ACTIVE_TARIFF.unit is None + assert isinstance(telegram.ELECTRICITY_ACTIVE_TARIFF.value, str) + assert telegram.ELECTRICITY_ACTIVE_TARIFF.value == '0001' + + # ACTUAL_SWITCH_POSITION (0-0:96.3.10) + assert isinstance(telegram.ACTUAL_SWITCH_POSITION, CosemObject) + assert telegram.ACTUAL_SWITCH_POSITION.unit is None + assert isinstance(telegram.ACTUAL_SWITCH_POSITION.value, str) + assert telegram.ACTUAL_SWITCH_POSITION.value == '1' + + # BELGIUM_MAX_POWER_PER_PHASE (ACTUAL_TRESHOLD_ELECTRICITY) (0-0:17.0.0) + assert isinstance(telegram.BELGIUM_MAX_POWER_PER_PHASE, CosemObject) + assert telegram.BELGIUM_MAX_POWER_PER_PHASE.unit == 'kW' + assert isinstance(telegram.BELGIUM_MAX_POWER_PER_PHASE.value, Decimal) + assert telegram.BELGIUM_MAX_POWER_PER_PHASE.value == Decimal('90.000') + + # ELECTRICITY_IMPORTED_TOTAL (1-0:1.8.0) + assert isinstance(telegram.ELECTRICITY_IMPORTED_TOTAL, CosemObject) + assert telegram.ELECTRICITY_IMPORTED_TOTAL.unit == 'kWh' + assert isinstance(telegram.ELECTRICITY_IMPORTED_TOTAL.value, Decimal) + assert telegram.ELECTRICITY_IMPORTED_TOTAL.value == Decimal('000173.640') + + # ELECTRICITY_USED_TARIFF_1 (1-0:1.8.1) + assert isinstance(telegram.ELECTRICITY_USED_TARIFF_1, CosemObject) + assert telegram.ELECTRICITY_USED_TARIFF_1.unit == 'kWh' + assert isinstance(telegram.ELECTRICITY_USED_TARIFF_1.value, Decimal) + assert telegram.ELECTRICITY_USED_TARIFF_1.value == Decimal('000047.719') + + # ELECTRICITY_USED_TARIFF_2 (1-0:1.8.2) + assert isinstance(telegram.ELECTRICITY_USED_TARIFF_2, CosemObject) + assert telegram.ELECTRICITY_USED_TARIFF_2.unit == 'kWh' + assert isinstance(telegram.ELECTRICITY_USED_TARIFF_2.value, Decimal) + assert telegram.ELECTRICITY_USED_TARIFF_2.value == Decimal('000125.921') + + # EON_HU_ELECTRICITY_USED_TARIFF_3 (1-0:1.8.3) + assert isinstance(telegram.EON_HU_ELECTRICITY_USED_TARIFF_3, CosemObject) + assert telegram.EON_HU_ELECTRICITY_USED_TARIFF_3.unit == 'kWh' + assert isinstance(telegram.EON_HU_ELECTRICITY_USED_TARIFF_3.value, Decimal) + assert telegram.EON_HU_ELECTRICITY_USED_TARIFF_3.value == Decimal('000000.000') + + # EON_HU_ELECTRICITY_USED_TARIFF_4 (1-0:1.8.4) + assert isinstance(telegram.EON_HU_ELECTRICITY_USED_TARIFF_4, CosemObject) + assert telegram.EON_HU_ELECTRICITY_USED_TARIFF_4.unit == 'kWh' + assert isinstance(telegram.EON_HU_ELECTRICITY_USED_TARIFF_4.value, Decimal) + assert telegram.EON_HU_ELECTRICITY_USED_TARIFF_4.value == Decimal('000000.000') + + # ELECTRICITY_EXPORTED_TOTAL (1-0:2.8.0) + assert isinstance(telegram.ELECTRICITY_EXPORTED_TOTAL, CosemObject) + assert telegram.ELECTRICITY_EXPORTED_TOTAL.unit == 'kWh' + assert isinstance(telegram.ELECTRICITY_EXPORTED_TOTAL.value, Decimal) + assert telegram.ELECTRICITY_EXPORTED_TOTAL.value == Decimal('000627.177') + + # ELECTRICITY_DELIVERED_TARIFF_1 (1-0:2.8.1) + assert isinstance(telegram.ELECTRICITY_DELIVERED_TARIFF_1, CosemObject) + assert telegram.ELECTRICITY_DELIVERED_TARIFF_1.unit == 'kWh' + assert isinstance(telegram.ELECTRICITY_DELIVERED_TARIFF_1.value, Decimal) + assert telegram.ELECTRICITY_DELIVERED_TARIFF_1.value == Decimal('000401.829') + + # ELECTRICITY_DELIVERED_TARIFF_2 (1-0:2.8.2) + assert isinstance(telegram.ELECTRICITY_DELIVERED_TARIFF_2, CosemObject) + assert telegram.ELECTRICITY_DELIVERED_TARIFF_2.unit == 'kWh' + assert isinstance(telegram.ELECTRICITY_DELIVERED_TARIFF_2.value, Decimal) + assert telegram.ELECTRICITY_DELIVERED_TARIFF_2.value == Decimal('000225.348') + + # EON_HU_ELECTRICITY_DELIVERED_TARIFF_3 (1-0:2.8.3) + assert isinstance(telegram.EON_HU_ELECTRICITY_DELIVERED_TARIFF_3, CosemObject) + assert telegram.EON_HU_ELECTRICITY_DELIVERED_TARIFF_3.unit == 'kWh' + assert isinstance(telegram.EON_HU_ELECTRICITY_DELIVERED_TARIFF_3.value, Decimal) + assert telegram.EON_HU_ELECTRICITY_DELIVERED_TARIFF_3.value == Decimal('000000.000') + + # EON_HU_ELECTRICITY_DELIVERED_TARIFF_4 (1-0:2.8.4) + assert isinstance(telegram.EON_HU_ELECTRICITY_DELIVERED_TARIFF_4, CosemObject) + assert telegram.EON_HU_ELECTRICITY_DELIVERED_TARIFF_4.unit == 'kWh' + assert isinstance(telegram.EON_HU_ELECTRICITY_DELIVERED_TARIFF_4.value, Decimal) + assert telegram.EON_HU_ELECTRICITY_DELIVERED_TARIFF_4.value == Decimal('000000.000') + + # ELECTRICITY_REACTIVE_IMPORTED_TOTAL (1-0:3.8.0) + assert isinstance(telegram.ELECTRICITY_REACTIVE_IMPORTED_TOTAL, CosemObject) + assert telegram.ELECTRICITY_REACTIVE_IMPORTED_TOTAL.unit == 'kvarh' + assert isinstance(telegram.ELECTRICITY_REACTIVE_IMPORTED_TOTAL.value, Decimal) + assert telegram.ELECTRICITY_REACTIVE_IMPORTED_TOTAL.value == Decimal('000000.123') + + # ELECTRICITY_REACTIVE_EXPORTED_TOTAL (1-0:4.8.0) + assert isinstance(telegram.ELECTRICITY_REACTIVE_EXPORTED_TOTAL, CosemObject) + assert telegram.ELECTRICITY_REACTIVE_EXPORTED_TOTAL.unit == 'kvarh' + assert isinstance(telegram.ELECTRICITY_REACTIVE_EXPORTED_TOTAL.value, Decimal) + assert telegram.ELECTRICITY_REACTIVE_EXPORTED_TOTAL.value == Decimal('000303.131') + + # EON_HU_ELECTRICITY_REACTIVE_TOTAL_Q1 (1-0:5.8.0) + assert isinstance(telegram.EON_HU_ELECTRICITY_REACTIVE_TOTAL_Q1, CosemObject) + assert telegram.EON_HU_ELECTRICITY_REACTIVE_TOTAL_Q1.unit == 'kvarh' + assert isinstance(telegram.EON_HU_ELECTRICITY_REACTIVE_TOTAL_Q1.value, Decimal) + assert telegram.EON_HU_ELECTRICITY_REACTIVE_TOTAL_Q1.value == Decimal('000000.668') + + # EON_HU_ELECTRICITY_REACTIVE_TOTAL_Q2 (1-0:6.8.0) + assert isinstance(telegram.EON_HU_ELECTRICITY_REACTIVE_TOTAL_Q2, CosemObject) + assert telegram.EON_HU_ELECTRICITY_REACTIVE_TOTAL_Q2.unit == 'kvarh' + assert isinstance(telegram.EON_HU_ELECTRICITY_REACTIVE_TOTAL_Q2.value, Decimal) + assert telegram.EON_HU_ELECTRICITY_REACTIVE_TOTAL_Q2.value == Decimal('000000.071') + + # EON_HU_ELECTRICITY_REACTIVE_TOTAL_Q3 (1-0:7.8.0) + assert isinstance(telegram.EON_HU_ELECTRICITY_REACTIVE_TOTAL_Q3, CosemObject) + assert telegram.EON_HU_ELECTRICITY_REACTIVE_TOTAL_Q3.unit == 'kvarh' + assert isinstance(telegram.EON_HU_ELECTRICITY_REACTIVE_TOTAL_Q3.value, Decimal) + assert telegram.EON_HU_ELECTRICITY_REACTIVE_TOTAL_Q3.value == Decimal('000160.487') + + # EON_HU_ELECTRICITY_REACTIVE_TOTAL_Q4 (1-0:8.8.0) + assert isinstance(telegram.EON_HU_ELECTRICITY_REACTIVE_TOTAL_Q4, CosemObject) + assert telegram.EON_HU_ELECTRICITY_REACTIVE_TOTAL_Q4.unit == 'kvarh' + assert isinstance(telegram.EON_HU_ELECTRICITY_REACTIVE_TOTAL_Q4.value, Decimal) + assert telegram.EON_HU_ELECTRICITY_REACTIVE_TOTAL_Q4.value == Decimal('000143.346') + + # EON_HU_ELECTRICITY_COMBINED (1-0:15.8.0) + assert isinstance(telegram.EON_HU_ELECTRICITY_COMBINED, CosemObject) + assert telegram.EON_HU_ELECTRICITY_COMBINED.unit == 'kWh' + assert isinstance(telegram.EON_HU_ELECTRICITY_COMBINED.value, Decimal) + assert telegram.EON_HU_ELECTRICITY_COMBINED.value == Decimal('000800.817') + + # INSTANTANEOUS_VOLTAGE_L2 (1-0:32.7.0) + assert isinstance(telegram.INSTANTANEOUS_VOLTAGE_L1, CosemObject) + assert telegram.INSTANTANEOUS_VOLTAGE_L1.unit == 'V' + assert isinstance(telegram.INSTANTANEOUS_VOLTAGE_L1.value, Decimal) + assert telegram.INSTANTANEOUS_VOLTAGE_L1.value == Decimal('240.4') + + # INSTANTANEOUS_VOLTAGE_L2 (1-0:52.7.0) + assert isinstance(telegram.INSTANTANEOUS_VOLTAGE_L2, CosemObject) + assert telegram.INSTANTANEOUS_VOLTAGE_L2.unit == 'V' + assert isinstance(telegram.INSTANTANEOUS_VOLTAGE_L2.value, Decimal) + assert telegram.INSTANTANEOUS_VOLTAGE_L2.value == Decimal('239.1') + + # INSTANTANEOUS_VOLTAGE_L3 (1-0:72.7.0) + assert isinstance(telegram.INSTANTANEOUS_VOLTAGE_L3, CosemObject) + assert telegram.INSTANTANEOUS_VOLTAGE_L3.unit == 'V' + assert isinstance(telegram.INSTANTANEOUS_VOLTAGE_L3.value, Decimal) + assert telegram.INSTANTANEOUS_VOLTAGE_L3.value == Decimal('241.2') + + # INSTANTANEOUS_CURRENT_L1 (1-0:31.7.0) + assert isinstance(telegram.INSTANTANEOUS_CURRENT_L1, CosemObject) + assert telegram.INSTANTANEOUS_CURRENT_L1.unit == 'A' + assert isinstance(telegram.INSTANTANEOUS_CURRENT_L1.value, Decimal) + assert telegram.INSTANTANEOUS_CURRENT_L1.value == Decimal('003') + + # INSTANTANEOUS_CURRENT_L2 (1-0:51.7.0) + assert isinstance(telegram.INSTANTANEOUS_CURRENT_L2, CosemObject) + assert telegram.INSTANTANEOUS_CURRENT_L2.unit == 'A' + assert isinstance(telegram.INSTANTANEOUS_CURRENT_L2.value, Decimal) + assert telegram.INSTANTANEOUS_CURRENT_L2.value == Decimal('004') + + # INSTANTANEOUS_CURRENT_L3 (1-0:71.7.0) + assert isinstance(telegram.INSTANTANEOUS_CURRENT_L3, CosemObject) + assert telegram.INSTANTANEOUS_CURRENT_L3.unit == 'A' + assert isinstance(telegram.INSTANTANEOUS_CURRENT_L3.value, Decimal) + assert telegram.INSTANTANEOUS_CURRENT_L3.value == Decimal('003') + + # EON_HU_INSTANTANEOUS_POWER_FACTOR_TOTAL (1-0:13.7.0) + assert isinstance(telegram.EON_HU_INSTANTANEOUS_POWER_FACTOR_TOTAL, CosemObject) + assert telegram.EON_HU_INSTANTANEOUS_POWER_FACTOR_TOTAL.unit is None + assert isinstance(telegram.EON_HU_INSTANTANEOUS_POWER_FACTOR_TOTAL.value, Decimal) + assert telegram.EON_HU_INSTANTANEOUS_POWER_FACTOR_TOTAL.value == Decimal('4.556') + + # EON_HU_INSTANTANEOUS_POWER_FACTOR_L1 (1-0:33.7.0) + assert isinstance(telegram.EON_HU_INSTANTANEOUS_POWER_FACTOR_L1, CosemObject) + assert telegram.EON_HU_INSTANTANEOUS_POWER_FACTOR_L1.unit is None + assert isinstance(telegram.EON_HU_INSTANTANEOUS_POWER_FACTOR_L1.value, Decimal) + assert telegram.EON_HU_INSTANTANEOUS_POWER_FACTOR_L1.value == Decimal('4.591') + + # EON_HU_INSTANTANEOUS_POWER_FACTOR_L2 (1-0:53.7.0) + assert isinstance(telegram.EON_HU_INSTANTANEOUS_POWER_FACTOR_L2, CosemObject) + assert telegram.EON_HU_INSTANTANEOUS_POWER_FACTOR_L2.unit is None + assert isinstance(telegram.EON_HU_INSTANTANEOUS_POWER_FACTOR_L2.value, Decimal) + assert telegram.EON_HU_INSTANTANEOUS_POWER_FACTOR_L2.value == Decimal('4.542') + + # EON_HU_INSTANTANEOUS_POWER_FACTOR_L3 (1-0:73.7.0) + assert isinstance(telegram.EON_HU_INSTANTANEOUS_POWER_FACTOR_L3, CosemObject) + assert telegram.EON_HU_INSTANTANEOUS_POWER_FACTOR_L3.unit is None + assert isinstance(telegram.EON_HU_INSTANTANEOUS_POWER_FACTOR_L3.value, Decimal) + assert telegram.EON_HU_INSTANTANEOUS_POWER_FACTOR_L3.value == Decimal('4.552') + + # EON_HU_FREQUENCY (1-0:14.7.0) + assert isinstance(telegram.EON_HU_FREQUENCY, CosemObject) + assert telegram.EON_HU_FREQUENCY.unit == "Hz" + assert isinstance(telegram.EON_HU_FREQUENCY.value, Decimal) + assert telegram.EON_HU_FREQUENCY.value == Decimal('50.00') + + # CURRENT_ELECTRICITY_USAGE (1-0:1.7.0) + assert isinstance(telegram.CURRENT_ELECTRICITY_USAGE, CosemObject) + assert telegram.CURRENT_ELECTRICITY_USAGE.unit == 'kW' + assert isinstance(telegram.CURRENT_ELECTRICITY_USAGE.value, Decimal) + assert telegram.CURRENT_ELECTRICITY_USAGE.value == Decimal('00.000') + + # CURRENT_ELECTRICITY_DELIVERY (1-0:2.7.0) + assert isinstance(telegram.CURRENT_ELECTRICITY_DELIVERY, CosemObject) + assert telegram.CURRENT_ELECTRICITY_DELIVERY.unit == 'kW' + assert isinstance(telegram.CURRENT_ELECTRICITY_DELIVERY.value, Decimal) + assert telegram.CURRENT_ELECTRICITY_DELIVERY.value == Decimal('02.601') + + # EON_HU_INSTANTANEOUS_REACTIVE_POWER_Q1 (1-0:5.7.0) + assert isinstance(telegram.EON_HU_INSTANTANEOUS_REACTIVE_POWER_Q1, CosemObject) + assert telegram.EON_HU_INSTANTANEOUS_REACTIVE_POWER_Q1.unit == 'kvar' + assert isinstance(telegram.EON_HU_INSTANTANEOUS_REACTIVE_POWER_Q1.value, Decimal) + assert telegram.EON_HU_INSTANTANEOUS_REACTIVE_POWER_Q1.value == Decimal('00.000') + + # EON_HU_INSTANTANEOUS_REACTIVE_POWER_Q2 (1-0:6.7.0) + assert isinstance(telegram.EON_HU_INSTANTANEOUS_REACTIVE_POWER_Q2, CosemObject) + assert telegram.EON_HU_INSTANTANEOUS_REACTIVE_POWER_Q2.unit == 'kvar' + assert isinstance(telegram.EON_HU_INSTANTANEOUS_REACTIVE_POWER_Q2.value, Decimal) + assert telegram.EON_HU_INSTANTANEOUS_REACTIVE_POWER_Q2.value == Decimal('00.000') + + # EON_HU_INSTANTANEOUS_REACTIVE_POWER_Q3 (1-0:7.7.0) + assert isinstance(telegram.EON_HU_INSTANTANEOUS_REACTIVE_POWER_Q3, CosemObject) + assert telegram.EON_HU_INSTANTANEOUS_REACTIVE_POWER_Q3.unit == 'kvar' + assert isinstance(telegram.EON_HU_INSTANTANEOUS_REACTIVE_POWER_Q3.value, Decimal) + assert telegram.EON_HU_INSTANTANEOUS_REACTIVE_POWER_Q3.value == Decimal('00.504') + + # EON_HU_INSTANTANEOUS_REACTIVE_POWER_Q4 (1-0:8.7.0) + assert isinstance(telegram.EON_HU_INSTANTANEOUS_REACTIVE_POWER_Q4, CosemObject) + assert telegram.EON_HU_INSTANTANEOUS_REACTIVE_POWER_Q4.unit == 'kvar' + assert isinstance(telegram.EON_HU_INSTANTANEOUS_REACTIVE_POWER_Q4.value, Decimal) + assert telegram.EON_HU_INSTANTANEOUS_REACTIVE_POWER_Q4.value == Decimal('00.000') + + # EON_HU_MAX_POWER_ON_L1 (1-0:31.4.0) + assert isinstance(telegram.EON_HU_MAX_POWER_ON_L1, CosemObject) + assert telegram.EON_HU_MAX_POWER_ON_L1.unit == 'A' + assert isinstance(telegram.EON_HU_MAX_POWER_ON_L1.value, Decimal) + assert telegram.EON_HU_MAX_POWER_ON_L1.value == Decimal('200.00') + + # EON_HU_MAX_POWER_ON_L2 (1-0:31.4.0) + assert isinstance(telegram.EON_HU_MAX_POWER_ON_L2, CosemObject) + assert telegram.EON_HU_MAX_POWER_ON_L2.unit == 'A' + assert isinstance(telegram.EON_HU_MAX_POWER_ON_L2.value, Decimal) + assert telegram.EON_HU_MAX_POWER_ON_L2.value == Decimal('200.00') + + # EON_HU_MAX_POWER_ON_L3 (1-0:31.4.0) + assert isinstance(telegram.EON_HU_MAX_POWER_ON_L3, CosemObject) + assert telegram.EON_HU_MAX_POWER_ON_L3.unit == 'A' + assert isinstance(telegram.EON_HU_MAX_POWER_ON_L3.value, Decimal) + assert telegram.EON_HU_MAX_POWER_ON_L3.value == Decimal('200.00') + + # TEXT_MESSAGE (0-0:96.13.0) + assert isinstance(telegram.TEXT_MESSAGE, CosemObject) + assert telegram.TEXT_MESSAGE.unit is None + assert telegram.TEXT_MESSAGE.value is None + + def test_checksum_valid(self): + # No exception is raised. + TelegramParser.validate_checksum(TELEGRAM_V5_EON_HU) + + def test_checksum_invalid(self): + # Remove the electricty used data value. This causes the checksum to + # not match anymore. + corrupted_telegram = TELEGRAM_V5_EON_HU.replace( + '1-0:1.8.1(000047.719*kWh)\r\n', + '' + ) + + with self.assertRaises(InvalidChecksumError): + TelegramParser.validate_checksum(corrupted_telegram) + + def test_checksum_missing(self): + # Remove the checksum value causing a ParseError. + corrupted_telegram = TELEGRAM_V5_EON_HU.replace('!99DA\r\n', '') + with self.assertRaises(ParseError): + TelegramParser.validate_checksum(corrupted_telegram)