From 0d1a971698a989998c73e4ebad5981ec8dda102e Mon Sep 17 00:00:00 2001 From: Dennis Siemensma Date: Wed, 1 Feb 2023 21:47:29 +0100 Subject: [PATCH] Restore DSMR-reader fix for CRC hex in favor of developing --- dsmr_parser/parsers.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/dsmr_parser/parsers.py b/dsmr_parser/parsers.py index 554e1547f..9fdb9fcc4 100644 --- a/dsmr_parser/parsers.py +++ b/dsmr_parser/parsers.py @@ -151,11 +151,16 @@ def validate_checksum(telegram): calculated_crc = TelegramParser.crc16(checksum_contents.group(0)) expected_crc = int(checksum_hex.group(0), base=16) + # @TODO DSMR-reader additions. Should eventually be pushed upstream. + calculated_crc_hex = "{:0>4}".format(hex(calculated_crc)[2:].upper()) + expected_crc_hex = "{:0>4}".format(hex(expected_crc)[2:].upper()) if calculated_crc != expected_crc: raise InvalidChecksumError( - "Invalid telegram. The CRC checksum '{}' does not match the " - "expected '{}'".format(calculated_crc, expected_crc) + "Invalid telegram CRC. The calculated checksum '{}' ({}) does not match the " + "telegram checksum '{}' ({})".format( + calculated_crc, calculated_crc_hex, expected_crc, expected_crc_hex + ) ) @staticmethod