Skip to content

Commit

Permalink
Add debug for read and write
Browse files Browse the repository at this point in the history
  • Loading branch information
golles committed Dec 2, 2023
1 parent 843a8c7 commit e31ba8e
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions custom_components/kamstrup_403/pykamstrup/kamstrup.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,16 @@ def _crc_1021(cls, message: tuple[int]) -> int:
reg ^= poly
return reg

def _debug(self, msg: str, byte_array: bytearray):
log = f"{msg}:"
for byte in byte_array:
log += f" {byte:02x}"
_LOGGER.debug(log)

def _write(self, data: tuple[int]):
"""Write directly to the meter"""
bytearray_data = bytearray(data)
self._debug("Write", bytearray_data)
self.ser.write(bytearray_data)

def _read(self) -> int | None:
Expand All @@ -54,6 +61,7 @@ def _read(self) -> int | None:
_LOGGER.debug("Rx Timeout")
return None
bytearray_data = bytearray(data)
self._debug("Read", bytearray((bytearray_data)))
return bytearray_data[0]

def _send(self, pfx: int, message: tuple[int]):
Expand Down

0 comments on commit e31ba8e

Please sign in to comment.