Repository navigation
feat(cars): a car keeps a goal per weekday - #2186
Merged
Merged
Conversation
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>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
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>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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.
Core still checks every value with today's ranges:
target0..1,ready_by_min0..1439,days0..127.No single write loses a goal it did not name
This rule covers every single-goal write:
car.goal.setwith a flat goal (byidorcharger_id),car.addwithgoal,PUT /api/loadpoints/{id}/scheduleandPOST /api/loadpoints/{id}/target. The box's charger card uses these routes too.clear: trueand the schedule route'snullremove every goal. Withcharger_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.goalsand car fieldgoals(kindobject_list, entries with the fields ofgoal).go/protocol/contract_gen.gois 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'scarclass carrygoalonly.Write:
car.goal.set {id, goals: [{target, ready_by_min, days?, finish_at_limit?}, …]}replaces the list. An entry withoutdaysis the once goal, and there is at most one.goals: []removes every goal.PUT /api/cars/{id}/goaltakes the same body.goalsmust come alone. Withtarget,ready_by_min,days,finish_at_limit,clearorcharger_id, or with any fault in the list (including two once goals), the box refuses the op withE_UNKNOWN_OPandarg: goals, and nothing changes.car.addtakesgoalsin the stored form (target_permille, …). It wins overgoal.goals. Their single goal follows the rules above.A box without this change ignores
goalsand answersapplied, so apps must checkcar.goalsinhello_ok.capsfirst.Migration and rollback
A car stored with
goaland nogoalsloads 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:charger_idgoals, including clear while the charger keeps the site rule;Integration tests run through the loadpoint (
ApplyCarGoal,setScheduleAs,RollSchedules):appprotoop tests cover acceptance with a once goal, every refusal, and agents. Anapiroute test covers the route.Run locally:
go testoninternal/cars,internal/appproto,internal/api,internal/loadpoint,cmd/ftwandgo/protocol;make verifyonce.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
go/internal/mpc. This PR shares no file with them and changes only which goal the charger hands the planner.docs/cars.md,cars/ops.goandcars/tick.go. Its hunks are not the lines this PR changes.contract/registry.yamlanddocs/protocol.md. The hunks are apart.Follow-ups outside this repo
contract/registry.yamlintoftw-webapp/contract/andftw-app/protocol/. Copy the Versioning paragraph intoftw-webapp/docs/protocol.md.Known edges
goaland saves it as every day sets the week, butgoalkeeps showing the once goal until its time.charger_idor 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
carclass carrygoals, or stay withgoal?finish_at_limitis kept per goal, though the sheet does not show it.minor, a visible new capability. Please approve the bump.🤖 Generated with Claude Code