Whole file

marcelblijleven/goodwe

The author described this change as Fix deconding 0x55 as not-set value of EcoMode. It counts as a record because the check below fails on the code as it stood at 0301bfb51 and passes on ec6d3ca60, with nothing else changed between the two runs.

Fix saved2024-01-09
Sharing licenceMIT · LICENSE
Change size+14 8

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

Fix deconding 0x55 as not-set value of EcoMode

The change

385385 self.soc: int = 100 # just to keep same API with V2
386386
387387 def __str__(self):
388- return f"{self.start_h}:{self.start_m}-{self.end_h}:{self.end_m} {self.days} {self.power}% {'On' if self.on_off != 0 else 'Off'}"
388+ return f"{self.start_h}:{self.start_m}-{self.end_h}:{self.end_m} {self.days} " \
389+ f"{self.power}% " \
390+ f"{'On' if self.on_off != 0 else 'Off'}"
389391
390392 def read_value(self, data: ProtocolResponse):
391393 self.start_h = read_byte(data)
483485 # 2 bytes padding 0000
484486
485487 def __str__(self):
486- return f"{self.start_h}:{self.start_m}-{self.end_h}:{self.end_m} {self.days} {self.power}% (SoC {self.soc}%) {'On' if self.on_off != 0 else 'Off'}"
488+ return f"{self.start_h}:{self.start_m}-{self.end_h}:{self.end_m} {self.days} " \
489+ f"{self.power}% (SoC {self.soc}%) " \
490+ f"{'On' if self.on_off == -1 else 'Off' if self.on_off == 0 else 'Unset'}"
487491
488492 def read_value(self, data: ProtocolResponse):
489493 self.start_h = read_byte(data)
499503 if self.end_m < 0 or self.end_m > 59:
500504 raise ValueError(f"{self.id_}: end_m value {self.end_m} out of range.")
501505 self.on_off = read_byte(data)
502- if self.on_off not in (0, -1):
506+ if self.on_off not in (0, -1, 85):
503507 raise ValueError(f"{self.id_}: on_off value {self.on_off} out of range.")
504508 self.day_bits = read_byte(data)
505509 self.days = decode_day_of_week(self.day_bits)
539543 and self.start_m == 0 \
540544 and self.end_h == 23 \
541545 and self.end_m == 59 \
542- and self.on_off != 0 \
546+ and self.on_off == -1 \
543547 and self.day_bits == 127 \
544548 and self.power < 0
545549
549553 and self.start_m == 0 \
550554 and self.end_h == 23 \
551555 and self.end_m == 59 \
552- and self.on_off != 0 \
556+ and self.on_off == -1 \
553557 and self.day_bits == 127 \
554558 and self.power > 0
555559
561565 result.end_h = self.end_h
562566 result.end_m = self.end_m
563567 result.power = self.power
564- result.on_off = self.on_off
568+ result.on_off = -1 if self.on_off == -1 else 0
565569 result.day_bits = self.day_bits
566570 result.days = self.days
567571 return result
584588 # 2 bytes padding 0000
585589
586590 def __str__(self):
587- return f"{self.start_h}:{self.start_m}-{self.end_h}:{self.end_m} {self.days} {self.import_power}kW (SoC {self.soc}%) {'On' if self.on_off == -4 else 'Off'}"
591+ return f"{self.start_h}:{self.start_m}-{self.end_h}:{self.end_m} {self.days} " \
592+ f"{self.import_power}kW (SoC {self.soc}%) " \
593+ f"{'On' if self.on_off == -4 else 'Off' if self.on_off == 3 else 'Unset'}"
588594
589595 def read_value(self, data: ProtocolResponse):
590596 self.start_h = read_byte(data)
600606 if self.end_m < 0 or self.end_m > 59:
601607 raise ValueError(f"{self.id_}: end_m value {self.end_m} out of range.")
602608 self.on_off = read_byte(data)
603- if self.on_off not in (-4, 3):
609+ if self.on_off not in (-4, 3, 85):
604610 raise ValueError(f"{self.id_}: on_off value {self.on_off} out of range.")
605611 self.day_bits = read_byte(data)
606612 self.days = decode_day_of_week(self.day_bits)

The check that tells the two apart

failpass·tests/test_sensor.py::TestUtils::test_eco_mode_v2

Check file tests/test_sensor.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 it0301bfb51d731aa73bd367efdec2eff6c94f4500
Broken version dated2024-01-02
Modulegoodwe.sensor
Units changedEcoModeV1, EcoModeV2, PeakShavingMode
Fingerprint5b3eec88b900345e
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