From ace810496baad105f03e892ba0c95e289bdddabd Mon Sep 17 00:00:00 2001 From: Jevgeni Kiski Date: Wed, 27 Apr 2022 23:25:27 +0300 Subject: [PATCH] 5c checksum fix --- nibe/__init__.py | 2 +- nibe/parsers.py | 7 +++++-- tests/test_message_parsing.py | 6 ++++++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/nibe/__init__.py b/nibe/__init__.py index 3b93d0b..27fdca4 100644 --- a/nibe/__init__.py +++ b/nibe/__init__.py @@ -1 +1 @@ -__version__ = "0.0.2" +__version__ = "0.0.3" diff --git a/nibe/parsers.py b/nibe/parsers.py index e98f6ed..82f6581 100644 --- a/nibe/parsers.py +++ b/nibe/parsers.py @@ -5,8 +5,11 @@ Int16ul, RawCopy, Struct, Switch, this,) -def xor8(data: bytes): - return reduce(xor, data) +def xor8(data: bytes) -> int: + chksum = reduce(xor, data) + if chksum == 0x5c: + chksum = 0xc5 + return chksum # fmt: off diff --git a/tests/test_message_parsing.py b/tests/test_message_parsing.py index f00ba48..850fa81 100644 --- a/tests/test_message_parsing.py +++ b/tests/test_message_parsing.py @@ -20,6 +20,12 @@ def test_parse_read_response_with_wrong_crc(self): ChecksumError, self._parse_hexlified_raw_message, "5c00206a060cb901000000f9" ) + def test_parse_multiple_5c_checksum(self): + data = self._parse_hexlified_raw_message("5c00206850449c2d00489cf4014c9c56014d9cf8014e9cc4014f9c4b00509c2800619cef00fda700004ea80a0080a80000ada90000afa9000004bc000067be0000a3b7010063befd006d9cf8006e9cff00eeacc800c5") + self.assertEqual(data.address, "MODBUS40") + self.assertEqual(data.cmd, "MODBUS_DATA_MSG") + self.assertIsInstance(data.data, list) + def test_parse_multiple_read_request(self): data = self._parse_hexlified_raw_message( "5c00206850449c9600489c49014c9c21014d9cb4014e9c8d014f9c2401509c0d01619ce400fda700004ea80"