Skip to content

Commit

Permalink
add unit test for parsing of extended registers
Browse files Browse the repository at this point in the history
  • Loading branch information
raymar9 committed Jul 8, 2024
1 parent 49c1ce0 commit b4f9d62
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
13 changes: 13 additions & 0 deletions tests/test_hdlc_dlms_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
10 changes: 10 additions & 0 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit b4f9d62

Please sign in to comment.