Skip to content

Commit

Permalink
Enforce correct asset units (#108)
Browse files Browse the repository at this point in the history
* Create draft PR for #107

* enforce MW as asset unit for now, as well in CLI

* make MW the default on Asset, fix test data

* add change log

* Typo

Co-authored-by: nhoening <nhoening@users.noreply.github.com>
Co-authored-by: Nicolas Höning <nicolas@seita.nl>
Co-authored-by: Felix Claessen <30658763+Flix6x@users.noreply.github.com>
  • Loading branch information
4 people committed May 1, 2021
1 parent 6dbc2c8 commit 6505852
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
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

0 comments on commit 6505852

Please sign in to comment.