Repository navigation
fix(history): keep working measurements when a device is offline #1592
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "ftw": patch | ||
| --- | ||
|
|
||
| Keep history for working devices when another device is offline. Show missing power, state of charge and energy as unknown, preserve gaps through retention and backup, and flag incomplete measurements or an invalid household balance. Separate additive schema-7 tables keep partial rows out of older readers and preserve them across a native rollback. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "github.com/srcfl/ftw/go/internal/state" | ||
| "github.com/srcfl/ftw/go/internal/telemetry" | ||
| "testing" | ||
| "time" | ||
| ) | ||
|
|
||
| func TestHistoryRetainsLiveMeterWhenBatteryOffline(t *testing.T) { | ||
| tel := telemetry.NewStore() | ||
| for _, name := range []string{"meter", "battery"} { | ||
| tel.EnsureDriverHealth(name) | ||
| } | ||
| tel.Update("meter", telemetry.DerMeter, 1200, nil, nil) | ||
| tel.RecordDriverSuccess("meter") | ||
| tel.DriverHealthMut("battery").SetOffline() | ||
| opts := telemetry.ForecastOptions{ExpectedFlows: []telemetry.ForecastFlow{{Driver: "battery", DerType: telemetry.DerBattery}}} | ||
| p, available := buildHistoryPoint(tel, tickPersistControl{SiteMeterDriver: "meter"}, time.Now().UnixMilli(), time.Minute, opts) | ||
| if !available || p.GridW != 1200 { | ||
| t.Fatalf("live meter lost when battery offline: available=%v point=%+v", available, p) | ||
| } | ||
| } | ||
|
|
||
| func TestHistoryConfiguredPVWithoutMeasurementIsUnknown(t *testing.T) { | ||
| tel := telemetry.NewStore() | ||
| tel.EnsureDriverHealth("meter") | ||
| tel.Update("meter", telemetry.DerMeter, 1200, nil, nil) | ||
| tel.RecordDriverSuccess("meter") | ||
| p, ok := buildHistoryPoint(tel, tickPersistControl{SiteMeterDriver: "meter"}, time.Now().UnixMilli(), time.Minute, telemetry.ForecastOptions{HouseholdInvalidReason: "configured_pv_without_measurement_source"}) | ||
| if !ok || p.Missing&state.MissingPV == 0 { | ||
| t.Fatalf("unmeasured configured PV reported as zero: %+v", p) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When
weather.pv_rated_wor PV arrays declare solar but no driver provides a PV flow,forecastMeasurementTopologysetsHouseholdInvalidReasontoconfigured_pv_without_measurement_source; it does not setPVInvalidReason. Because this condition checks only the latter andKnown[DerPV]remains true when there is no flow, every live-meter tick is persisted with PV equal to a measured zero. The daily history then permanently reports 0 Wh rather than unknown solar generation, so this household topology needs to setMissingPVas well.AGENTS.md reference: AGENTS.md:L22-L23
Useful? React with 👍 / 👎.