Commit Graph
1188 Commits
Author SHA1 Message Date
b944d4adfa docs(prediction): describe the update when a provider fails
Refs #1571

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Assisted-by: Claude Code (claude-opus-5-5)
2026-11-20 18:50:25 +01:00
14acf759a7 fix(cache): leave no empty cache file after a failed cached call
cache_in_file created the cache file before it called the function. When
the call raised, e.g. a provider request answered with HTTP 500, the
empty file stayed in the store until it expired, and the next call logged
"Read failed: Ran out of input" before it called the function again. The
function is now called first; a failed call leaves the store unchanged.

Refs #1571

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Assisted-by: Claude Code (claude-opus-5-5)
2026-11-20 18:50:25 +01:00
c8f793c203 fix(prediction): update all providers before reporting a failing one
The prediction container stopped at the first enabled provider that
failed to update, so the providers after it in the sequence were not
updated in that run. A failing weather provider, at the start of the
sequence, thus also kept the electricity price, feed-in tariff, load and
PV forecasts from being updated. The container now updates all providers
and then raises one RuntimeError with the failures of all enabled
providers; with one failing provider the message is unchanged.

Refs #1571

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Assisted-by: Claude Code (claude-opus-5-5)
2026-11-20 18:50:25 +01:00
867bc38fc0 fix(config): write a migrated config file in place only with a backup
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Assisted-by: Claude Code (claude-opus-5-5)
2026-11-20 18:39:14 +01:00
fed03a0069 fix(config): write a migrated config file in place if it is not replaceable
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Assisted-by: Claude Code (claude-opus-5-5)
2026-11-20 18:39:14 +01:00
f3773de8f8 fix(config): never autosave defaults over an unreadable config file
Additional changes
The migration copies the old file to the backup instead of moving it and replaces the file atomically, only after the migration succeeded.
An explicit save keeps a copy of a file that could not be loaded and serializes the configuration before it opens the file.
The configuration guide describes the migration backup and what happens to a file that cannot be loaded.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Assisted-by: Claude Code (claude-opus-5-5)
2026-11-20 18:39:14 +01:00
887bae551b ci: install the locked environment in the test workflow
uv sync without --locked resolves again when uv.lock is out of date.
The test jobs of #1569 installed pydantic 2.14.3 and pydantic-core
2.50.4, while uv.lock pins 2.14.2 and 2.50.2, and passed. With --locked
the test jobs fail on a stale lockfile like the pre-commit job and test
the versions uv.lock pins.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Assisted-by: Claude Code (claude-opus-5-5)
2026-11-20 18:36:11 +01:00
1768e11020 ci(dependabot): update Python dependencies together with uv.lock
Dependabot used the pip ecosystem, which changes only pyproject.toml.
The pre-commit job runs uv with --locked, so every Python dependency
pull request (#1565 to #1569) failed with "The lockfile at uv.lock
needs to be updated". The uv ecosystem updates uv.lock as well.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Assisted-by: Claude Code (claude-opus-5-5)
2026-11-20 18:36:11 +01:00
4b15419b4d build(make): cap the parallel workers of test-ci
test-ci ran the tests without a server with `-n auto`, one pytest-xdist
worker per core. On a machine with 32 cores and 16 GB of memory this
exhausted the threads (Windows, `RuntimeError: can't start new thread`)
or the memory (WSL); with eight workers all parts passed (reported in
the review of this pull request).

The target now adds `--maxprocesses=$(TEST_CI_MAX_WORKERS)` with a
default of 8, so it still starts one worker per core, but at most
eight. `make test-ci TEST_CI_MAX_WORKERS=<n>` changes the limit. CI is
not affected: its jobs call pytest themselves, on runners with four
cores.

Additional changes
Describe the limit, `--maxprocesses` and `PYTEST_XDIST_AUTO_NUM_WORKERS`
in the developer documentation

Refs #1553

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Assisted-by: Claude Code (claude-fable-5-2)
2026-11-20 07:15:33 +01:00
57905b2024 ci: run the tests in parallel jobs and speed up the Sphinx build
The single test job ran all tests one after the other on one runner,
including the Sphinx build and the Docker checks (11-19 min). It is now
split so that every test still runs exactly once:

- docs-test, docker-test: the Sphinx build (new marker "docs") and the
  Docker / Home Assistant add-on checks ("docker") in jobs of their own.
- test-server: the tests that start EOS or EOSdash on the fixed ports.
  The collection hook marks every test that uses the xprocess fixture
  with "eos_server" and puts them into one xdist group, so
  "pytest -n auto --dist loadgroup" also works locally. A test that
  binds the ports without a fixture carries the marker itself.
- test-shard: all other tests in four shards of about equal runtime
  (scripts/shard_test_files.py, runtimes in scripts/test_durations.json),
  each with pytest-xdist.
- test-count: fails if these parts do not add up to the tests of one
  plain run.
- test: keeps the name of the required check. It prints the combined
  coverage report and fails if any of the jobs above failed.

COVERAGE_CORE=sysmon measures line coverage through sys.monitoring:
the report is the same, the test time drops by about a third. The
combined report misses 1-3 statements more than a single run, in lines
that only run when a test finds state left by an earlier test.

The Sphinx build spent 74 % of its time in one search of
PythonDomain.find_obj (sphinx-doc/sphinx#11282). The local extension
docs/_ext/pyxrefindex.py answers it from an index of name endings with
the same matches in the same order; a build has a byte-identical
objects.inv. It copies the logic of Sphinx 9.0.4 and is only active for
that version; TestPyXrefIndex compares it with the installed Sphinx and
fails after a Sphinx update until the version is raised. The
documentation test builds with -j (up to four jobs); its pages can
differ from a serial build in the target of ambiguous cross-references.
Read the Docs builds without -j. Sphinx build on GitHub runners:
427-480 s -> 180-233 s.

make test-ci runs the commands of these jobs one after the other.

On GitHub runners the tests are done after about 2 minutes; the
required check ends with docs-test after about 4-5 minutes.

Additional changes
Add pytest-xdist to the development dependencies
List the 25 slowest tests in each test job (--durations=25)
Test version() directly; it was covered only through the Sphinx test
Add a "Keep Tests Fast" tip, the server marker rule, the extension and
test-ci to the development guide and the testing skill

Refs #1553

Co-authored-by: SchaafAlexander <86607129+SchaafAlexander@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Signed-off-by: SchaafAlexander <86607129+SchaafAlexander@users.noreply.github.com>
Assisted-by: Claude Code (claude-opus-5-5)
Assisted-by: Claude Code (claude-fable-5-2)
2026-11-20 07:15:33 +01:00
e2726354c2 test: make slow and order-dependent tests fast and independent
Slow tests:
- TestPerformance inserted 10 000 records three times per backend. One
  test per backend now times insert, save and load on the same records,
  with the same assertions.
- test_measurement_realtime_stream slept one second per update, 20 s per
  backend. The updates use synthetic timestamps one second apart in the
  recent past, without a pause, and send the same duplicates,
  out-of-order and burst writes.
- test_readers_never_see_a_partial_document: the readers spun on the
  cache and kept the writer waiting for the GIL (~50 s). They now yield
  with time.sleep(0) after each lookup (~0.5 s); a non-atomic save still
  fails the test 10 of 10 times.
- test_devicessettingsbattery.py compiled the same plain profile before
  each of its 235 tests. A module-scoped fixture compiles it once; a
  compiled profile is frozen and may be shared (20.8 s -> 9.4 s).
- The --finalize case of test_geneticoptimize.py runs 250 instead of
  400 generations. For this input and seed the best fitness is final in
  generation 213, and the solutions after 250 and 400 generations are
  identical field by field. The test checks the keys and the consistency
  of the result, not the schedule, so it detects the same as before
  (127 s -> 80 s on GitHub runners). test_genetic0optimize.py keeps 400.

Tests that depended on another test of the same process, found by
running them in another order and under pytest-xdist:
- TestPredictionContainer::test_len relied on a class flag that a
  TestPredictionProvider fixture set and never reset. Both fixtures now
  set the flags with monkeypatch.
- The EnergyCharts status code test got a cached response from an
  earlier test; it now calls _request_forecast(force_update=True) and
  asserts that the request was made.
- test_ingress_safe_links did not wait for EOSdash, which EOS starts
  after its own startup.
- test_forward_stream_truncates_very_long_line found the log queue left
  behind by test_server_start_eosdash (no worker, closed event loop). It
  installs its own queue now, and test_server_start_eosdash no longer
  leaves its queue behind. Dropping lines from a full queue was only
  covered through that left-over queue and gets a test of its own.

Refs #1553

Co-authored-by: SchaafAlexander <86607129+SchaafAlexander@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Signed-off-by: SchaafAlexander <86607129+SchaafAlexander@users.noreply.github.com>
Assisted-by: Claude Code (claude-opus-5-5)
Assisted-by: Claude Code (claude-fable-5-2)
2026-11-20 07:15:33 +01:00
ce7fb96faf fix(database): reopen SQLite at the current data folder
SQLiteDatabase resolved its file once, in __init__. open() then created
the directory of the current storage_path but connected to the old file.
Database keeps the backend while the provider stays the same, so after a
data folder change and a reopen, EOS kept reading and writing the database
of the old folder. LMDB resolves its directory on every open and was not
affected.

Tests showed it as order dependence: test_count_records[SQLite] found the
five records of test_load_records_with_range[SQLite] when both ran in a
row. Under pytest-xdist, ten SQLite tests failed this way.

open() now resolves the file from the current storage_path, like LMDB.

Refs #1553

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Signed-off-by: SchaafAlexander <86607129+SchaafAlexander@users.noreply.github.com>
Assisted-by: Claude Code (claude-fable-5-2)
2026-11-20 07:15:33 +01:00
00a39f75bf perf(datetimeutil): parse ISO 8601 instants without the format search
to_datetime() tried ten pendulum formats before an ISO 8601 date-time
with "Z" or an explicit offset reached pendulum.parse(). None of the
formats can match such a string (each is combined with a timezone
name), so every call paid ~190 µs for nothing. Database timestamps
("20241027T123456Z") take this path on every record lookup
(db_get_record, _db_timestamp_after, key_from_series), and so do API
and provider date-times.

These strings name one instant and are now parsed directly (~7 µs),
built with pendulum.datetime() like pendulum.parse(), so the result
keeps the same fold. Any other form, offsets of 24 hours or more and
out-of-range fields still go through the generic parser. Compared with
the previous to_datetime() over 162 432 calls (5076 strings, 8 target
zones): no difference in value, timezone, fold or raised exception.

DatabaseTimestamp.from_datetime() formats with an f-string instead of
the format-token parser of pendulum (6 µs -> 2 µs), with the same output
for every 4-digit year. Its docstring example shows the stored form
"20241027T123456Z".

The five DB/EnergyCharts test modules: 298 s -> 112 s.

Additional changes
Test the config returned to a re-entrant get_config(); the full suite
reached that line only as a side effect of slow tests

Refs #1553

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: SchaafAlexander <86607129+SchaafAlexander@users.noreply.github.com>
Assisted-by: Claude Code (claude-opus-5-5)
2026-11-20 07:15:33 +01:00
Bobby NoelteandClaude Opus 5.5 cc875f798c feat(measurement): treat long *_emr_keys meter gaps as unknown
Additional fixes:
Add timezone to loadakkudoktoradapted tests datetime generation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Assisted-by: Claude Code (claude-opus-5-5)
2026-11-15 18:30:00 +01:00
Bobby NoelteandClaude Opus 5.5 f441759dfa fix(measurement): use quality-aware meter energy for load and PV
Additional fixes
Measurement.meter_energy_kwh converts meter energy over the whole period in one read; the 31-day and 10000-interval limits apply to the public energy queries only.
Load intervals a meter does not fully cover are NaN and the load adjustment skips them; load_total_kwh returns an empty array for an empty store and keeps full last intervals.
The load adjustment compares over the period the load meters report, skips a stale load meter period and says when no load meter is configured.
PV calibration, snow feedback and the load adjustment fall back without measurements when a conversion fails, logged as error once per failure streak and consumer.
Measurement.keys_first_datetime and keys_last_datetime find each meter's first and last valid reading in bounded scans, keep each meter's newest reading and return stamps in the configured zone.
Measurement.keys_common_period derives the common meter period for PV calibration and the load adjustment and names the meter that ends it, also when meters share no period.
PV calibration warns once per stale period when a stopped PV meter holds it on old data; snow feedback warns once about a stale feedback meter.
Lasting meter conditions (silent, reset, gap, replaced meter, no shared period) are warned once per condition and consumer through one helper and warned again when they recur.
A replaced meter whose readings touch the new one is reported; a single reading is not; a meter group waiting for its second reading is an info once.
The PV meter resolution is detected from valid readings only (pre-existing), using one shared valid-reading rule in energy.py.
Stale meter stamps are compared with compare_datetimes; new meter tests create durations with datetimeutil.
The unused legacy Measurement._energy_from_meter_readings is removed; its test scenarios cover meter_energy_kwh.
The converter's range error no longer mentions the API's 31-day limit, and its duplicate interval check is gone.
Measurement and prediction docs describe the meter coverage rule, even gap spreading and when the load forecast stays unadjusted.
Tests reset the warn-once state of the shared measurement store and restore the EMS start they change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Assisted-by: Claude Code (claude-opus-5-5)
2026-11-15 18:30:00 +01:00
Bobby NoelteandClaude Opus 5.5 2bfb6eafab fix(pvforecast): align the calibration window to the UTC slot grid
Additional fixes
PV meter energy comes from the quality-aware conversion.
Calibration rows are binned by interval start with end-stamped rows.
The fit covers only the period every PV meter covers and stays inside its lookback.
The meter resolution is judged only where every PV meter reports.
Snow feedback derives its window from the same slot window helper and shares one PV meter read per forecast with calibration.
Window bounds and pandas timestamps are converted in one place, always to UTC; fit days are counted in the configured zone.
Calibration tests write meters in bulk, stamp them in the configured zone and check every azimuth bin; snow feedback has its own slot window test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Assisted-by: Claude Code (claude-opus-5-5)
2026-11-15 18:30:00 +01:00
NormannandGitHub 6fad58655f build(deps): update dependencies
dnspython 2.9.2
Tornado 6.6.1
2026-11-15 17:09:24 +01:00
45a6377b60 fix(genetic): keep a deadline from capping the DAILY appliance estimate
The tail estimate queried its probe appliance with the configured
deadline. A deadline inside the control horizon then left no start on
the following days: with BEST_EFFORT the 48 h tail held one run and
logged "deadline can not be met" twice per run, with STRICT it held no
appliance load. The deadline only limits the run it was set for, so the
probe leaves it out.

Additional changes
Test the tail load with a deadline inside the control horizon for both deadline policies

Refs: #1495
Signed-off-by: SchaafAlexander <86607129+SchaafAlexander@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Assisted-by: Claude Code (claude-opus-5-5)
2026-11-15 15:10:57 +01:00
d9a5ac0b0b fix(genetic): count a run in progress in the DAILY appliance estimate
Since #1549 a run in progress counts as the run of its day and delays
the next cycle until after its end and the minimum gap. The DAILY
appliance estimate of the tail and terminal value now does the same
(completed_cycles_on, next_cycle_earliest_slot), so a running appliance
is not expected to run a second time on that day.

Additional changes
Format the tail load expression and the estimate docstring (ruff format)
Test the estimate with and without a reported run in progress

Refs: #1495
Signed-off-by: SchaafAlexander <86607129+SchaafAlexander@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Assisted-by: Claude Code (claude-opus-5-5)
2026-11-15 15:10:57 +01:00
ChenYi-NnergyandBobby Noelte a344e04ca5 fix(genetic): include DAILY appliance load in tail and terminal value
With terminal_value_mode AUTO, the tail and the continuation curve only
saw the base load: appliance load is added to consumption inside
simulate() but never reached either curve. Stored battery energy was
therefore valued at 0 ct/kWh over a wide SoC range, and the optimizer
drained the battery to run scheduled appliances instead of using cheap
night grid energy.

Both curves now include the expected load of DAILY home appliances: one
run per local day and cycle at its earliest allowed start within its
window, with the minimum cycle gap. Days whose run is already planned in
the control horizon are not counted again in the tail. ONCE appliances
are left out.

Squashed from PR #1540 (6 commits) onto main e40ff7f.

Closes: #1495
Signed-off-by: SchaafAlexander <86607129+SchaafAlexander@users.noreply.github.com>
2026-11-15 15:10:57 +01:00
Bobby NoelteandClaude Opus 5.5 ebb440238a chore: untrack the generated docs that test_doc writes into tests/testdata
Assisted-by: Claude Code (claude-opus-5-5)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 14:36:53 +01:00
e40ff7f6e3 fix(genetic): date a run in progress in the time zone of the horizon
The start day of a run in progress decides which DAILY cycle it counts
for. Take it in the time zone of slot 0, which also dates the cycles.

The cycle counting test gave its times with a +01:00 offset, so on a
runner in UTC the run started on the previous day and was rightly not
counted for today. It now uses local times without offset and passes in
local time zones from UTC-12 to UTC+14.

Refs: #1548
Signed-off-by: SchaafAlexander <86607129+SchaafAlexander@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Assisted-by: Claude Code (claude-opus-5-5)
2026-11-15 13:54:22 +01:00
4693e1fa97 fix(genetic): keep a started home appliance run until the device reports it finished
A re-plan treated a running home appliance as not started. In its start
slot it could pick another start of equal cost and switch the appliance
off; after the start slot it could only plan a new complete run later; and
when no complete run fitted into the rest of the window, the DAILY cycle
was dropped and the running appliance got OFF.

The executor now reports the start of a planned run as UNIX seconds under
`<device_id>.run_started_at` (setting `run_started_measurement_key`) and 0
when the device reports the run as finished. The device decides when that
is, also before or after the configured duration. Until then the GENETIC
optimizer places the remaining energy from now on as fixed load,
independent of windows, deadline and genes, sends RUN, counts the run as a
cycle of its start day and plans further cycles after its end and gap. A
run past its duration keeps the current slot without extra energy; a start
more than two run durations ago, or an invalid value, is logged and
ignored.

Refs: #1548
Signed-off-by: SchaafAlexander <86607129+SchaafAlexander@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Assisted-by: Claude Code (claude-opus-5-5)
2026-11-15 13:54:22 +01:00
0bf9f50b97 fix(genetic): plan the running slot only for the remaining time
A run within a slot (e.g. 10:45 with hourly slots) planned slot 0 as a
full slot, although the SoC is measured at the run time. Slot 0 now moves
only the remaining part of the slot energy: battery, EV and inverter
energy caps, SoC power limit tables and the slot's PV and load forecast
are scaled by first_slot_fraction; efficiency curves are read at the
power of that part. The plan's SoC headroom clamp of the AC charge factor
uses the same part, and the GENETIC result reports first_slot_fraction.
A run on a slot boundary is unchanged.

Additional changes
Pin GENETIC test start times to the full hour; their results now depend on seconds within the slot
Document first_slot_fraction for consumers of GENETIC results

Refs: #1543
Signed-off-by: SchaafAlexander <86607129+SchaafAlexander@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Assisted-by: Claude Code (claude-opus-5-5)
2026-11-15 12:45:56 +01:00
Bobby Noelte 7e10f64048 chore: development version update (incl. home assistant config)
Signed-off-by: Bobby Noelte <b0661n0e17e@gmail.com>
2026-11-12 22:59:31 +01:00
Bobby NoelteandClaude Opus 5.5 88904874e7 fix(version): keep VERSION_DATE in _version_date.py up to date
Additional fixes
Use a portable shebang instead of the workspace .venv in update_version.py
Update the stale VERSION_DATE of 2026-02-24 to 2026-11-12

Assisted-by: Claude Code (claude-opus-5-5)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 22:01:05 +01:00
Bobby NoelteandClaude Opus 5.5 14e439c265 ci: run the AI self-review check on pull_request
GitHub blocks pull_request_target by default in public repositories from
December 2, 2026. The ai-self-review workflow now runs on pull_request.
It still checks out and runs the check script of the base branch and no
other code of the pull request. The workflow file itself now comes from
the pull request, so a pull request that changes it can weaken its own
check. .github/CODEOWNERS therefore makes a maintainer the code owner of
the workflows, CODEOWNERS and the check script; this is enforced once the
branch protection of main requires a review from code owners.

Additional changes
- Record the switch in ADR 0002, which supersedes the pull_request_target
  consequence of ADR 0001.
- Skip the comment step for pull requests from forks, whose token is
  read-only, and point their error message to the job summary only.
- Describe the trigger, code owners and fork limits in docs/develop/ai.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Assisted-by: Claude Code (claude-opus-5-5)
2026-11-12 22:00:42 +01:00
NormannandGitHub eb4b34f194 build(deps): combine Dependabot updates (#1527)
types-PyYAML 6.0.12.20260906 → 6.0.12.20261103
types-requests 2.33.0.20261006 → 2.33.0.20261030
tzfpy 2.1.1 → 2.1.2
cachebox 6.2.8 → 6.2.10
pypdf 6.21.4 → 7.0.0
2026-11-12 19:34:57 +01:00
b4d2d7b2aa fix(genetic): same plan on every CPU (fixed-order dot products, stable sort of equal prices) (#1518)
* fix(genetic): sum the self-consumption dot products in a fixed order

GENETIC gave different plans for the same input and seed on different
CPUs. SelfConsumptionProbabilityInterpolator computed its two dot
products with np.dot, which calls BLAS; OpenBLAS picks a ddot kernel per
CPU at run time (and macOS uses Accelerate), and the kernels sum in
different orders, so the result differs in the last bit. The optimizer
compares fitness values exactly, so one bit is enough for a different
plan.

fixed_order_dot() adds the rounded products in index order with Python
floats, without BLAS: the same result on every CPU. The vectors have one
entry per 50 W load bin and the results are cached per (load, PV) pair,
so the run time does not change noticeably. Plans change once in the
last bits compared with the previous np.dot result of a given CPU.

* fix(genetic): sort equal prices of the terminal value window in slot order

np.argsort with the default kind (quicksort) leaves the order of equal
values to the platform: NumPy sorts with SIMD kernels on x86-64
(x86-simd-sort) and with introsort elsewhere. Slots with the same price
then fill the terminal value curve in another order, the battery
capacity cuts it elsewhere, and the same input and seed gave another
plan on x86-64 than on aarch64 (seen as a native-vs-Python compare
difference on x86-64 in
test_plan_keeps_reserve_for_a_peak_beyond_the_control_horizon).

The window is now sorted with kind="stable": slots with the same price
keep their slot order on every platform. Same goal as the dot product
change in this PR: the same input gives the same plan on every CPU.

Assisted-by: Claude Code (claude-opus-5-5)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 19:05:43 +01:00
43cb0f04b2 docs(eosdash): describe the setup assistant (#1516)
Add a how-to page for the first setup with the EOSdash setup assistant and link it from the documentation index, the getting started tutorial and the README.

The status of the measurements step is derived from the configuration only. Say what that means for a system that sends the state of charge on its own.

Add the new Home Assistant step to the list of steps, say that the Home Assistant 
adapter needs EOS to run as an add-on and that an automation has to act on the 
instructions, and update the screenshot to the eleven steps.

The devices step of the setup assistant now asks for the size of each unit,
because the packaged battery and inverter profiles are generic and give no
capacity or nominal power. Say so on the setup page, point to the Profiles
page and link the battery configuration and the inverter profiles.

Signed-off-by: SchaafAlexander <86607129+SchaafAlexander@users.noreply.github.com>
Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-12 14:47:10 +01:00
fca524a913 feat(eosdash): add the remaining steps to the setup assistant - #1515⁠
The setup assistant only covered the location, the horizons and the energy
management, and sent the user to the Config page for everything else.

Add the steps PV system, weather, prices and fees, load, devices and
measurements, each with an explanation, an example and a check of what is
still to do.

Add a Home Assistant step after the measurements step that explains what EOS
reads from and writes to Home Assistant, with a template sensor and an automation
as example. Its status reports a missing state of charge mapping, missing instruction
entities and an adapter that is selected while EOS does not run as an add-on. The
measurements step keeps the choice of the adapter.

Add examples for an inverter, an electric vehicle and a home appliance.

A step can now show configuration values depending on the value of another
one (WizardChoice), so that only the settings of the selected provider are
shown. The horizon of the selected optimization algorithm uses the same
mechanism instead of a placeholder in the configuration name.

Describe the profiles, point to the Profiles page and use the
profile_adjustment settings in the examples. The packaged profiles are
generic and give no size, so the devices step now reports a battery,
electric vehicle or inverter whose effective nominal capacity or power is
unknown. The changelog entry names the Home Assistant step.

Signed-off-by: SchaafAlexander <86607129+SchaafAlexander@users.noreply.github.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Assisted-by: Claude Code (claude-fable-5-2)
2026-11-12 13:35:37 +01:00
8e94ab02d1 fix(eosdash): describe the automatic saving of the configuration in the setup assistant
The setup assistant said a changed value is only written to the configuration file by the save button of the last step. By default EOS saves configuration changes on its own (general.config_save_mode AUTOMATIC). Say so, and show general.config_save_mode in the last step.

Signed-off-by: SchaafAlexander <86607129+SchaafAlexander@users.noreply.github.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Assisted-by: Claude Code (claude-fable-5-2)
2026-11-12 10:40:57 +01:00
7f4014c408 feat(eosdash): add a setup assistant for the basic configuration
New users have to find the settings EOS needs among all configuration values
on the Config page, without a hint which ones matter or what is still missing.

The new Setup page takes the user through the configuration step by step.
Each step explains a few settings, gives an example, reports what is still to
do and shows the configuration cards of exactly these settings. The cards are
the ones of the Config page; the code that creates a card and sends an update
moved out of Configuration() into config_card() and config_update().

The assistant keeps no state: the step travels with the requests and the
status is derived from the EOS configuration, which is read and written
through the EOS server only.

First steps: location, horizons and energy management, save the configuration.

Signed-off-by: SchaafAlexander <86607129+SchaafAlexander@users.noreply.github.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Assisted-by: Claude Code (claude-fable-5-2)
2026-11-12 10:40:57 +01:00
Bobby NoelteandClaude Opus 5.5 3bcc902104 feat(eosdash): add the profile page for battery and inverter profiles
The new Profiles page of EOSdash lists the user and packaged battery and
inverter profiles and edits them as JSON: preview without saving, save,
save as and delete, or revert a user profile to the packaged one. Saved
profiles apply at once.

One toolbar row holds the profile kind and profile selection, the Edit
button, the Share link and the status of the last action. A compact grid
summarizes the profile. A battery profile shows its charge and discharge
limit maps as heat maps as EOS evaluates them (with the exact hard
cutoffs) and its efficiency curves; an inverter profile its power at
45 degC, the DC→AC and AC→DC efficiency curves over the load fraction and
the power derating over the ambient temperature with 45 degC marked. Both
show the profile as highlighted JSON with a copy button. The sections are
collapsible and keep their state across actions.

The editor is shown only in edit mode: Edit in the toolbar opens it above
the plots, Close in the editor or Close editor in the toolbar ends it.
Edit mode is kept after preview, save and save as and across profile
changes.

Share opens a new issue with the battery or inverter profile issue form,
filled in with the profile, so users can propose their profiles for
packaging with EOS; each form asks for consent to publish the values under
Apache-2.0. EOS sends nothing itself.

Additional changes
- Add a compact variant to ConfigSection and status messages in the theme
  colors, readable in dark mode, to the EOSdash components.
- Use the muted theme color for explanatory texts.
- Check profile names before saving.
- Show the paste instruction for profiles too large for the share URL as
  text, not only as tooltip; name the selections for screen readers.
- Keep the toolbar layout when the profiles cannot be listed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Assisted-by: Claude Code (claude-opus-5-5)
2026-11-11 22:08:18 +01:00
Bobby NoelteandClaude Opus 5.5 faf37abfe7 feat(devices): add inverter profiles
An inverter profile describes the technical data of an inverter model: its
nominal AC power, the DC→AC and AC→DC efficiency curves over the load
fraction (AC power relative to the nominal power), the AC charge power
limit of the model, whether that limit also limits PV charging, and an
optional power derating over the ambient temperature. Curves are read
linearly and clamped at their ends, so every lookup yields a value. The
packaged profile generic-hybrid has typical hybrid inverter efficiencies,
no nominal power (the inverter device has to provide it) and full power up
to 45 degC.

Inverter settings name their profile (inverter_profile, default
generic-hybrid) and hold the differences of the unit in profile_adjustment:
nominal_power_w (replaces the profile value, required for a generic
profile), max_power_w and max_ac_charge_power_w (installation limits that
can only lower; an AC charge limit of 0 disables AC charging). The
effective parameters are resolved at the ambient temperature of the
inverter, given by the new measurement key <device_id>-temperature-degc
(45 degC without a fresh value); the power derating lowers the maximum
power and the AC charge limit.

Optimization parameters are always valid: the GENETIC and GENETIC0
parameter preparation resolve the inverter with
resolve_current_operating_parameters_or_defaults, which never raises. An
unusable profile gives the generic-hybrid profile, a missing nominal power
the fallback of 10000 W, an inverter derated to zero power the parameters
at 45 degC, and no usable profile at all the profile adjustment with
constant efficiency; each is logged as error. The GENETIC inverter takes
the AC→DC efficiency curve of the profile, solved exactly on each linear
piece of the curve (about 2 % longer runs); GENETIC0 keeps constant
efficiencies and no longer replaces the configured inverters with the demo
inverter; a battery, electric vehicle or inverter that cannot be prepared
is left out of the GENETIC0 run, never replaced by a demo device.

Configurations migrate: max_power_w becomes
profile_adjustment.nominal_power_w, max_ac_charge_power_w moves into the
adjustment, an ac_to_dc_efficiency of 0 keeps AC charging disabled, and
the efficiency fields are dropped with an error log, as for batteries, so
the profile efficiencies apply. Home Assistant config paths follow.

Additional changes
- Move the curve algorithms of the battery profile into profilecurve, so
  battery and inverter profiles share them; the battery profile keeps its
  document format and classes.
- Move ProfileBaseModel, the strict base of profile documents, into
  profilestore.
- Serve inverter profiles through the profile REST API. Refuse to delete a
  profile that a configured device uses and that has no packaged profile
  to revert to (409).
- Share the measurement access of the device settings in
  devicemeasurement.
- Rename check_battery_profiles to check_device_profiles; the device
  profile check at configuration setup covers inverters, too.
- Document inverter profiles, their configuration, defaults and sharing;
  regenerate the configuration and OpenAPI documentation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Assisted-by: Claude Code (claude-opus-5-5)
2026-11-11 22:08:18 +01:00
Bobby NoelteandClaude Opus 5.5 e255f987bf feat(devices): add battery profiles
A battery profile describes a battery model: the charge and discharge limit
maps over temperature and SoC, the charge and discharge efficiency curves
over C-rate, the technical SoC bounds, the hard temperature cutoffs and,
for a model, its nominal capacity and power limits. EOS packages the
generic profile generic-lfp; users add their own profiles.

A battery or electric vehicle selects its profile by battery_profile and
describes how the installation differs from it in profile_adjustment
(capacity, power limits of the installation, periodic full charge). The
effective values are resolved from both at the measured operating point
(temperature, SoC, power) and shown as effective_* fields.

The GENETIC simulation uses the limits and efficiencies of the profile over
SoC, with precomputed tables as a fast path; GENETIC0 gets the values at the
operating point. Optimization parameters are always valid: a battery whose
profile is missing, unreadable or invalid uses the packaged generic-lfp
profile, and the former defaults only if that is not usable either; each is
logged as error, and an optimization run is never cancelled because of a
battery.

Additional changes
- Add a generic device profile store: user and packaged profiles, atomic
  saves, compiled profiles cached per file and checked again at most once a
  second, plain file names as profile names ('schema' is reserved). On
  Windows, a save or read that collides with the other is retried briefly.
- Add the REST API /v1/profile to list the profile kinds and to list, read
  (document and JSON schema), save and delete profiles.
- Check the hard temperature cutoffs on the exact temperature.
- Resolve inhibited charging or discharging to a power of 0, e.g. for a cold
  battery; give GENETIC0 its own discharge limit for that.
- Limit generic profiles without own power limits to the former 5000 W.
- Accept only the implemented units; current limits need the nominal
  voltage.
- Migrate legacy battery settings into the profile adjustment, keep the
  former charge power limit as discharge limit (also for a Home Assistant
  entity on it) and report dropped efficiencies as errors.
- Limit GENETIC battery discharge by the discharge power.
- Allow battery profile lookups while the configuration is created.
- Resolve a battery once per configuration dump.
- Package the bundled profiles, document battery profiles and regenerate
  the configuration and OpenAPI documentation.
- Ignore the report PDFs written by the visualization tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Assisted-by: Claude Code (claude-opus-5-5)
2026-11-11 22:08:18 +01:00
Bobby NoelteandClaude Opus 5.5 dd41e5d57c chore(ai): add agent self-review and a CI check for agent-assisted PRs
Additional changes
Agents write a task plan to .scratch/<branch>/plan.md and self-review with code-review
Agents fix hard violations, report judgement calls and rerun the self-review before every push
Agents declare the review in a Self-review section of the pull request body
Add the ai-self-review workflow and scripts/check_pr_self_review.py for pull requests into main
Detect agents by Assisted-by or Anthropic Co-Authored-By trailers, body markers or the AI box
Fail only on a missing Self-review section or a missing, malformed or stale Reviewed SHA
Note an unticked AI-assisted box and malformed optional lines without failing
Comment on the pull request how to fix a failure and update that one comment on later runs
Show the same report in the job summary and accept Windows line endings in the body
Skip dependabot and release pull requests
Run on pull_request_target with the base branch's script, never pull request code
Add the pull request template: the pr skill's sections plus Checklist and Self-review
Require always valid optimization parameters in the energy-domain skill
Require datetimeutil for date and time handling in new and changed code in AGENTS.md
Require the Assisted-by trailer on agent commits in the commit-messages skill
Add tests for the check in tests/test_ai.py
Add GLOSSARY.md and the agent tracker docs in docs/agents/
Add decision record docs/adr/0001 with an ADR index in the docs toctree
Document the workflow in docs/develop/ai.md and CONTRIBUTING.md
Exclude docs/agents from Sphinx and PyMarkdown and ignore .scratch/
Document cz check instead of make gitlint for commit messages in docs/develop/ai.md

Assisted-by: Claude Code (claude-opus-5-5)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 15:37:33 +01:00
62cbf4cf2a fix(homeassistant): apply 0 and off from config entities, never add settings
The configuration sync of the Home Assistant adapter skipped every value that is false in
Python, so an entity state of 0 or off never reached the configuration. It also set any
path it was given: the documented example devices/batteries/0/capacity_wh named a device
"0" that does not exist, so EOS silently added a new battery with a random device id.

Apply every value except an unavailable or unknown entity, and only update settings that
exist; report other paths as an error. The example now addresses the battery by its
device_id.

Signed-off-by: SchaafAlexander <86607129+SchaafAlexander@users.noreply.github.com>

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 09:38:45 +01:00
elschmanandGitHub 1fda5f9201 fix(doc): compose file in README
Without a docker compose the recommended install part of the documentation will not work at all
2026-11-11 09:36:16 +01:00
7767028a14 fix(config): keep dict entries with "/" in keys during config migration
The automatic field migration recursed into every dict and addressed each
leaf by a "/"-joined path. Keys that themselves contain "/" - e.g. the config
paths used as keys of adapter.homeassistant.config_entity_ids - were split
into path elements. set_nested_value() then created a "devices" entry with
an empty string default and failed further down, so every version migration
replaced the mapping by {"devices": ""}.

Migrate a dict whose keys contain "/" as one value instead of per key.

Signed-off-by: SchaafAlexander <86607129+SchaafAlexander@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-10 12:50:41 +01:00
Bobby Noelte 93ccb8d592 chore: development version update (incl. home assistant config)
Signed-off-by: Bobby Noelte <b0661n0e17e@gmail.com>
2026-11-09 17:05:56 +01:00
Bobby NoelteandClaude Opus 5.5 2c58874c52 fix(cache): use a reproducible function hash for cache_in_file keys
Build the cache_in_file key from an MD5 hash of the wrapped function
instead of inspect.getsource(). Reading the source fails for functions
whose source is not on disk, and the key could go stale when the file
changes after import.

The hash covers what decides the result besides the arguments: the
qualified name, the bytecode with the names of called functions,
attributes and globals, the constants including nested functions, the
defaults and the values captured from an enclosing function. Wrappers made
with functools.wraps are unwrapped. Code objects, functions and sets are
hashed without memory addresses or hash-seed dependent order, so the key
stays the same across restarts and the file cache keeps hitting.

Additional fixes
- Build the key from the arguments bound to the signature, so *args,
  **kwargs and the arguments of wrapped functions are part of it.
- Apply control parameters given at call time to that call only; they no
  longer change the decorator settings for later calls.
- Apply all control parameters of a call, so until_date is no longer
  dropped when force_update is also passed; keep the precedence
  until_datetime > with_ttl > until_date.
- Recreate an unreadable cache file in that call only, instead of
  disabling the cache for the rest of the process.
- Pass force_update in two provider tests that relied on a force_update
  left over from an earlier test.
- Fix "Calback" typo in cache_energy_management_store_callback docstring.

Signed-off-by: Bobby Noelte <b0661n0e17e@gmail.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 16:16:26 +01:00
ChenYi-NnergyandGitHub 38b07f5a5b fix: apply inverter_paco cap and system loss in PVForecastPVLib - #1504⁠
Planes sharing one inverter_paco feed a single physical inverter, but their AC output was summed without any cap, so a 15 kW inverter could report 21-25 kW. This PR groups the per-plane AC output by inverter_paco and clips each group's sum to its rating; planes without a rating are left alone. It also applies the configured system loss (PVGIS-style percent, same semantics as PVForecastAkkudoktorLocal) to DC and AC output instead of warning that it is unsupported.
2026-11-09 14:41:16 +01:00
Bobby NoelteandClaude Opus 5.5 b92d115a39 test(eosdash): wait for the htmx swap before checking a tab's content
The browser test read the content area right after the tab's response
arrived. htmx swaps the response in after that, and wait_for_load_state()
did not wait for it, as the page itself was loaded long before. For the
large configuration tab the content area was sometimes still empty, so
the test failed in CI.

Wait until the content area is filled again after a successful response.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 14:21:51 +01:00
c230d9d9de fix: keep tests and doc generators away from the developer's config files
test_docsphinx pointed EOS_DIR/EOS_CONFIG_DIR at an empty temporary
directory. EOS then fell back to the config file in the user config
directory, migrated it and wrote it back with a timestamped backup. The
test now writes an empty config file into the temporary directory, as
server_base does.

Additional fixes
- Decode the Sphinx output in test_sphinx_build as UTF-8; on Windows the
  default code page failed and the test reported a NoneType error.
- Check the user config directory with the app author in
  --check-config-side-effect, as EOS does; on Windows the check looked at
  the wrong directory.
- Let the doc generators create EOS' config file in a temporary directory.
  They left an EOS.config.json in the working directory, and a following
  make test-ci then failed in every test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 13:40:25 +01:00
Bobby NoelteandClaude Opus 5.5 d68f040206 feat(ai): add the mattpocock engineering skills for AI agents
Vendor the engineering skills of https://github.com/mattpocock/skills into
ai/skills/engineering, with their MIT license, and list them in AGENTS.md.
The agent-specific metadata (agents/openai.yaml) is kept for other agents.

Additional changes
- Add scripts/update_mattpocock_skills.py to compare the copy with upstream by
  git blob hashes from a blobless clone and to update it on request.
- Add tests/test_ai.py; it warns when the copy differs from upstream and caches
  the upstream hashes in the pytest cache for a day.
- Document the engineering skills in docs/develop/ai.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 12:45:20 +01:00
Bobby NoelteandClaude Opus 5.5 57132df44e fix(config): enable documentation mode only explicitly
ConfigEOS.documentation_mode() was true as soon as Sphinx was imported
anywhere in the process. A test importing Sphinx therefore switched all
later tests into documentation mode, and test_config_md_current failed
depending on test order. Documentation mode is now enabled only by the
documentation generators (_force_documentation_mode) or by the Sphinx
configuration, which sets sys._called_from_sphinx in docs/conf.py.

Declare _force_documentation_mode as a ClassVar. Without the annotation
pydantic turned it into a private attribute, and the class attribute was
a truthy descriptor object.

Behavior change: because of that descriptor, every running EOS was in
documentation mode, so the get_adapter/config/measurement/prediction/ems/
database/resource_registry() guards never raised "access before init" and
created the singletons lazily on first access. They now raise for every
access before initialization. The worker process of uvicorn's auto-reload
(server.reload, make run-dev) relied on that: the app's lifespan now sets up
the configuration and initializes the singletons that do not exist yet.

Leave runtime state out of the documentation: the Home Assistant entity ID
properties and OptimizationCommonSettings.keys return an empty list in
documentation mode, so entity IDs and solution keys of a running system
no longer reach the generated configuration docs.

Keep the tests isolated: test_doc sets documentation mode on the class
and test_docstringrst restores sys._called_from_sphinx after reading the
Sphinx configuration. Add tests for how documentation mode is enabled and
for the runtime values it leaves out.

Additional changes
- Generate openapi.json in documentation mode, as the config docs.
- Share the documentation mode check as coreabc.documentation_mode().
- Move the logging and server address setup of run_eos() to setup_eos_config().
- Test that EOS starts with server.reload.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 12:40:15 +01:00
Bobby NoelteandClaude Opus 5.5 a0e57a18b7 fix(config): validate prediction providers before the prediction exists
The provider settings (weather, PV forecast, load, electricity price, feed-in
tariff, electricity fee) validate their provider id against the providers of
the prediction instance. While the configuration is created, that instance
does not exist yet, and the validation falls back to fixed lists. These were
incomplete: weather knew only 'WeatherImport', load lacked
'LoadAkkudoktorAdjusted'. A configuration file with e.g. weather provider
'OpenMeteo' then fails to load:

  Provider 'OpenMeteo' is not a valid weather provider: ['WeatherImport']

This is hidden today because ConfigEOS.documentation_mode() is always true
(_force_documentation_mode is a pydantic private attribute, whose class
attribute is a truthy descriptor), and get_prediction() then creates the
prediction instance on access. Once documentation mode is enabled only
explicitly, the configuration does not load.

Derive the provider ids from the provider classes instead
(prediction_provider_ids). They no longer depend on whether the prediction
instance exists, so the validation is the same before and after
initialization.

Additional changes
- Add the test fixture uncreated_config, which lets get_config(init=True)
  create a new configuration from the config file and restores the old one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 12:40:15 +01:00
Bobby NoelteandClaude Opus 5.5 4475774c06 test(eosdash): run EOSdash in a headless Chromium browser
Run EOSdash in a headless Chromium browser for testing. Every menu tab must
load with HTTP 200 and render content, in light and dark mode, without
JavaScript errors.

Additional changes
Enable the browser tests by --browser-test (marker browser), skip them otherwise
Add the CI job browser-test that installs Chromium and runs them
Add the make target test-browser, run with --extra dev so playwright is installed
Add playwright to the dev dependencies
Document how to run the browser tests with --extra dev, incl. the browser system
libraries on Linux
Accept a child PID of the started server in the server startup checks, on Windows
only: there the venv python.exe runs the real interpreter as a child process
Share one Chromium per test class, so Playwright stops before other tests run
Request chromium before servers so a missing browser fails before EOS starts
Make the missing-browser hint platform neutral (Linux: add --with-deps)
Set PYTHONIOENCODING=utf-8 for the test server to avoid encoding errors on Windows

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 12:39:30 +01:00
2245976de4 docs(ai): move agent rules to ai/skills and add an AI development sandbox (#1498)
The sandbox provides an isolated Docker environment for AI-assisted development
(OpenCode + Claude Code + Qwen Code) against the local AkkudoktorEOS repository.

The sandbox does not protect the repository from harmful changes by the agent.
It limits what a misled agent can reach on the machine, but the agent can still
write any change into the repository.

Primary security defence is to check every change before it is run on the host.
Same holds for opening a pull request or updating one.

Additional changes

- Reduce AGENTS.md to the project summary, baseline rules, completion checklist,
  and an index of the skills.
- Add skills for the Python environment and REST API error responses.
- Add the development guide page docs/develop/ai.md: the AI coding
  workflow, how agents get the project rules from AGENTS.md and ai/skills,
  and how to use the sandbox (start, agent logins, project commands with a
  virtual environment outside the workspace, running EOS and EOSdash,
  GitHub access, persistent data, security model).
- Add a checklist for reviewing agent changes before pushing, starting with
  .git, which stays writable in the sandbox.
- Check out all text files with LF line endings (.gitattributes), also on
  Windows with core.autocrlf, so the sandbox scripts run in the container
  and git in the container agrees with git on the host. Batch files keep CRLF.
- Publish the ports of ai/compose.yaml on request (AI_SANDBOX_PORTS=1).
  docker compose run publishes them only with --service-ports. Off by
  default, so that several sandboxes can run in parallel.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 09:15:12 +01:00