Skip to content

Schedule 24h: simulation, GET /schedule, MCP tool and dashboard tile (F-01) - #528

Open
MaStr wants to merge 7 commits into
mainfrom
copilot/feature-schedule-prototype
Open

MaStr wants to merge 7 commits into
mainfrom
copilot/feature-schedule-prototype

Conversation

@MaStr

@MaStr MaStr commented Dec 3, 2026 •

Copy link
Copy Markdown
Owner

Summary

What batcontrol is expected to do over the next 24 hours - as a dashboard tile, a REST endpoint and an MCP tool (feature F-01). The plan is computed by running the real logic once per upcoming slot, starting from the current SoC.

Simulation (schedule_simulation.py)

  • Every slot from now on runs through the default logic: a fresh instance per slot, fed with the remaining forecast from that slot on - as the control loop would see it then. The decided mode moves the slot's energy:
    • discharge: PV surplus in, deficit out
    • blocked: surplus only
    • PV limit: surplus up to the limit
    • grid charge: the charge rate plus surplus
  • Ideal battery (no losses) within MIN/MAX SoC. The current slot counts only its remaining part, the same way the loop scales slot 0.
  • Covers the current hour plus 24. Quarters of the current hour that are already over keep what was planned for them.
  • Recomputed by four hourly scheduler jobs at :00/:15/:30/:45, plus a startup job that retries every 10 s until the first plan exists and then drops itself (new helpers schedule_hourly_at() / schedule_until_done(), runs logged at debug level only). About 25 ms per plan on a desktop.

Isolation from the control loop (the key requirement):

  • The cycle publishes one frozen ScheduleInputs under the control lock. The simulation reads only that object: no inverter, no control lock.
  • Each logic instance gets a private CommonLogic copy (new optional common argument), so the singleton is never written from another thread.
  • The DecisionTrace is discarded: nothing reaches the decision journal, the Decision sensor or MQTT.
  • Logic logging is filtered on the simulating thread only.
  • Active interventions (API mode, evcc discharge block or peak shaving suspension, grid charge lock) are ignored and reported in overrides.
  • core.py builds the logic parameters in one place for the cycle and the preview, so the preview cannot drift from what the loop decides with.

API

  • GET /api/v1/schedule and the MCP tool batcontrol_get_schedule, both through service.schedule(). Per slot: mode, SoC at start and end, battery and grid energy in Wh, charge rate or PV limit in W, lookahead_hours.
  • Returns 503 no_data_yet before the first plan and forecast_expired once every slot has passed.
  • /schedule, not /forecast/schedule: the existing /forecast/{series} route would have answered that path with not_found.
  • Not published on MQTT (maintainer decision).

Dashboard tile "SCHEDULE 24H"

  • Boxes: 25 hour boxes from the current hour.
  • Colours by mode: grid charge amber, blocked red, PV limited turquoise, discharge green.
  • Two views:
    • marker, the default on phones: majority mode, a tie goes to the more important mode, and a bar marks a more important mode that lost.
    • quarters, the default on desktops: four stripes per hour.
    • A resize across 820 px switches the view. A manual choice is remembered per width class.
  • Popover per hour, opened by tap or hover. The whole hour column is the touch target, and a finger drag scrubs across the hours.
  • SoC line above the boxes.
  • Plan end: the plan ends with the forecast. A "plan until HH:MM" line marks the end, and hours with less than 4 h lookahead are dimmed.
  • Overrides are named in a note.
  • Hidden while the API serves no plan.

Logging

  • log_everything: false now also quiets mcp (and all mcp.* loggers, one INFO line per MCP request) and sse_starlette.sse to WARNING. The list lives in NOISY_LOGGERS in __main__.py; the config template comment and docs name every logger.

Local review fixes (in this PR)

  • DST-safe hour start.
  • A malformed payload can no longer take the whole dashboard stale.
  • The popover is keyed by the hour, so it no longer jumps at the full hour.
  • Larger touch targets, accessibility labels, debug URL params only on the dev server.

Test plan

  • pytest: 2951 passed. New: test_schedule_simulation.py (plan window, energy balance, SoC limits, grid charge clamp, isolation from CommonLogic, journal, inverter and log; core wiring; grid lock and API mode ignored), web/test_schedule_api.py (REST, MCP, 503 cases)
  • npm test: 128 passed, also under TZ St. John's, Kathmandu, Chatham, UTC (DST and 30/45-minute offsets)
  • pylint: schedule_simulation.py 10/10, package 9.74 (was 9.73)
  • mkdocs build --strict, npm run build incl. offline check
  • End to end: python -m batcontrol with the dummy inverter and the API enabled. /api/v1/schedule returns 56 slots up to midnight (morning, no day-ahead prices yet). The dashboard renders it at 390 px and 1100 px. No logic log lines from the 56 simulated runs.
  • Maintainer review on real hardware

🤖 Generated with Claude Code

MaStr and others added 2 commits December 3, 2026 08:46
Frontend-only prototype of the planned schedule tile; the backend
simulation and the /forecast/schedule endpoint follow separately.

- 25 hour boxes (current hour + 24), mode colours: grid charge amber,
  discharge blocked red, charge limited turquoise, discharge green.
- Two views: marker (majority, tie to the more important mode, bar for
  a more important mode that lost) on phones, quarters (four stripes
  per hour) on desktops. A resize across the 820 px breakpoint switches
  the view; a view picked by hand is remembered per width class.
- Popover per hour with the four quarters (mouse and tap), SoC line
  above the boxes, "plan until" marker at the end of the forecast,
  hours with less than 4 h lookahead dimmed.
- fixtures/schedule.js generates the plan around the current local
  time; scenarios schedule-short-horizon and schedule-startup.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI adaptive review requested due to automatic review settings December 3, 2026 07:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Changes are needed because the review evidence identifies an unresolved moderate compatibility issue with MediaQueryList change listeners lacking an addListener/removeListener fallback, alongside smaller maintainability and ASCII-convention nits in the schedule time calculations and template output.

3 open issues
What changed in this PR

Adds a frontend-only prototype of the “Schedule 24h” dashboard tile, backed by generated fixtures and tests, and gated so it stays hidden until the backend schedule endpoint exists.

Changes:

  • Implement schedule-to-UI helpers (hour aggregation/boxing, SoC line, quarter details) and integrate optional schedule fetching/normalization.
  • Add the new SchedulePanel component with responsive marker/quarters variants and per-hour popover details.
  • Introduce generator-driven schedule fixtures (plus scenarios) and unit/component test coverage.
File Description
frontend/​vite.fixtures.js Adds support for generating and serving forecast/schedule fixture data via a $generate: "schedule" entry in the Vite fixtures dev server.
frontend/​src/​lib/​schedule.test.js Introduces unit tests covering schedule aggregation, hour-box logic, SoC line generation, and quarter-detail formatting behavior.
frontend/​src/​lib/​schedule.js Implements schedule transformation utilities used by the UI, including hour aggregation/boxing, SoC polyline computation, and per-quarter detail formatting.
frontend/​src/​lib/​api.test.js Updates API-layer tests to mirror dev fixture behavior by generating schedule responses when fixtures request $generate: "schedule".
frontend/​src/​lib/​api.js Wires optional schedule fetching and normalization into the frontend API layer so schedule data can be consumed when present.
frontend/​src/​components/​SchedulePanel.vue Adds the Schedule 24h tile component UI, including responsive marker/quarters rendering, horizon markers/dimming, and a per-hour popover with quarter details.
frontend/​src/​components/​SchedulePanel.test.js Adds component tests for variant selection defaults and persistence across breakpoint changes.
frontend/​src/​App.vue Integrates the schedule panel into the app layout and gates rendering so it remains hidden until schedule data is available.
frontend/​fixtures/​schedule.js Adds a synthetic schedule generator that produces a realistic-looking schedule around the current local time for fixtures and tests.
frontend/​fixtures/​schedule-startup.json Adds a fixture scenario representing a mid-hour startup with an active override note for UI verification.
frontend/​fixtures/​schedule-short-horizon.json Adds a fixture scenario with a shortened forecast horizon to exercise end-of-plan UI behavior.
frontend/​fixtures/​README.md Documents how to run and use the new schedule fixtures and generator-driven scenarios.
frontend/​fixtures/​default.json Extends the default fixture configuration to include a generated forecast/schedule response entry.

Review effort: Balanced (adaptive)
Copilot was unable to complete this review at the selected tier due to model policy or plan restrictions.

Comment thread frontend/fixtures/schedule.js Resolved
…ouch)

From a local review of #528:

- hourStart() works from the instant: setMinutes(0) resolved the
  repeated hour at the end of DST to its first occurrence, so box 0
  was the hour already past and the plan reached only 23.5 h ahead.
  Same fix in the fixture generator.
- A schedule payload without a slot list is "no plan" instead of an
  exception in normalize() that marked every tile stale.
- The popover is keyed by the start of the hour, not by the box
  position, so it no longer jumps to the next hour on the hour; Escape
  and an outside click also close a hover preview.
- Touch: the whole column of an hour is the target (about 10 x 80 px
  instead of 10 x 26), a tap pins it, dragging a finger scrubs across
  the hours. Keyboard still works through the box buttons.
- No NaN for an empty schedule, the "plan until" line only inside the
  chart, SoC line starts at soc_start_percent (fallback: derived from
  the energy, never off the chart without a capacity).
- Quarters bucketed by position (60-minute slots fill four quarters,
  millisecond jitter is tolerated).
- aria-expanded/aria-controls, labels with every planned mode per hour.
- ?variant= and ?open= only on the dev server; dead "no schedule yet"
  branch removed.
- Tests: DST and 30/45-minute zones, malformed payloads, 404 on
  today's backend, popover open/close/rollover, touch, storage errors.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI adaptive review requested due to automatic review settings December 3, 2026 08:42

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

A moderate accessibility issue remains in SchedulePanel.vue where aria-controls is always bound to popId even when the popover isn’t rendered or the box isn’t expanded, leading to potentially incorrect assistive-technology relationships that should be fixed before approval.

4 open issues

Review effort: Balanced (adaptive)

MaStr and others added 2 commits December 3, 2026 10:01
New schedule_simulation.py: from the current SoC, every upcoming slot
runs through the default logic (a fresh instance per slot, fed with the
remaining forecast from that slot on); the decided mode moves the
slot's energy on an ideal battery within MIN/MAX SoC. The plan covers
the current hour plus 24 and keeps the past quarters of the current
hour as planned.

Isolation from the control loop:
- The cycle publishes one frozen ScheduleInputs under the control lock;
  the simulation reads only that object - no inverter, no lock.
- Each logic instance gets a private CommonLogic copy (new optional
  `common` argument of DefaultLogic / Logic.create_logic), so the
  loop's singleton is never written from the scheduler thread.
- The DecisionTrace is discarded: no journal entry, no MQTT.
- Logic log output is filtered on the simulating thread only.
- Active interventions (API mode, evcc block / peak shaving suspension,
  grid charge lock) are ignored and named in `overrides`.

core.py builds the logic parameters in one place for the cycle and the
preview, and the scheduler recomputes the plan on every new quarter
hour. A failing simulation is logged and keeps the last plan.

About 25 ms per plan on a desktop.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- REST /api/v1/schedule and MCP batcontrol_get_schedule through
  service.schedule(): per slot mode, SoC at start and end, battery and
  grid energy in Wh, charge rate / PV limit in W, lookahead in hours;
  503 before the first plan and once every slot has passed. Not on
  MQTT (maintainer decision).
- /schedule instead of /forecast/schedule, which the existing
  /forecast/{series} route would have answered with not_found.
- Dashboard reads the real contract: `_wh` field names, overrides as a
  list ("preview ignores: API mode"), the SoC line starts each slot at
  its reported soc_start_percent and breaks where the plan jumps from
  the planned past quarters to the real SoC.
- Fixture generator emits the API shape (checked field by field against
  the Pydantic models).
- Docs: dashboard tile, REST and MCP references, dashboard and MCP
  specs, threading model.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI adaptive review requested due to automatic review settings December 3, 2026 09:01
@MaStr MaStr changed the title Dashboard: schedule 24h tile prototype (F-01, step 1) Schedule 24h: simulation, GET /schedule, MCP tool and dashboard tile (F-01) Dec 3, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The change is blocked by an unresolved moderate bug where refresh_schedule_plan() can clobber the existing schedule_plan with None when the forecast expires (breaking the documented behavior and causing incorrect API status), alongside several ASCII-only policy violations from non-ASCII characters in frontend and schedule strings.

7 open issues

Review effort: Balanced (adaptive)

Comment thread src/batcontrol/core.py Resolved
Comment thread frontend/src/App.vue Resolved
Comment thread frontend/src/lib/schedule.js Resolved
- Keep the last plan when the simulation has nothing to plan with (e.g.
  the forecast ran out), so the API reports forecast_expired instead of
  no_data_yet. Regression test.
- MediaQueryList: fall back to addListener/removeListener (Safari < 14).
- aria-controls only on the expanded hour box.
- Fixture generator: the PV sampling offset is a named slot middle.
- docs/assets/dashboard.png shows the SCHEDULE 24H tile.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI adaptive review requested due to automatic review settings December 3, 2026 09:26
@MaStr

MaStr commented Dec 3, 2026

Copy link
Copy Markdown
Owner Author

Deployed locally with 16h Forecast cap:

grafik

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

A source-level guideline violation remains in SchedulePanel.vue where a UI string contains a non-ASCII en dash, which must be replaced with an ASCII hyphen to comply with the repo’s ASCII-only requirement.

No open issues 🎉

7 resolved since last review

Review effort: Max (adaptive)

…er hours

- log_everything: false now also raises `mcp` (and everything below it,
  one INFO line per MCP request) and `sse_starlette.sse` to WARNING. The
  list moved into NOISY_LOGGERS / quiet_noisy_loggers() in __main__.py;
  template comment and docs list every logger.
- The schedule preview ran as a job every minute that only computed on
  a new quarter hour, writing two INFO lines per minute. It is now four
  hourly jobs at :00/:15/:30/:45 plus a startup job that retries every
  10 s until the first plan exists and then drops itself.
  New scheduler helpers schedule_hourly_at() and schedule_until_done()
  log their runs at debug level only.
- A computed plan is logged at debug level (slot count, plan end).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI adaptive review requested due to automatic review settings December 3, 2026 10:15

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request due to rate limiting. Please try again later. See Usage limits for GitHub Copilot for details.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request due to rate limiting. Please try again later. See Usage limits for GitHub Copilot for details.

This branch has not been deployed

No deployments
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.

2 participants