Skip to content

Commit

Permalink
5c checksum fix
Browse files Browse the repository at this point in the history
  • Loading branch information
yozik04 committed Apr 27, 2022
1 parent e2b6dad commit ace8104
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion nibe/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.0.2"
__version__ = "0.0.3"
7 changes: 5 additions & 2 deletions nibe/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions tests/test_message_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit ace8104

Please sign in to comment.