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.
Projectmarcelblijleven/goodwe
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
| 385 | 385 | self.soc: int = 100 # just to keep same API with V2 | |
| 386 | 386 | ||
| 387 | 387 | 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'}" | |
| 389 | 391 | ||
| 390 | 392 | def read_value(self, data: ProtocolResponse): | |
| 391 | 393 | self.start_h = read_byte(data) | |
| ⋯ | |||
| 483 | 485 | # 2 bytes padding 0000 | |
| 484 | 486 | ||
| 485 | 487 | 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'}" | |
| 487 | 491 | ||
| 488 | 492 | def read_value(self, data: ProtocolResponse): | |
| 489 | 493 | self.start_h = read_byte(data) | |
| ⋯ | |||
| 499 | 503 | if self.end_m < 0 or self.end_m > 59: | |
| 500 | 504 | raise ValueError(f"{self.id_}: end_m value {self.end_m} out of range.") | |
| 501 | 505 | 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): | |
| 503 | 507 | raise ValueError(f"{self.id_}: on_off value {self.on_off} out of range.") | |
| 504 | 508 | self.day_bits = read_byte(data) | |
| 505 | 509 | self.days = decode_day_of_week(self.day_bits) | |
| ⋯ | |||
| 539 | 543 | and self.start_m == 0 \ | |
| 540 | 544 | and self.end_h == 23 \ | |
| 541 | 545 | and self.end_m == 59 \ | |
| 542 | - | and self.on_off != 0 \ | |
| 546 | + | and self.on_off == -1 \ | |
| 543 | 547 | and self.day_bits == 127 \ | |
| 544 | 548 | and self.power < 0 | |
| 545 | 549 | ||
| ⋯ | |||
| 549 | 553 | and self.start_m == 0 \ | |
| 550 | 554 | and self.end_h == 23 \ | |
| 551 | 555 | and self.end_m == 59 \ | |
| 552 | - | and self.on_off != 0 \ | |
| 556 | + | and self.on_off == -1 \ | |
| 553 | 557 | and self.day_bits == 127 \ | |
| 554 | 558 | and self.power > 0 | |
| 555 | 559 | ||
| ⋯ | |||
| 561 | 565 | result.end_h = self.end_h | |
| 562 | 566 | result.end_m = self.end_m | |
| 563 | 567 | result.power = self.power | |
| 564 | - | result.on_off = self.on_off | |
| 568 | + | result.on_off = -1 if self.on_off == -1 else 0 | |
| 565 | 569 | result.day_bits = self.day_bits | |
| 566 | 570 | result.days = self.days | |
| 567 | 571 | return result | |
| ⋯ | |||
| 584 | 588 | # 2 bytes padding 0000 | |
| 585 | 589 | ||
| 586 | 590 | 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'}" | |
| 588 | 594 | ||
| 589 | 595 | def read_value(self, data: ProtocolResponse): | |
| 590 | 596 | self.start_h = read_byte(data) | |
| ⋯ | |||
| 600 | 606 | if self.end_m < 0 or self.end_m > 59: | |
| 601 | 607 | raise ValueError(f"{self.id_}: end_m value {self.end_m} out of range.") | |
| 602 | 608 | 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): | |
| 604 | 610 | raise ValueError(f"{self.id_}: on_off value {self.on_off} out of range.") | |
| 605 | 611 | self.day_bits = read_byte(data) | |
| 606 | 612 | self.days = decode_day_of_week(self.day_bits) | |
The check that tells the two apart
fail→pass·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
- 2026-03-29Fix duplicate sensor registrations
- 2024-05-14Fix decoding 0 energy values
- 2024-05-12Fix writing single byte settings on ES inverters
- 2024-05-08Fix setup of BT inverters
- 2024-04-08Fix decoding of voltage values
- 2023-12-31Fix unit of current MPPT sensors