Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforce correct asset units #108

Merged
merged 5 commits into from May 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion documentation/changelog.rst
Expand Up @@ -3,6 +3,14 @@ FlexMeasures Changelog
**********************


v0.5.0 | May XX, 2021
===========================

Infrastructure / Support
----------------------
* Make assets use MW as their default unit and enforce that in CLI, as well (API already did) [see `PR #108 <http://www.github.com/SeitaBV/flexmeasures/pull/108>`_]


v0.4.0 | April 29, 2021
===========================

Expand All @@ -13,7 +21,6 @@ New features

.. note:: Read more on these features on `the FlexMeasures blog <https://flexmeasures.io/v040-plugin-support/>`__.


Bugfixes
-----------
* Asset edit form displayed wrong error message. Also enabled the asset edit form to display the invalid user input back to the user [see `PR #93 <http://www.github.com/SeitaBV/flexmeasures/pull/93>`_]
Expand Down
2 changes: 1 addition & 1 deletion flexmeasures/api/v2_0/tests/utils.py
Expand Up @@ -18,7 +18,7 @@
def get_asset_post_data() -> dict:
post_data = {
"name": "Test battery 2",
"unit": "kW",
"unit": "MW",
"capacity_in_mw": 3,
"event_resolution": timedelta(minutes=10).seconds / 60,
"latitude": 30.1,
Expand Down
5 changes: 4 additions & 1 deletion flexmeasures/data/models/assets.py
Expand Up @@ -113,9 +113,12 @@ def __init__(self, **kwargs):
else:
# The UI may initialize Asset objects from API form data with a known id
sensor_id = kwargs["id"]

if "unit" not in kwargs:
kwargs["unit"] = "MW" # current default
super(Asset, self).__init__(**kwargs)
self.id = sensor_id
if self.unit != "MW":
raise Exception("FlexMeasures only supports MW as unit for now.")
self.name = self.name.replace(" (MW)", "")
if "display_name" not in kwargs:
self.display_name = humanize(self.name)
Expand Down
14 changes: 12 additions & 2 deletions flexmeasures/data/scripts/cli_tasks/data_add.py
Expand Up @@ -108,8 +108,18 @@ def add_sensor(**args):
@with_appcontext
@click.option("--name", required=True)
@click.option("--asset-type-name", required=True)
@click.option("--unit", required=True, help="e.g. MW, kW/h", default="MW")
@click.option("--capacity-in-MW", required=True, type=float)
@click.option(
"--unit",
help="unit of rate, just MW (default) for now",
type=click.Choice(["MW"]),
default="MW",
) # TODO: enable others
@click.option(
"--capacity-in-MW",
required=True,
type=float,
help="Maximum rate of this asset in MW",
)
@click.option(
"--event-resolution",
required=True,
Expand Down