Skip to content

Feat/integrate reporting api hems - #224

Draft
BelhsanHmida wants to merge 12 commits into
mainfrom
feat/integrate-reporting-api-hems
Draft

Feat/integrate reporting api hems#224
BelhsanHmida wants to merge 12 commits into
mainfrom
feat/integrate-reporting-api-hems

Conversation

@BelhsanHmida

Copy link
Copy Markdown
Contributor

Description

Replaces the HEMS example's flexmeasures add report subprocess calls with the report-job API, and adds the client methods that make that possible.

Closes #223.

  • add trigger_report() for POST /assets/<id>/reports/trigger, returning the queued job UUID
  • add get_job_status() / wait_for_job() for polling GET /jobs/<uuid> with bounded backoff, plus trigger_and_await_report() chaining both
  • add JobFailedError and JobTimeoutError
  • rewire the HEMS example to trigger reports over the API, scoping each report to the asset owning its output sensors
  • drop the CLI probe, the temporary parameter files, and the Docker bind-mount workaround
  • document the reporting worker queue and the minimum server version

Background jobs polled via the generic jobs API can end in a failed
terminal state or never reach one at all. Give both cases a dedicated
exception so callers can tell them apart from transport errors.

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Add get_job_status() for a single lookup of GET /api/v3_0/jobs/<uuid>,
and wait_for_job() to poll one until it reaches a terminal state, with
exponential backoff capped at max_polling_interval and a total timeout
budget.

Failed jobs raise JobFailedError carrying the server's message and
traceback, so callers get something actionable instead of a bare status.

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Add trigger_report(), posting to POST /assets/<id>/reports/trigger and
returning the queued job UUID, plus trigger_and_await_report() which
chains it with wait_for_job().

The endpoint lands in FlexMeasures v1.1.0, so a 404 from an older server
is reported as a version problem pointing at the CLI fallback.

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Assert the exact request bodies sent to the trigger endpoint, that
polling walks through QUEUED/DEFERRED/STARTED before returning a
finished job, and that failed, stopped, canceled and never-finishing
jobs each raise the right error.

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Replace run_report_cmd() and its subprocess call with an async
run_report() that triggers the report on the asset owning its output
sensors and waits for the job.

Parameters are now built in memory rather than written to
configs/*_reporter_param.json, and configs are read on the client side
and posted along with the request. Neither the CLI nor a bind-mount of
configs/ into the server is needed anymore, so cli_command_prefix() and
the FLEXMEASURES_CLI_CMD/FLEXMEASURES_CLI_CONFIG_DIR handling are gone.

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Drop the 'which flexmeasures' probe that silently skipped report
generation, and call run_report() per site instead of writing parameter
files and shelling out.

Also carry the per-site outcome into the return value, which previously
reflected the last site only.

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Sensors nested in an asset listing are dumped with only id and name, so
deriving the asset from an output sensor fails for anything read that
way. Add an asset_id override to run_report() and a clear error when
derivation is not possible.

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Make run_community_aggregate async and route both the per-site and the
community aggregate through run_report(). Awaiting each job in turn
keeps the ordering the community report depends on, and the community
report is now skipped outright when a site aggregate did not finish,
rather than silently aggregating stale data.

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Note the v1.1.0 server requirement, add reporting to the worker queues,
and replace the CLI workaround section, which no longer applies now that
report configuration is posted rather than read from disk by the server.

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Reporter parameters are built in memory now, so nothing writes
configs/*_reporter_param.json anymore.

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Mirror the forecasting page: endpoints and server requirement, which
asset a report is triggered against, the polling knobs, and what
JobFailedError and JobTimeoutError each mean.

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Assert that reports are scoped to the asset owning their output sensors,
that mixed-asset and asset-less outputs are refused, that parameters and
configs come out as the reporters expect, and that no HEMS module shells
out anymore.

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
@BelhsanHmida BelhsanHmida self-assigned this Aug 18, 2026
@coveralls

Copy link
Copy Markdown

Coverage Report for CI Build 32161932884

Coverage increased (+0.03%) to 96.612%

Details

  • Coverage increased (+0.03%) from the base build.
  • Patch coverage: 2 uncovered changes across 1 file (64 of 66 lines covered, 96.97%).
  • No coverage regressions found.

Uncovered Changes

File Changed Covered %
src/flexmeasures_client/client.py 58 56 96.55%
Total (2 files) 66 64 96.97%

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 797
Covered Lines: 770
Line Coverage: 96.61%
Coverage Strength: 9.66 hits per line

💛 - Coveralls

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.

Replace HEMS report CLI subprocesses with the report-job API

2 participants