Skip to content

Commit

Permalink
refactor: Not standard following sticks compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
davidrapan committed Dec 12, 2024
1 parent 00e7019 commit 800cd90
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion custom_components/solarman/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def __init__(self, address, serial, port, mb_slave_id):
self._passthrough = False

async def _tcp_send_receive_frame(self, mb_request_frame):
return mb_response_adu if (l := len(mb_response_adu := await self._send_receive_v5_frame(mb_request_frame))) and not 8 <= l <= 10 else mb_response_adu + b_(b'\x00\x01', 10 - l)
return mb_compatibility(await self._send_receive_v5_frame(mb_request_frame), mb_request_frame)

async def _tcp_parse_response_adu(self, mb_request_frame):
return parse_response_adu(await self._tcp_send_receive_frame(mb_request_frame), mb_request_frame)
Expand Down
4 changes: 2 additions & 2 deletions custom_components/solarman/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ def is_ethernet_frame(frame):
return int.from_bytes(frame[5:6], byteorder = "big") == len(frame[6:])
return False

def b_(suffix, count):
return b'\x00' * count + suffix
def mb_compatibility(response, request):
return response if not 8 <= (l := len(response)) <= 10 else response[:5] + b'\x06' + response[6:] + (request[l:10] if len(request) > 12 else (b'\x00' * (10 - l))) + b'\x00\x01'

def format_exception(e):
return re.sub(r"\s+", " ", f"{type(e).__name__}{f': {e}' if f'{e}' else ''}")
Expand Down

0 comments on commit 800cd90

Please sign in to comment.