flexmeasures.utils.plugin_utils

Utils for registering FlexMeasures plugins

Functions

flexmeasures.utils.plugin_utils.check_config_settings(app, settings: dict[str, dict])

Make sure expected config settings exist.

For example:

settings = {
“MY_PLUGIN_URL”: {

“description”: “URL used by my plugin for x.”, “level”: “error”,

}, “MY_PLUGIN_TOKEN”: {

“description”: “Token used by my plugin for y.”, “level”: “warning”, “message”: “Without this token, my plugin will not do y.”, “parse_as”: str,

}, “MY_PLUGIN_COLOR”: {

“description”: “Color used to override the default plugin color.”, “level”: “info”,

},

}

flexmeasures.utils.plugin_utils.log_missing_config_setting(app, setting_name: str, setting_fields: dict)

Log a message for this missing config setting.

The logging level is taken from the ‘level’ key. If missing, we default to error. If present, we also log the ‘description’ and the ‘message_if_missing’ keys.

flexmeasures.utils.plugin_utils.log_wrong_type_for_config_setting(app, setting_name: str, setting_fields: dict, setting_type: type)

Log a message for this config setting that has the wrong type.

flexmeasures.utils.plugin_utils.register_plugins(app: Flask)

Register FlexMeasures plugins as Blueprints. This is configured by the config setting FLEXMEASURES_PLUGINS.

Assumptions: - a setting EITHER points to a plugin folder containing an __init__.py file

OR it is the name of an installed module, which can be imported.

  • each plugin defines at least one Blueprint object. These will be registered with the Flask app, so their functionality (e.g. routes) becomes available.

If you load a plugin via a file path, we’ll refer to the plugin with the name of your plugin folder (last part of the path).