From b4f9d62b17451e28c0ebecbe7d85d67575ef079e Mon Sep 17 00:00:00 2001 From: Mario Coray Date: Mon, 8 Jul 2024 12:01:38 +0200 Subject: [PATCH] add unit test for parsing of extended registers --- tests/test_hdlc_dlms_parser.py | 13 +++++++++++++ tests/utils.py | 10 ++++++++++ 2 files changed, 23 insertions(+) diff --git a/tests/test_hdlc_dlms_parser.py b/tests/test_hdlc_dlms_parser.py index 76f843a..8471c29 100644 --- a/tests/test_hdlc_dlms_parser.py +++ b/tests/test_hdlc_dlms_parser.py @@ -81,6 +81,19 @@ def test_ignore_not_parsable_data_to_meter_data(self, unencrypted_invalid_data_l assert isinstance(meter_data, list) assert len(meter_data) == 5 + def test_parse_dlms_data_with_extended_registers(self, unencrypted_extended_register_data: List[bytes]): + cosem = Cosem("fallbackId", register_obis_extended=[RegisterCosem( + # this is not the correct MeterDataPointType for this OBIS code (just for testing) + OBISCode(0, 1, 24, 2, 1, 255), MeterDataPointTypes.ACTIVE_POWER_N.value)]) + + parser = prepare_parser(unencrypted_extended_register_data, cosem) + dlms_objects = parser.parse_to_dlms_objects() + meter_data = parser.convert_dlms_bundle_to_reader_data(dlms_objects) + + assert isinstance(meter_data, list) + assert len(meter_data) == 1 + assert meter_data[0].value == 30545 + class TestDlmsParserEncrypted: def test_hdlc_to_dlms_objects_without_pushlist(self, encrypted_data_no_pushlist_lg: List[bytes], cosem_config_lg: Cosem): diff --git a/tests/utils.py b/tests/utils.py index 4e69c25..1127317 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -96,3 +96,13 @@ def encrypted_data_no_pushlist_lg() -> List[bytes]: "7E A0 30 CE FF 03 13 86 F8 E0 C0 00 03 00 00 1F 1F FE C7 27 11 0F 74 B7 EF F4 1B 48 F7 47 B6 B6 A2 39 5B 42 BD 61 EA 18 7E D9 A0 99 8B 81 45 44 78 7E") data = list(map(lambda frag: bytes.fromhex(frag.replace(" ", "")), data_str)) return data + + +@pytest.fixture +def unencrypted_extended_register_data() -> List[bytes]: + data_str: List[str] = [] + data_str.append("7E A0 84 CE FF 03 13 12 8B E6 E7 00 E0 40 00 01 00 00 70 0F 00 04 15 7A 0C 07 E8 06 0B 02 10 00 00 FF 80 00 00 02 0A 01 0A 02 04 12 00 28 09 06 00 0B 19 09 00 FF 0F 02 12 00 00 02 04 12 00 28 09 06 00 0B 19 09 00 FF 0F 01 12 00 00 02 04 12 00 01 09 06 00 01 60 01 00 FF 0F 02 12 00 00 02 04 12 00 01 09 06 00 02 60 01 00 FF 0F 02 12 00 00 02 04 12 00 01 09 06 00 03 60 01 00 FF 0F 02 12 00 00 EB F5 7E") + data_str.append("7E A0 86 CE FF 03 13 9A 9D E0 40 00 02 00 00 75 02 04 12 00 01 09 06 00 04 60 01 00 FF 0F 02 12 00 00 02 04 12 00 04 09 06 00 01 18 02 01 FF 0F 02 12 00 00 02 04 12 00 04 09 06 00 02 18 02 01 FF 0F 02 12 00 00 02 04 12 00 04 09 06 00 03 18 02 01 FF 0F 02 12 00 00 02 04 12 00 04 09 06 00 04 18 02 01 FF 0F 02 12 00 00 09 06 00 0B 19 09 00 FF 09 08 32 34 35 32 31 36 36 32 09 01 00 09 01 00 09 01 00 C4 FD 7E") + data_str.append("7E A0 25 CE FF 03 13 92 6A E0 C0 00 03 00 00 14 05 00 00 77 51 05 00 00 00 00 05 00 00 00 00 05 00 00 00 00 87 59 7E") + data = list(map(lambda frag: bytes.fromhex(frag.replace(" ", "")), data_str)) + return data