Repository navigation
fix(solis): don't let an early-armed window cut off the one running in TOU V2 slot 1 (#6210) - #6213
Conversation
…n TOU V2 slot 1 (#6210) A TOU V2 inverter keeps only one of a slot's charge and discharge enables on: writing one turns the other off. Predbat binds both its charge and its export controls to slot 1 and arms the next window set_window_minutes before it starts, so an export armed during a charge (or a charge armed during an export) switched the running window off. The 5-minute in-window re-read then found the dropped enable and wrote it back, and the two flipped every five minutes until one window was gone. Pass 2 of the V2 write now leaves a slot's other direction unwritten while both are asked for. The slot goes to the running window (its end minute counts as over, so the next one takes over on the hand-over minute), else to the one that starts first; when both are running, the one that started later wins. The hold-back keeps no state: the schedule Predbat sees is unchanged, a window moved while held back is written at its new times, and after a restart Predbat re-arms it and it is held back again. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…d-back Runs run() every minute from the held-back window being armed until after the hand-over, against a simulated inverter that keeps only one of slot 1's enables on, with the 5-minute in-window re-read and the hourly poll reading from it. Checks every minute that the running window stays on at the inverter and that the published slot entities Predbat reads its windows back from still show both windows as it asked. Run for a held-back export and a held-back charge; without the hold-back both fail on the first cycle. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
springfall2008
left a comment
There was a problem hiding this comment.
Automated comment from the triage bot.
Reviewed at 4728320 (PR head). 1 finding inline, 1 in this body.
The core change holds up. The deferral sits in the one Pass 2 path every TOU V2 slot-enable write goes through, and Predbat's own schedule is left alone: decode_time_windows_v2() only runs on the first cycle or after a TOU-mode change, so the 5-minute in-window re-read refreshes the register cache without overwriting the ask, which is what stops execute re-arming the held-back window every cycle. now_utc_exact really is local time (ComponentBase returns datetime.now(self.local_tz)), matching the slot times. The four new module-level helpers are pure and the end-to-end run() test drives the real write path against a simulated inverter with the reported exclusion, so the flip-flop is covered where it actually happened.
Also checked and clean: the V1 branch and the slot switch handlers keep their own paths and every V2 enable write still funnels through Pass 2; the read-only handover disables enables through write_read_only_reset_cid, so the deferral cannot block it; reset_charge_windows_if_needed() only clears slots 2-6, so slot 1 is the only slot that normally sees both directions enabled; the new tuple-keyed slot_direction_deferred lives on the component, which DEBUG_EXCLUDE_LIST keeps out of the debug dump; the new tests pin the wall clock, so they are not time-of-day flaky; and no existing test pairs both V2 enables with a live window, so nothing else becomes clock-dependent.
docs/components.md:1534 - "Important notes (solis)" has no note on this
The "Important notes (solis)" list already records quirks of exactly this shape (the firmware note and the timezone note just below it), and this change is visible to users in two ways. An export or charge that used to be programmed on the inverter up to set_window_minutes (30 by default) early is now programmed on the hand-over cycle instead, so the inverter dashboard no longer shows the next window ahead of time while a window is running in that slot; and the new Solis API: Holding back ... log line will be pasted into support threads. One short paragraph saying TOU V2 keeps only one of a slot's charge and discharge enables, that Predbat therefore gives slot 1 to the window that is running (or starts first) and programmes the other when the running one ends, and what the Holding back line means, would close the gap - and would stop the later arming being reported as a regression.
…rection-collision-6210
… invariant (#6210) Review feedback on #6213. The components docs now say that TOU V2 keeps one direction per slot, that the next window is programmed on the hand-over while one is running in slot 1, and what the "Holding back" log line means. slot_direction_to_defer() now states the invariant its both-running branch relies on (the plan gives each slot of time a single action; the state is only seen mid-execute, when a charge moved to now is armed just before the export it replaces is withdrawn) instead of implying it is checked. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Reply from Claude Code, working with the maintainer. On the review's body finding (
The same push merges |
Fixes #6210.
Problem
A Solis TOU V2 inverter keeps only one of a slot's charge and discharge enables on. Writing discharge slot 1 enable (CID 5922) turns charge slot 1 enable (CID 5916) off, and the reverse.
Predbat binds both its charge and export controls to slot 1 (
charge_slot1_*/discharge_slot1_*inautomatic_config()).execute.pyarms the next window up toset_window_minutes(30 by default) before it starts, and SolisCloud hashas_discharge_enable_time. So an export armed during a charge switched the charge off. A charge armed during an export would switch the export off in the same way.Then the 5-minute in-window re-read made it worse. It refreshes the register cache but not the schedule Predbat asked for, so each re-read found the dropped enable and wrote it back.
read_and_write_cid()verifies only the CID it wrote, so it never noticed the partner enable dropping. The two enables flipped every 5 minutes until one window was gone.Fix
Pass 2 of the V2 path in
write_time_windows_if_changed()now leaves one direction of a slot unwritten while Predbat asks for both:time_in_window()includes it, so the next window takes over on the hand-over minute.The logic is in the new
slot_direction_to_defer(),slot_window_wait()andminutes_after(), plusSolisAPI.defer_slot_direction(), which logs the hold-back once per change.What stays the same
charge_discharge_time_windows(what Predbat asked for), and the write works on a deep copy. Soadjust_force_export()/adjust_charge_window()still see their own request and don't re-arm every cycle.slot_direction_deferredonly stops the log line repeating. A window moved while held back is written at its new times when it takes the slot. After a restart, the first decode shows the held-back window as off; Predbat re-arms it and it is held back again.Cost
When one window hands over to the next, the incoming window's enable, time, SOC and current are written on the hand-over cycle rather than up to 30 minutes ahead. That adds about a minute of cloud writes to the start of that window.
Not in this PR
slot1_active,is_holding_in_charge_slotand the in-window re-read. It needs a hardware test first.Tests
New tests in
apps/predbat/tests/test_solis.py. Each is run twice: once with an export held back behind a running charge (the reported case), and once with a charge held back behind a running export.held_window_waitsheld_window_takes_slot_when_running_endsheld_window_waits_after_restartheld_window_moves_laterheld_window_moves_to_nowheld_window_removedsooner_window_takes_slotcovers the case where neither window is running, across midnight and in both directions.test_run_v2_hold_back_through_re_reads(both directions) tests the whole loop. It drivesrun()once a minute, from the held-back window being armed until after the hand-over, against a simulated inverter that keeps only one of slot 1's enables on. The realwrite_time_windows_if_changedis used, and the 5-minute in-window re-reads and the hourly poll all read from the simulated inverter (7 slot polls in total). Every minute it checks two things: the running window is still on at the inverter, and the published slot entities, which Predbat reads its windows back from, still show both windows as Predbat asked. Without the hold-back it fails on the first cycle in both directions.Mutation checks:
moves_to_now, and "export wins a tie" fails the held-charge version.held_window_removed../run_all --test solisand pre-commit pass../run_all --quickpassed on the core change, before the final tie-break and log edits.Workaround until this ships
Turn off
switch.predbat_inverter_set_charge_before. That setsset_window_minutesto 0, so windows are armed only once they start. The cost is a later start for every window, on every inverter.🤖 Generated with Claude Code