Cars: log what charging costs, and drag the provider readings
Three things, all on a car's page. A Charging cost tab, which is the Fuel cost tab written for an electric car: charges in kWh, consumption in kWh/100km beside km per kWh, cost per km and price per kWh, and the same summary panel over the whole history. It keeps the reference-point method too, and has to — a session records the energy that went in, not what was left in the battery, so a given number of kWh only maps to a distance between two charges that ended at the same state. A charge to the car's usual full point plays the part of the full tank; partial charges still count towards the cost and roll into the next full one; and a charge taken without logging it leaves its window uncomputed rather than reporting an implausibly good figure. Sessions live in their own collection, the figures are derived on read like the fuel ones, and logging a charge advances the odometer exactly as a refill does. The tab switches off from the gear like every other, so a petrol car need never see it. The headline readings on the connected-service tab now drag into any order, saved on drop. Stored on the car as metricOrder, like the Information rows, rather than per device the way the collapsed cards are: an arrangement is something everyone the car is shared with should see, where a folded card is one browser's reading habit. Only what the provider reported can be arranged, so a reading that turns up later joins the end rather than displacing the arrangement. Fuel is now Fuel cost, tab and heading, which is what the tab has always been about and what pairs it with Charging cost. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
2b6da642ad
commit
6191160f14
20 files changed
+1388
-53
No files matched your search
@@ -33,13 +33,16 @@ func TestNormalizeHiddenTabs(t *testing.T) {
|
||||
|
||||
// The hideable set is the contract the web app's HIDEABLE_TABS mirrors:
|
||||
// every tab the car page renders beside Information.
|
||||
for _, key := range []string{"provider", "services", "technical", "maintenance", "fuel", "documents", "parts", "reminders"} {
|
||||
for _, key := range []string{
|
||||
"provider", "services", "technical", "maintenance", "fuel", "charging",
|
||||
"documents", "parts", "reminders",
|
||||
} {
|
||||
if !hideableCarTabs[key] {
|
||||
t.Errorf("tab %q should be hideable", key)
|
||||
}
|
||||
}
|
||||
if len(hideableCarTabs) != 8 {
|
||||
t.Errorf("hideableCarTabs has %d entries, want the 8 tabs beside Information", len(hideableCarTabs))
|
||||
if len(hideableCarTabs) != 9 {
|
||||
t.Errorf("hideableCarTabs has %d entries, want the 9 tabs beside Information", len(hideableCarTabs))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,6 +102,32 @@ func TestNormalizeFieldOrder(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// The connected service's headline readings arrange the same way, against the
|
||||
// key set derived from what that panel renders.
|
||||
func TestNormalizeMetricOrder(t *testing.T) {
|
||||
got, err := normalizeKeys([]string{"evRangeWithAc", "odometer"}, arrangeableCarMetrics, "reading")
|
||||
if err != nil {
|
||||
t.Fatalf("normalizeKeys: %v", err)
|
||||
}
|
||||
assertKeys(t, got, []string{"evRangeWithAc", "odometer"})
|
||||
|
||||
// Every reading the panel can show has to be arrangeable, the two that are
|
||||
// not measures included.
|
||||
for _, key := range []string{
|
||||
"odometer", "fuelLevel", "fuelRange", "batteryLevel", "evRange",
|
||||
"evRangeWithAc", "chargingStatus", "location",
|
||||
} {
|
||||
if !arrangeableCarMetrics[key] {
|
||||
t.Errorf("reading %q should be arrangeable", key)
|
||||
}
|
||||
}
|
||||
|
||||
// A field key is not a reading key — a car's two arrangements are separate.
|
||||
if _, err := normalizeKeys([]string{"vin"}, arrangeableCarMetrics, "reading"); err == nil {
|
||||
t.Error("normalizeKeys accepted a field key as a reading, want an error")
|
||||
}
|
||||
}
|
||||
|
||||
func assertKeys(t *testing.T, got, want []string) {
|
||||
t.Helper()
|
||||
if len(got) != len(want) {
|
||||
|
||||
Reference in new issue
Block a user