goodwe 0.4.3__tar.gz → 0.4.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. {goodwe-0.4.3/goodwe.egg-info → goodwe-0.4.4}/PKG-INFO +1 -1
  2. goodwe-0.4.4/VERSION +1 -0
  3. {goodwe-0.4.3 → goodwe-0.4.4}/goodwe/modbus.py +7 -6
  4. {goodwe-0.4.3 → goodwe-0.4.4}/goodwe/protocol.py +21 -20
  5. {goodwe-0.4.3 → goodwe-0.4.4/goodwe.egg-info}/PKG-INFO +1 -1
  6. goodwe-0.4.3/VERSION +0 -1
  7. {goodwe-0.4.3 → goodwe-0.4.4}/LICENSE +0 -0
  8. {goodwe-0.4.3 → goodwe-0.4.4}/README.md +0 -0
  9. {goodwe-0.4.3 → goodwe-0.4.4}/goodwe/__init__.py +0 -0
  10. {goodwe-0.4.3 → goodwe-0.4.4}/goodwe/const.py +0 -0
  11. {goodwe-0.4.3 → goodwe-0.4.4}/goodwe/dt.py +0 -0
  12. {goodwe-0.4.3 → goodwe-0.4.4}/goodwe/es.py +0 -0
  13. {goodwe-0.4.3 → goodwe-0.4.4}/goodwe/et.py +0 -0
  14. {goodwe-0.4.3 → goodwe-0.4.4}/goodwe/exceptions.py +0 -0
  15. {goodwe-0.4.3 → goodwe-0.4.4}/goodwe/inverter.py +0 -0
  16. {goodwe-0.4.3 → goodwe-0.4.4}/goodwe/model.py +0 -0
  17. {goodwe-0.4.3 → goodwe-0.4.4}/goodwe/sensor.py +0 -0
  18. {goodwe-0.4.3 → goodwe-0.4.4}/goodwe.egg-info/SOURCES.txt +0 -0
  19. {goodwe-0.4.3 → goodwe-0.4.4}/goodwe.egg-info/dependency_links.txt +0 -0
  20. {goodwe-0.4.3 → goodwe-0.4.4}/goodwe.egg-info/top_level.txt +0 -0
  21. {goodwe-0.4.3 → goodwe-0.4.4}/pyproject.toml +0 -0
  22. {goodwe-0.4.3 → goodwe-0.4.4}/setup.cfg +0 -0
  23. {goodwe-0.4.3 → goodwe-0.4.4}/tests/test_dt.py +0 -0
  24. {goodwe-0.4.3 → goodwe-0.4.4}/tests/test_es.py +0 -0
  25. {goodwe-0.4.3 → goodwe-0.4.4}/tests/test_et.py +0 -0
  26. {goodwe-0.4.3 → goodwe-0.4.4}/tests/test_modbus.py +0 -0
  27. {goodwe-0.4.3 → goodwe-0.4.4}/tests/test_protocol.py +0 -0
  28. {goodwe-0.4.3 → goodwe-0.4.4}/tests/test_sensor.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: goodwe
3
- Version: 0.4.3
3
+ Version: 0.4.4
4
4
  Summary: Read data from GoodWe inverter via local network
5
5
  Home-page: https://github.com/marcelblijleven/goodwe
6
6
  Author: Martin Letenay, Marcel Blijleven
goodwe-0.4.4/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.4.4
@@ -221,10 +221,11 @@ def validate_modbus_tcp_response(data: bytes, cmd: int, offset: int, value: int)
221
221
  if len(data) <= 8:
222
222
  logger.debug("Response is too short.")
223
223
  return False
224
- expected_length = int.from_bytes(data[4:6], byteorder='big', signed=False) + 6
225
- # The weird expected_length != 12 is work around Goodwe bug answering wrong (hardcoded 6) length.
226
- if len(data) < expected_length and expected_length != 12:
227
- raise PartialResponseException(len(data), expected_length)
224
+
225
+ # The Modbus/TCP message length check is completely ignore due to Goodwe bugs
226
+ # expected_length = int.from_bytes(data[4:6], byteorder='big', signed=False) + 6
227
+ # if len(data) < expected_length:
228
+ # raise PartialResponseException(len(data), expected_length)
228
229
 
229
230
  if data[7] == MODBUS_READ_CMD:
230
231
  expected_length = data[8] + 9
@@ -235,8 +236,8 @@ def validate_modbus_tcp_response(data: bytes, cmd: int, offset: int, value: int)
235
236
  return False
236
237
  elif data[7] in (MODBUS_WRITE_CMD, MODBUS_WRITE_MULTI_CMD):
237
238
  if len(data) < 12:
238
- logger.debug("Response has unexpected length: %d, expected %d.", len(data), 14)
239
- raise PartialResponseException(len(data), expected_length)
239
+ logger.debug("Response has unexpected length: %d, expected %d.", len(data), 12)
240
+ return False
240
241
  response_offset = int.from_bytes(data[8:10], byteorder='big', signed=False)
241
242
  if response_offset != offset:
242
243
  logger.debug("Response has wrong offset: %X, expected %X.", response_offset, offset)
@@ -42,6 +42,7 @@ class InverterProtocol:
42
42
  self.response_future: Future | None = None
43
43
  self.command: ProtocolCommand | None = None
44
44
  self._partial_data: bytes | None = None
45
+ self._partial_missing: int = 0
45
46
 
46
47
  def _ensure_lock(self) -> asyncio.Lock:
47
48
  """Validate (or create) asyncio Lock.
@@ -125,23 +126,21 @@ class UdpInverterProtocol(InverterProtocol, asyncio.DatagramProtocol):
125
126
  self._timer.cancel()
126
127
  self._timer = None
127
128
  try:
128
- if self._partial_data:
129
- logger.debug("Received another response fragment: %s.", data.hex())
129
+ if self._partial_data and self._partial_missing == len(data):
130
+ logger.debug("Composed fragmented response: %s + %s", self._partial_data.hex(), data.hex())
130
131
  data = self._partial_data + data
131
- if self.command.validator(data):
132
- if self._partial_data:
133
- logger.debug("Composed fragmented response: %s", data.hex())
134
- else:
135
- logger.debug("Received: %s", data.hex())
136
132
  self._partial_data = None
133
+ self._partial_missing = 0
134
+ if self.command.validator(data):
135
+ logger.debug("Received: %s", data.hex())
137
136
  self.response_future.set_result(data)
138
137
  else:
139
138
  logger.debug("Received invalid response: %s", data.hex())
140
139
  asyncio.get_running_loop().call_soon(self._retry_mechanism)
141
- except PartialResponseException:
142
- logger.debug("Received response fragment: %s", data.hex())
140
+ except PartialResponseException as ex:
141
+ logger.debug("Received response fragment (%d of %d): %s", ex.length, ex.expected, data.hex())
143
142
  self._partial_data = data
144
- return
143
+ self._partial_missing = ex.expected - ex.length
145
144
  except asyncio.InvalidStateError:
146
145
  logger.debug("Response already handled: %s", data.hex())
147
146
  except RequestRejectedException as ex:
@@ -169,6 +168,8 @@ class UdpInverterProtocol(InverterProtocol, asyncio.DatagramProtocol):
169
168
  """Send message via transport"""
170
169
  self.command = command
171
170
  self.response_future = response_future
171
+ self._partial_data = None
172
+ self._partial_missing = 0
172
173
  payload = command.request_bytes()
173
174
  if self._retry > 0:
174
175
  logger.debug("Sending: %s - retry #%s/%s", self.command, self._retry, self.retries)
@@ -266,25 +267,23 @@ class TcpInverterProtocol(InverterProtocol, asyncio.Protocol):
266
267
  if self._timer:
267
268
  self._timer.cancel()
268
269
  try:
269
- if self._partial_data:
270
- logger.debug("Received another response fragment: %s.", data.hex())
270
+ if self._partial_data and self._partial_missing == len(data):
271
+ logger.debug("Composed fragmented response: %s + %s", self._partial_data.hex(), data.hex())
271
272
  data = self._partial_data + data
273
+ self._partial_data = None
274
+ self._partial_missing = 0
272
275
  if self.command.validator(data):
273
- if self._partial_data:
274
- logger.debug("Composed fragmented response: %s", data.hex())
275
- else:
276
- logger.debug("Received: %s", data.hex())
276
+ logger.debug("Received: %s", data.hex())
277
277
  self._retry = 0
278
- self._partial_data = None
279
278
  self.response_future.set_result(data)
280
279
  else:
281
280
  logger.debug("Received invalid response: %s", data.hex())
282
281
  self.response_future.set_exception(RequestRejectedException())
283
282
  self._close_transport()
284
- except PartialResponseException:
285
- logger.debug("Received response fragment: %s", data.hex())
283
+ except PartialResponseException as ex:
284
+ logger.debug("Received response fragment (%d of %d): %s", ex.length, ex.expected, data.hex())
286
285
  self._partial_data = data
287
- return
286
+ self._partial_missing = ex.expected - ex.length
288
287
  except asyncio.InvalidStateError:
289
288
  logger.debug("Response already handled: %s", data.hex())
290
289
  except RequestRejectedException as ex:
@@ -335,6 +334,8 @@ class TcpInverterProtocol(InverterProtocol, asyncio.Protocol):
335
334
  """Send message via transport"""
336
335
  self.command = command
337
336
  self.response_future = response_future
337
+ self._partial_data = None
338
+ self._partial_missing = 0
338
339
  payload = command.request_bytes()
339
340
  if self._retry > 0:
340
341
  logger.debug("Sending: %s - retry #%s/%s", self.command, self._retry, self.retries)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: goodwe
3
- Version: 0.4.3
3
+ Version: 0.4.4
4
4
  Summary: Read data from GoodWe inverter via local network
5
5
  Home-page: https://github.com/marcelblijleven/goodwe
6
6
  Author: Martin Letenay, Marcel Blijleven
goodwe-0.4.3/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.4.3
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes