From 3af19bb8e520a33e7887486647b1d2a98b1fff19 Mon Sep 17 00:00:00 2001 From: Fredrik Ahlgren Date: Tue, 27 Oct 2026 18:03:55 +0100 Subject: [PATCH 1/3] fix(drivers): bundle sungrow 1.6.1, an outage keeps the release Move the pin to srcfl/device-drivers cc16f0e (srcfl/device-drivers#201, not merged yet). After an outage, sungrow 1.6.0 reported the release as held without writing it and dropped 13000, which signs the battery. The random site rig on 83c2b24c saw the forced command outlive the outage in 8 of 10 seeds. TestSungrowOutageKeepsTheReleaseAndTheBatterySign feeds the driver the dial and backoff errors FTW's Modbus client returns while the inverter is offline. It fails on 1.6.0 and passes on 1.6.1. Co-Authored-By: Claude Opus 5.5 --- .changeset/bundle-sungrow-outage.md | 5 ++ drivers/BUNDLED_SOURCE.json | 2 +- go/internal/drivers/sungrow_driver_test.go | 91 ++++++++++++++++++++++ 3 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 .changeset/bundle-sungrow-outage.md diff --git a/.changeset/bundle-sungrow-outage.md b/.changeset/bundle-sungrow-outage.md new file mode 100644 index 000000000..1353da3a8 --- /dev/null +++ b/.changeset/bundle-sungrow-outage.md @@ -0,0 +1,5 @@ +--- +"ftw": patch +--- + +Bundle sungrow 1.6.1. After the inverter drops off the network and comes back, the driver writes the release instead of reporting it held, so a forced charge or discharge no longer keeps running. It also keeps reading the battery's direction and PV, instead of dropping them for the session. diff --git a/drivers/BUNDLED_SOURCE.json b/drivers/BUNDLED_SOURCE.json index 5dfa246e7..f326d8f8b 100644 --- a/drivers/BUNDLED_SOURCE.json +++ b/drivers/BUNDLED_SOURCE.json @@ -16,7 +16,7 @@ "from the signed channel. Run scripts/sync-bundled-drivers.sh to update." ], "repository": "srcfl/device-drivers", - "commit": "57984984a9bf6939d5206c5a05138296d9c6d940", + "commit": "cc16f0e88482c49452070ca932a783859a531032", "source_dir": "drivers/lua", "drivers": [ "ambibox_v2x", "ctek", "ctek_hybrid", "ctek_v2", "deye", "easee_cloud", diff --git a/go/internal/drivers/sungrow_driver_test.go b/go/internal/drivers/sungrow_driver_test.go index 86b5ac5a0..82d898d3b 100644 --- a/go/internal/drivers/sungrow_driver_test.go +++ b/go/internal/drivers/sungrow_driver_test.go @@ -3,6 +3,8 @@ package drivers import ( "context" "encoding/json" + "errors" + "fmt" "strings" "testing" "time" @@ -355,3 +357,92 @@ func TestSungrowProbesTheHybridBlockWhenTheDeviceTypeNeverAnswers(t *testing.T) "running state; the probing fallback is not working") } } + +// offlineModbus fails every read and write the way FTW's Modbus client does +// while the inverter is unreachable: the dial error the site rig logged for +// reads, and the reconnect backoff for writes. +type offlineModbus struct { + *recordingModbus + offline bool +} + +func (m *offlineModbus) Read(addr uint16, count uint16, kind int32) ([]uint16, error) { + if m.offline { + return nil, errors.New("dial tcp 127.0.0.1:502: connect: connection refused") + } + return m.recordingModbus.Read(addr, count, kind) +} + +func (m *offlineModbus) WriteSingle(addr uint16, value uint16) error { + if m.offline { + return fmt.Errorf("%w for 1.243s", ErrModbusBackoff) + } + return m.recordingModbus.WriteSingle(addr, value) +} + +func (m *offlineModbus) WriteMulti(addr uint16, values []uint16) error { + if m.offline { + return fmt.Errorf("%w for 1.243s", ErrModbusBackoff) + } + return m.recordingModbus.WriteMulti(addr, values) +} + +// An inverter that drops off the network for a while is not an inverter +// without registers. The random site rig (27 October 2026) took the Sungrow +// offline while it held a forced discharge. sungrow 1.6.0 counted the failed +// writes as the device refusing the EMS block, then reported the release as +// held without writing it, so the inverter kept discharging for up to five +// minutes after it came back. It also counted the failed reads as missing +// registers and dropped 13000, which signs the battery. +func TestSungrowOutageKeepsTheReleaseAndTheBatterySign(t *testing.T) { + tel := telemetry.NewStore() + modbus := &offlineModbus{recordingModbus: newRecordingModbus()} + modbus.regs[4999] = 0x0E0E // SH10RT + modbus.regs[13000] = 0x0004 + modbus.regs[13021] = 900 // battery power, unsigned; 13000 says discharging + modbus.regs[13022] = 550 + env := NewHostEnv("sungrow", tel).WithModbus(modbus) + env.BatteryCapacityWh = 9600 + d, err := NewLuaDriver("../../../drivers/sungrow.lua", env) + if err != nil { + t.Fatalf("load: %v", err) + } + defer d.Cleanup() + ctx := context.Background() + + if _, err := d.Poll(ctx); err != nil { + t.Fatalf("poll: %v", err) + } + cmd, _ := json.Marshal(map[string]any{"action": "battery", "power_w": -3000}) + if err := d.Command(ctx, cmd); err != nil { + t.Fatalf("forced discharge: %v", err) + } + + modbus.offline = true + for i := 0; i < 6; i++ { + untilNextFullRead(env) + _, _ = d.Poll(ctx) + if err := d.DefaultMode(); err == nil { + t.Fatalf("default mode %d reported success while nothing reached the device", i) + } + } + modbus.offline = false + + if err := d.DefaultMode(); err != nil { + t.Fatalf("default mode after the device returned: %v", err) + } + if got := modbus.regs[13049]; got != 0 { + t.Fatalf("EMS mode = %d after the device returned, want 0: the "+ + "release was skipped and the forced discharge kept running", got) + } + + untilNextFullRead(env) + if _, err := d.Poll(ctx); err != nil { + t.Fatalf("poll after the device returned: %v", err) + } + reading := tel.Get("sungrow", telemetry.DerBattery) + if reading == nil || reading.RawW != -900 { + t.Fatalf("battery reading = %+v, want -900 W: 13000, which signs it, "+ + "was dropped during the outage", reading) + } +} From f2e0e56b2f52e8fe7524642c6095db3acf05e065 Mon Sep 17 00:00:00 2001 From: Fredrik Ahlgren Date: Tue, 27 Oct 2026 19:15:24 +0100 Subject: [PATCH 2/3] docs(changeset): the sungrow release lands within about a minute The rig shows the forced state still running 3 to 69 s after the inverter returns, because two Core timers (Modbus reconnect backoff and the default-recovery retry) set when the release is tried. Say what the driver change delivers, not that the forced state stops at once. Co-Authored-By: Claude Opus 5.5 --- .changeset/bundle-sungrow-outage.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/bundle-sungrow-outage.md b/.changeset/bundle-sungrow-outage.md index 1353da3a8..55a7dc254 100644 --- a/.changeset/bundle-sungrow-outage.md +++ b/.changeset/bundle-sungrow-outage.md @@ -2,4 +2,4 @@ "ftw": patch --- -Bundle sungrow 1.6.1. After the inverter drops off the network and comes back, the driver writes the release instead of reporting it held, so a forced charge or discharge no longer keeps running. It also keeps reading the battery's direction and PV, instead of dropping them for the session. +Bundle sungrow 1.6.1. After the inverter drops off the network and comes back, the driver writes the release instead of reporting it held. A forced charge or discharge left over from before the outage now usually ends within about a minute of the return. Before, it ran for three to eight minutes, or did not end. The driver also keeps reading the battery's direction and PV, instead of dropping them for the session. From 8f24a9341ecdfb8d95998909aff932bf7302f673 Mon Sep 17 00:00:00 2001 From: Fredrik Ahlgren Date: Wed, 28 Oct 2026 11:30:32 +0100 Subject: [PATCH 3/3] fix(drivers): pin sungrow 1.6.1 at device-drivers' merged commit (46b28a1) Co-Authored-By: Claude Opus 5.5 --- drivers/BUNDLED_SOURCE.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/BUNDLED_SOURCE.json b/drivers/BUNDLED_SOURCE.json index f326d8f8b..e054fb4e7 100644 --- a/drivers/BUNDLED_SOURCE.json +++ b/drivers/BUNDLED_SOURCE.json @@ -16,7 +16,7 @@ "from the signed channel. Run scripts/sync-bundled-drivers.sh to update." ], "repository": "srcfl/device-drivers", - "commit": "cc16f0e88482c49452070ca932a783859a531032", + "commit": "46b28a1cb968bb81cf30df9290cfca816d1d91b9", "source_dir": "drivers/lua", "drivers": [ "ambibox_v2x", "ctek", "ctek_hybrid", "ctek_v2", "deye", "easee_cloud",