Skip to content

Commit

Permalink
Merge b0a4a8f into 97e9cbf
Browse files Browse the repository at this point in the history
  • Loading branch information
Flix6x committed Jun 15, 2023
2 parents 97e9cbf + b0a4a8f commit ec9c150
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 5 deletions.
3 changes: 2 additions & 1 deletion documentation/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
FlexMeasures Changelog
**********************

v0.14.0 | June XX, 2023
v0.14.0 | June 15, 2023
============================

New features
Expand All @@ -13,6 +13,7 @@ New features
* Allow setting multiple :abbr:`SoC (state of charge)` maxima and minima constraints for the `StorageScheduler`, using the new ``soc-minima`` and ``soc-maxima`` fields when calling `/sensors/<id>/schedules/trigger` (POST) through the API (within the ``flex-model`` field) [see `PR #680 <https://www.github.com/FlexMeasures/flexmeasures/pull/680>`_]
* New CLI command ``flexmeasures add report`` to calculate a custom report from sensor data and save the results to the database, with the option to export them to a CSV or Excel file [see `PR #659 <https://www.github.com/FlexMeasures/flexmeasures/pull/659>`_]
* New CLI commands ``flexmeasures show reporters`` and ``flexmeasures show schedulers`` to list available reporters and schedulers, respectively, including any defined in registered plugins [see `PR #686 <https://www.github.com/FlexMeasures/flexmeasures/pull/686>`_ and `PR #708 <https://github.com/FlexMeasures/flexmeasures/pull/708>`_]
* Allow creating public assets through the CLI, which are available to all users [see `PR #727 <https://github.com/FlexMeasures/flexmeasures/pull/727>`_]

Bugfixes
-----------
Expand Down
9 changes: 9 additions & 0 deletions documentation/cli/change_log.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@
FlexMeasures CLI Changelog
**********************

since v0.14.0 | June 15, 2023
=================================

* Allow setting a storage efficiency using the new ``--storage-efficiency`` option to the ``flexmeasures add schedule for-storage`` CLI command.
* Add CLI command ``flexmeasures add report`` to calculate a custom report from sensor data and save the results to the database, with the option to export them to a CSV or Excel file.
* Add CLI command ``flexmeasures show reporters`` to list available reporters, including any defined in registered plugins.
* Add CLI command ``flexmeasures show schedulers`` to list available schedulers, including any defined in registered plugins.
* Make ``--account-id`` optional in ``flexmeasures add asset`` to support creating public assets, which are available to all users.

since v0.13.0 | May 1, 2023
=================================

Expand Down
21 changes: 18 additions & 3 deletions flexmeasures/cli/data_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,12 @@ def new_account(name: str, roles: str):
@with_appcontext
@click.option("--username", required=True)
@click.option("--email", required=True)
@click.option("--account-id", type=int, required=True)
@click.option(
"--account-id",
type=int,
required=True,
help="Add user to this account. Follow up with the account's ID.",
)
@click.option("--roles", help="e.g. anonymous,Prosumer,CPO")
@click.option(
"--timezone",
Expand Down Expand Up @@ -286,7 +291,12 @@ def add_asset_type(**args):
type=LongitudeField(),
help="Longitude of the asset's location",
)
@click.option("--account-id", type=int, required=True)
@click.option(
"--account-id",
type=int,
required=False,
help="Add asset to this account. Follow up with the account's ID. If not set, the asset will become public (which makes it accessible to all users).",
)
@click.option(
"--asset-type-id",
"generic_asset_type_id",
Expand All @@ -298,6 +308,11 @@ def add_asset(**args):
"""Add an asset."""
check_errors(GenericAssetSchema().validate(args))
generic_asset = GenericAsset(**args)
if generic_asset.account_id is None:
click.secho(
"Creating a PUBLIC asset, as the account_id is not given ...",
**MsgStyle.WARN,
)
db.session.add(generic_asset)
db.session.commit()
click.secho(
Expand All @@ -319,7 +334,7 @@ def add_initial_structure():
"--name",
required=True,
type=str,
help="Name of the source (usually an organisation)",
help="Name of the source (usually an organization)",
)
@click.option(
"--model",
Expand Down
8 changes: 7 additions & 1 deletion flexmeasures/data/schemas/generic_assets.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import json

from marshmallow import validates, validates_schema, ValidationError, fields
Expand Down Expand Up @@ -66,7 +68,11 @@ def validate_generic_asset_type(self, generic_asset_type_id: int):
)

@validates("account_id")
def validate_account(self, account_id: int):
def validate_account(self, account_id: int | None):
if account_id is None and (
running_as_cli() or user_has_admin_access(current_user, "update")
):
return
account = Account.query.get(account_id)
if not account:
raise ValidationError(f"Account with Id {account_id} doesn't exist.")
Expand Down

0 comments on commit ec9c150

Please sign in to comment.