Commit 07d54d5
fix(gateway): write entities for the bound control target, not just primary units (#4360)
On a multi-AIO site automatic_config picks the Gateway/EMS as the control target
and binds every PredBat arg to its serial suffix. _inject_entities only ever
wrote entities for units flagged primary — and firmware never flags a Gateway or
EMS primary — so none of the bound entities were written. They held whatever
value they had and silently froze.
Observed in production: a site froze for 69 minutes with byte-identical SoC,
battery power, grid power, load power and PV power, while PredBat continued to
plan and issue control against a stale 76% SoC. The only escaping symptom was the
clock-skew warning, because inverter_time is the one bound value whose staleness
is self-evident against wall clock — which sends users to fix an inverter clock
that is not broken.
Inject a unit when it is primary OR when automatic_config bound args to it
(tracked in _suffix_to_serial), and write inverter_time under the bound suffix
rather than the primary's. Non-primary units that are not the control target stay
skipped, preserving the existing guard against double-counted power readings.
Adds TestBoundEntitiesAreWritten, which asserts the invariant directly: every
entity automatic_config binds must actually be written by _inject_entities.
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>1 parent 61f98d6 commit 07d54d5
2 files changed
Lines changed: 140 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
62 | 77 | | |
63 | 78 | | |
64 | 79 | | |
| |||
719 | 734 | | |
720 | 735 | | |
721 | 736 | | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
722 | 753 | | |
723 | 754 | | |
724 | 755 | | |
| |||
735 | 766 | | |
736 | 767 | | |
737 | 768 | | |
738 | | - | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
739 | 772 | | |
740 | | - | |
741 | | - | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
742 | 777 | | |
743 | 778 | | |
744 | 779 | | |
| |||
748 | 783 | | |
749 | 784 | | |
750 | 785 | | |
751 | | - | |
752 | | - | |
753 | | - | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
754 | 793 | | |
755 | | - | |
756 | | - | |
| 794 | + | |
757 | 795 | | |
758 | 796 | | |
759 | 797 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
| |||
291 | 292 | | |
292 | 293 | | |
293 | 294 | | |
| 295 | + | |
294 | 296 | | |
295 | 297 | | |
296 | 298 | | |
| |||
673 | 675 | | |
674 | 676 | | |
675 | 677 | | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
676 | 769 | | |
677 | 770 | | |
678 | 771 | | |
| |||
4259 | 4352 | | |
4260 | 4353 | | |
4261 | 4354 | | |
| 4355 | + | |
4262 | 4356 | | |
4263 | 4357 | | |
4264 | 4358 | | |
| |||
0 commit comments