Whole file

marcelblijleven/goodwe

The author described this change as Fix decoding of voltage values. It counts as a record because the checks below fail on the code as it stood at 925f37d51 and pass on c2f1de07f, with nothing else changed between the two runs.

Fix saved2024-04-08
Sharing licenceMIT · LICENSE
Change size+3 3

What the code was meant to do, written into the code itself as a save note

Fix decoding of voltage values

The change

739739 """Retrieve voltage [V] value (2 bytes) from buffer"""
740740 if offset is not None:
741741 buffer.seek(offset)
742- value = int.from_bytes(buffer.read(2), byteorder="big", signed=True)
743- return float(value) / 10
742+ value = int.from_bytes(buffer.read(2), byteorder="big", signed=False)
743+ return float(value) / 10 if value != 0xffff else 0
744744
745745
746746 def encode_voltage(value: Any) -> bytes:
747747 """Encode voltage value to raw (2 bytes) payload"""
748- return int.to_bytes(int(value * 10), length=2, byteorder="big", signed=True)
748+ return int.to_bytes(int(value * 10), length=2, byteorder="big", signed=False)
749749
750750
751751 def read_current(buffer: ProtocolResponse, offset: int = None) -> float:

The check that tells the two apart

failpass·tests/test_dt.py::GW5000D_NS_Test::test_GW5000D_NS_runtime_data
failpass·tests/test_dt.py::GW5000_MS_Test::test_GW5000_MS_runtime_data
failpass·tests/test_dt.py::GW6000_DT_Test::test_GW6000_DT_runtime_data

Check file tests/test_dt.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.

Origin and history

The code before it925f37d51d7d0370d1220d55e7f95b3cf06e16f1
Broken version dated2024-02-17
Modulegoodwe.sensor
Units changedencode_voltage, read_voltage
Fingerprinteaf546202b5ecb6a
Checked2026-08-18 by goldset/0.1

Every field above is generated by our program. None of it is written by hand.

Other bugs found in marcelblijleven/goodwe