Skip to content

Commit

Permalink
refactor: Add control code constants for V5 HEARTBEAT
Browse files Browse the repository at this point in the history
  • Loading branch information
davidrapan committed Dec 19, 2024
1 parent 24ce03f commit 1385c65
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 2 additions & 2 deletions custom_components/solarman/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ async def _heartbeat_response(self, request_frame):
v5_frame = bytearray(
self.v5_start
+ struct.pack("<H", 10)
+ struct.pack("<H", 0x1710)
+ CONTROL_CODE.HEARTBEAT_RESPONSE
+ request_frame[5:6]
+ self.v5_loggerserial
+ struct.pack("<H", 0x0100)
Expand Down Expand Up @@ -102,7 +102,7 @@ def _received_frame_is_valid(self, frame):
if frame[5] != self.sequence_number:
self.log.debug("[%s] V5_SEQ_NO_MISMATCH: %s", self.serial, frame.hex(" "))
return False
if frame.startswith(self.v5_start + b"\x01\x00\x10\x47"):
if frame.startswith(self.v5_start + CONTROL_CODE.HEARTBEAT):
self.log.debug("[%s] V5_HEARTBEAT: %s", self.serial, frame.hex(" "))
asyncio.ensure_future(self._heartbeat_response(frame))
return False
Expand Down
2 changes: 2 additions & 0 deletions custom_components/solarman/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@
CONTROL_CODE = types.SimpleNamespace()
CONTROL_CODE.REQUEST = struct.pack("<H", 0x4510)
CONTROL_CODE.RESPONSE = struct.pack("<H", 0x1510)
CONTROL_CODE.HEARTBEAT = struct.pack("<I", 0x47100001)
CONTROL_CODE.HEARTBEAT_RESPONSE = struct.pack("<H", 0x1710)

AUTO_RECONNECT = True

Expand Down

0 comments on commit 1385c65

Please sign in to comment.