Skip to content

docs: add a complete plugin automation example - #2705

Merged
nhoening merged 7 commits into
mainfrom
docs/plugin-automation-example-2610
Nov 10, 2026
Merged

nhoening merged 7 commits into
mainfrom
docs/plugin-automation-example-2610

Conversation

@BelhsanHmida

Copy link
Copy Markdown
Contributor

Description

  • Show a complete plugin automation example in the plugin docs, by including the test plugin mock_ingestion in full, so the example is tested and cannot drift from the code.
  • Walk through it part by part: the schemas, the DataGenerator, input_sensors/output_sensors, _compute, and the __automation_types__ registration.
  • Explain what __data_generator_base__ and __version__ mean for stored automations, including that raising __version__ makes existing automations fail until they are recreated.
  • State that the web app, the dispatcher and the worker each need the plugin in FLEXMEASURES_PLUGINS, and that a plugin needs a Blueprint to be registered.
  • Add example config and parameter YAML files, and the commands to create an automation inactive and try one run with flexmeasures jobs run-automation.
  • Correct the docs on unknown=RAISE: FlexMeasures already refuses unknown fields when it loads the config and parameters, so plugin schemas don't need to set it.

Look & Feel

New sub-sections under Plugin Customization → Adding your own automation type:

  • A complete example
  • Data source type and version
  • Enabling the plugin
  • Creating and trying out an automation
  • Rules for automation types (the existing rules, moved here)

How to test

Build the docs and open plugin/customisation.html. The example code should render in full.

Further improvements

  • Link the plugin template once it can scaffold an automation type (flexmeasures-plugin-template#29).

Related Items

Closes #2610


Sign-off

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on code under GPL or other license that is incompatible with FlexMeasures

Show the test plugin in full as the example of an automation type,
and explain what __data_generator_base__ and __version__ mean for stored automations,
which processes need the plugin enabled,
and how to create and try out an automation with config and parameter files.

Closes #2610

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
@BelhsanHmida BelhsanHmida self-assigned this Oct 12, 2026
@BelhsanHmida BelhsanHmida added documentation Improvements or additions to documentation Plugin support Automations labels Oct 12, 2026
Walk through the example the way the other customisation sections do,
keeping only what the code does not already show,
and point to the automations docs for the add automation command instead of repeating it.

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>

@joyshmitz joyshmitz left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for this. Including the tested mock_ingestion plugin with literalinclude keeps the example in step with code the test suite runs. I applied both commits onto current main (they apply cleanly) and checked the walkthrough against the code there.

Checked against main

  • The included module is the plugin the test suite uses: test_plugin_loader_discovers_declared_automation loads it through FLEXMEASURES_PLUGINS, and the run tests register its handler and execute it (flexmeasures/data/tests/test_plugin_automations_fresh_db.py, plus the API, CLI and UI test modules). The PR changes only its docstring.
  • Unknown fields: load_automation_payload loads config and parameters with schema.load(payload, unknown=RAISE) (flexmeasures/data/automations.py:29), and resolve_plugin_generator does the same for a run's parameters (line 367). This overrides a schema's own Meta.unknown, so dropping the advice to set unknown=RAISE is correct.
  • Data source and version: get_data_source_info() sets the source type from __data_generator_base__ (flexmeasures/data/models/data_sources.py:260), create() stores the version from the generator's __version__ (flexmeasures/data/automations.py:138), and resolve_plugin_generator refuses to run when it differs from the installed version, telling the user to recreate the automation (lines 354-357).
  • Undeclared outputs: before saving, the worker raises GeneratorWritesUncheckedSensor for any result on a sensor outside the declared outputs (check_generator_results in flexmeasures/data/services/generator_results.py).
  • Blueprint: when a plugin defines none, register_plugins() logs "No blueprints found for plugin ..." and skips the plugin, so its __automation_types__ are never registered (flexmeasures/utils/plugin_utils.py:152-156).
  • The YAML examples use the schemas' field names (sensor, value).
  • The strict docs build (sphinx-build -W --keep-going -n) renders the whole module into plugin/customisation.html and reports no warning on the lines this PR adds. The one warning in that file, an unresolved :class:DataGenerator on line 418, predates the PR; since the PR touches this section, :class:~flexmeasures.data.models.data_sources.DataGenerator`` resolves it.

Suggestions

  1. The linked CLI example does not match the plugin. The new text sends readers to :ref:automations for flexmeasures add automation, but the plugin example there still uses --type site-ingestion (documentation/features/automations.rst:180), the identifier of the SiteIngestor example this PR removes; the example plugin registers mock-ingestion. That command also creates the automation active (the default, flexmeasures/cli/data_add.py:1811 and 1989), while the text asks readers to verify one run "before activating its recurrence". Showing the full command next to the YAML files, with --type mock-ingestion and --inactive, makes the walkthrough runnable as written. It could also say that sensor has to belong to the automation's asset or one of its descendants, which every run checks (flexmeasures/data/automations.py:334-342).
  2. Which __version__. The example module defines __version__ twice: on the module (line 14) and on MockIngestionGenerator (line 29). The automation's version comes from the generator class (flexmeasures/data/automations.py:138); the module's is what register_plugins() records as the plugin version (flexmeasures/utils/plugin_utils.py:142). Saying "the generator class's __version__" tells readers which one to raise.
  3. Queue names. A handler's queue has to be one of forecasting, scheduling, ingestion or reporting (flexmeasures/utils/job_utils.py:15); any other name fails registration with "Unknown automation queue" (flexmeasures/data/automations.py:282-283). The example uses ingestion, so it works, but one sentence keeps plugin authors from inventing their own queue.
  4. Changelog. The PR template asks for a changelog item, and documentation PRs such as #2597 and #2721 have one. The existing line on plugin automation types in documentation/changelog.rst (line 267, crediting #2553 and #2644) could credit #2705 as well.
  5. Nested schemas (nit). "Unknown fields in the configuration or parameters are always refused" holds for top-level fields. A fields.Nested schema keeps its own Meta.unknown: with EXCLUDE there, an extra nested key is dropped silently despite the outer unknown=RAISE. "Unknown top-level fields are always refused" is exact.
  6. Optional. The removed closing sentence, that permissions and output scope are checked again when a run is queued and computed, still holds on main: queueing checks the run user's access (flexmeasures/data/services/automations.py:2544-2545) and the output scope (flexmeasures/data/automations.py:211), and the worker repeats both before computing (lines 426-427). It could stay.

Note for maintainers: #2779 (open) makes an automation's config editable and moves the automation to the data source the new config resolves to. Whichever of the two merges second should check whether "existing automations need to be recreated" still holds.

Context:
- The linked automations page uses another type and creates the automation active,
  so the walkthrough could not be followed as written.

Change:
- Show the full command with the example's type and --inactive.
- State that the sensor must belong to the automation's asset or one of its descendants.

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Context:
- The example defines __version__ twice, and only the generator class's version is stored with an automation.
- Registration refuses queues outside the known set.
- A nested schema keeps its own handling of unknown fields.

Change:
- Name the generator class's __version__.
- List the allowed queues.
- Limit the unknown fields note to top-level fields.

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Context:
- The strict docs build warns that :class:`DataGenerator` has no target.

Change:
- Use the full path, which links to the class's API page.

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
@joyshmitz

Copy link
Copy Markdown
Collaborator

Thanks, the three new commits cover the points from my review. I checked them against current main (c943861): the queue list matches KNOWN_JOB_QUEUES (flexmeasures/utils/job_utils.py:15), every option in the new command exists on flexmeasures add automation (flexmeasures/cli/data_add.py:1770-1846), and the sentence on the sensor's asset matches validate_automation_output_scope (flexmeasures/data/automations.py:335-341).

The changelog item is the one point left. With v1.1.0 released, it would go into the next release's section, which main doesn't have yet.

@nhoening

nhoening commented Nov 6, 2026

Copy link
Copy Markdown
Member

@nhoening nhoening added this to the 1.2.0 milestone Nov 10, 2026
Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
@nhoening
nhoening merged commit 027a2c9 into main Nov 10, 2026
11 checks passed
@nhoening
nhoening deleted the docs/plugin-automation-example-2610 branch November 10, 2026 13:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Automations documentation Improvements or additions to documentation Plugin support

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a complete plugin automation example to the documentation

3 participants