diff --git a/goodwe/protocol.py b/goodwe/protocol.py index d8d6a33..653ab4c 100644 --- a/goodwe/protocol.py +++ b/goodwe/protocol.py @@ -127,7 +127,7 @@ def datagram_received(self, data: bytes, addr: Tuple[str, int]) -> None: self._timer = None try: if self._partial_data and self._partial_missing == len(data): - logger.debug("Composed fragmented response: %s", data.hex()) + logger.debug("Composed fragmented response: %s + %s", self._partial_data.hex(), data.hex()) data = self._partial_data + data self._partial_data = None self._partial_missing = 0 @@ -141,7 +141,6 @@ def datagram_received(self, data: bytes, addr: Tuple[str, int]) -> None: logger.debug("Received response fragment (%d of %d): %s", ex.length, ex.expected, data.hex()) self._partial_data = data self._partial_missing = ex.expected - ex.length - return except asyncio.InvalidStateError: logger.debug("Response already handled: %s", data.hex()) except RequestRejectedException as ex: @@ -161,7 +160,6 @@ async def send_request(self, command: ProtocolCommand) -> Future: await self._connect() response_future = asyncio.get_running_loop().create_future() self._retry = 0 - self._partial_data = None self._send_request(command, response_future) await response_future return response_future @@ -170,6 +168,8 @@ def _send_request(self, command: ProtocolCommand, response_future: Future) -> No """Send message via transport""" self.command = command self.response_future = response_future + self._partial_data = None + self._partial_missing = 0 payload = command.request_bytes() if self._retry > 0: logger.debug("Sending: %s - retry #%s/%s", self.command, self._retry, self.retries) @@ -268,7 +268,7 @@ def data_received(self, data: bytes) -> None: self._timer.cancel() try: if self._partial_data and self._partial_missing == len(data): - logger.debug("Composed fragmented response: %s", data.hex()) + logger.debug("Composed fragmented response: %s + %s", self._partial_data.hex(), data.hex()) data = self._partial_data + data self._partial_data = None self._partial_missing = 0 @@ -284,7 +284,6 @@ def data_received(self, data: bytes) -> None: logger.debug("Received response fragment (%d of %d): %s", ex.length, ex.expected, data.hex()) self._partial_data = data self._partial_missing = ex.expected - ex.length - return except asyncio.InvalidStateError: logger.debug("Response already handled: %s", data.hex()) except RequestRejectedException as ex: @@ -304,7 +303,6 @@ async def send_request(self, command: ProtocolCommand) -> Future: try: await asyncio.wait_for(self._connect(), timeout=5) response_future = asyncio.get_running_loop().create_future() - self._partial_data = None self._send_request(command, response_future) await response_future return response_future @@ -336,6 +334,8 @@ def _send_request(self, command: ProtocolCommand, response_future: Future) -> No """Send message via transport""" self.command = command self.response_future = response_future + self._partial_data = None + self._partial_missing = 0 payload = command.request_bytes() if self._retry > 0: logger.debug("Sending: %s - retry #%s/%s", self.command, self._retry, self.retries)