Skip to content

feat(cars): a car keeps a goal per weekday - #2186

Merged
frahlg merged 3 commits into
masterfrom
car-goals-per-day
Dec 5, 2026
Merged

frahlg merged 3 commits into
masterfrom
car-goals-per-day

Conversation

@frahlg

@frahlg frahlg commented Dec 5, 2026 •

Copy link
Copy Markdown
Member

What

A car keeps a short list of goals. Weekly goals each have a level, a ready time and their weekdays, with no weekday in two. Beside them a car may keep one once goal. This covers HannesB's Laddmål sheet (for example 80 % by 07:30 on weekdays and 60 % by 10:00 at the weekend), plus the one-off goal that old clients and the charger card can already set.

The charger runs one goal at a time. The planner, the reserve and the controller are unchanged: they still see one goal per charger, and the cars runtime picks which one at each sync.

  • Once goal: it is for the next time its ready time comes after it is set. If a client writes the once goal back unchanged, in a list or alone, it keeps that time. Until then it is the goal the charger runs, even over a weekly goal due before it. When that time passes, the box takes it out of the list and the weekly goals carry on. A once goal to the car's own limit stays while the car on the charger still charges to it.
  • Weekly goals: otherwise the charger runs the weekly goal for the next departure. A goal whose time today has passed gives way to the next, and the box replans. A due weekly goal to the car's own limit stays until the car stops.
  • Limits: at most 8 goals (7 weekly and 1 once). Every goal has a level. Weekly goals that differ only in their days are folded into one, and the list is sorted by first weekday with the once goal last.

Core still checks every value with today's ranges: target 0..1, ready_by_min 0..1439, days 0..127.

No single write loses a goal it did not name

This rule covers every single-goal write: car.goal.set with a flat goal (by id or charger_id), car.add with goal, PUT /api/loadpoints/{id}/schedule and POST /api/loadpoints/{id}/target. The box's charger card uses these routes too.

  • A goal with days takes exactly those days. A goal it overlaps keeps its other days. For example, 80 % by 07:00 every day followed by a weekday write of 60 % by 06:00 leaves Saturday and Sunday at 80 % by 07:00.
  • A goal without days is the once goal. It replaces the car's once goal and leaves the weekly goals alone. A weekly write leaves the once goal alone.
  • A goal without a level removes the days it names, or the once goal, and nothing else.
  • clear: true and the schedule route's null remove every goal. With charger_id, the charger keeps the site's battery rule, so the charger sees the clear as a no-level goal at the local time of UTC midnight. The box therefore clears the car's goals directly, and a Stockholm-zone test covers this.

Wire contract

New registry names: capability car.goals and car field goals (kind object_list, entries with the fields of goal). go/protocol/contract_gen.go is regenerated.

Read: GET /api/cars (full and redacted) carries:

  • goals: weekly goals by first weekday, then the once goal;
  • goal: the goal the charger runs, or would run if the car were plugged in.

Both are absent when there is no goal. cmd.result's brief car and FTW Cloud's car class carry goal only.

Write:

  • car.goal.set {id, goals: [{target, ready_by_min, days?, finish_at_limit?}, …]} replaces the list. An entry without days is the once goal, and there is at most one. goals: [] removes every goal. PUT /api/cars/{id}/goal takes the same body.
  • goals must come alone. With target, ready_by_min, days, finish_at_limit, clear or charger_id, or with any fault in the list (including two once goals), the box refuses the op with E_UNKNOWN_OP and arg: goals, and nothing changes.
  • car.add takes goals in the stored form (target_permille, …). It wins over goal.
  • Agents cannot send goals. Their single goal follows the rules above.

A box without this change ignores goals and answers applied, so apps must check car.goals in hello_ok.caps first.

Migration and rollback

A car stored with goal and no goals loads it as a list of one, and charges as before. A stored once goal is for the next time its ready time comes, which is how the charger read it after a restart.

Each save also writes goal: the next departure's goal, on its own days. A box rolled back to an older release keeps that one goal. A weekday goal then charges on weekdays only, until someone sets the other days.

Tests

go/internal/cars/goals_test.go:

  • migration of a weekly goal and of a once goal;
  • the rollback mirror;
  • weekday and weekend switches;
  • across midnight in Stockholm;
  • DST on 29 March and 25 October 2026;
  • one-goal writes that split masks, remove days without a level, and fold;
  • a once goal beside the week: it wins over an earlier weekly goal, then goes, and two once goals are refused;
  • charger routes and charger_id goals, including clear while the charger keeps the site rule;
  • list checks and folding, and car.add.

Integration tests run through the loadpoint (ApplyCarGoal, setScheduleAs, RollSchedules):

  • A Friday goal to the car's limit stays due past 07:00 while the car charges, then hands over to the weekend goal when the car stops taking current.
  • A once goal to the limit stays the same way, then leaves the list.
  • A list or a once goal written back past its time keeps that time. The once goal still goes when the car stops and does not return the next morning.

appproto op tests cover acceptance with a once goal, every refusal, and agents. An api route test covers the route.

Run locally:

  • go test on internal/cars, internal/appproto, internal/api, internal/loadpoint, cmd/ftw and go/protocol;
  • make verify once.

All pass. Each new test fails if its fix is taken out: the held-due check, the clear fix, or keeping the once goal's time.

Other open PRs

Follow-ups outside this repo

  • Copy contract/registry.yaml into ftw-webapp/contract/ and ftw-app/protocol/. Copy the Versioning paragraph into ftw-webapp/docs/protocol.md.
  • The apps and the box's page still edit one goal. They need the Laddmål sheet once this merges.

Known edges

  • An old app that reads a waiting once goal as goal and saves it as every day sets the week, but goal keeps showing the once goal until its time.
  • If the box restarts while a once goal to the car's limit is past its time and still charging, the goal ends at the restart.
  • On a UTC box with no battery rule, a goal without a level, without days and at 00:00, sent by charger_id or the schedule route, reaches Core in the same form as a clear and removes every goal. An old client's plain clear looks the same, so the box cannot tell them apart.

Questions for Fredrik

  1. Should FTW Cloud's car class carry goals, or stay with goal?
  2. The sheet has no once goal. The box keeps one beside the week for old clients and the charger card. Should the sheet offer it?
  3. finish_at_limit is kept per goal, though the sheet does not show it.
  4. The changeset is minor, a visible new capability. Please approve the bump.

🤖 Generated with Claude Code

A car now holds up to seven goals, each a level, a ready time and the
weekdays it applies to, with no day in two goals. The charger runs the
goal for the car's next departure, so the planner and the controller
still see one goal. A goal for today whose time has passed gives way to
the next; a due goal to the car's own limit stays until the car stops.

A stored single goal loads as a list of one. Each save still writes
goal, the next departure's goal, so a rollback finds one goal per car.

car.goal.set and car.add take goals; the box lists car.goals. Clients
that know one goal read goal and keep writing one: it takes the place of
the goals it shares a day with, and goals for other days stay.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 5, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-05T14:08:58.251482Z 34bb1dd PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

frahlg and others added 2 commits December 5, 2026 15:23
A once goal from an old client, the charger route or a charger_id goal
replaced the whole weekly list, and the list never came back after the
once goal fired. A weekday write over an every-day goal also dropped the
weekend.

Now a once goal sits beside the weekly goals, at most one of it. It runs
until its ready time, even over a weekly goal due first, then goes and
the week carries on; one to the car's own limit stays while the car still
charges to it. A single write with days takes exactly those days and
splits the goals it overlaps. A goal without a level takes out only what
it names. clear, and the schedule route's null, still remove every goal,
also when the charger keeps the site's battery rule.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A list write dated its once goal again from now. A client that sent back
the list it read, after editing another day, moved a once goal past its
time but still held due to its next ready time. The charger kept running
it, and when the car stopped the box no longer took it out, so it fired
the next morning.

A once goal alike the car's stored one now keeps the stored instant, for
a list write and for a single once write. A new test writes the list and
the once goal back past its time and checks it goes when the car stops.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@frahlg
frahlg merged commit c403700 into master Dec 5, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant