Skip to content

Commit

Permalink
Issue 294 post udi event bug rolling back due to integrity error (#300)
Browse files Browse the repository at this point in the history
Fix recording time of schedules triggered by UDI events.


* Accept prior in postUdiEvent, with server time as default

Signed-off-by: F.N. Claessen <felix@seita.nl>

* API changelog entry

Signed-off-by: F.N. Claessen <felix@seita.nl>

* Main changelog entry

Signed-off-by: F.N. Claessen <felix@seita.nl>

* Correct PR number

Signed-off-by: F.N. Claessen <felix@seita.nl>

* Add type annotation and inline comment

Signed-off-by: F.N. Claessen <felix@seita.nl>
  • Loading branch information
Flix6x committed Jan 5, 2022
1 parent bc189c7 commit bb5817f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
10 changes: 10 additions & 0 deletions documentation/api/change_log.rst
Expand Up @@ -39,6 +39,16 @@ v2.0-0 | 2020-11-14
- REST endpoints for managing assets: `/assets/` (GET, POST) and `/asset/<id>` (GET, PATCH, DELETE).


v1.3-11 | 2022-01-05
""""""""""""""""""""

*Affects all versions since v1.3*.

- Changed the *postUdiEvent* endpoint:

- The recording time of new schedules triggered by calling the endpoint is now the time at which the endpoint was called, rather than the datetime of the sent state of charge (SOC).
- Introduced the "prior" field for the purpose of communicating an alternative recording time, thereby keeping support for simulations.

v1.3-10 | 2021-11-08
""""""""""""""""""""

Expand Down
1 change: 1 addition & 0 deletions documentation/changelog.rst
Expand Up @@ -11,6 +11,7 @@ New features

Bugfixes
-----------
* Fix recording time of schedules triggered by UDI events [see `PR #300 <http://www.github.com/FlexMeasures/flexmeasures/pull/300>`_]

Infrastructure / Support
----------------------
Expand Down
8 changes: 5 additions & 3 deletions flexmeasures/api/v1_3/implementations.py
@@ -1,5 +1,5 @@
# flake8: noqa: C901
from datetime import timedelta
from datetime import datetime, timedelta

import inflect
import isodate
Expand Down Expand Up @@ -35,6 +35,7 @@
type_accepted,
assets_required,
optional_duration_accepted,
optional_prior_accepted,
units_accepted,
parse_isodate_str,
)
Expand Down Expand Up @@ -215,8 +216,9 @@ def get_device_message_response(generic_asset_name_groups, duration):

@type_accepted("PostUdiEventRequest")
@units_accepted("State of charge", "kWh", "MWh")
@optional_prior_accepted()
@as_json
def post_udi_event_response(unit):
def post_udi_event_response(unit: str, prior: datetime):

if not has_assets():
current_app.logger.info("User doesn't seem to have any assets.")
Expand Down Expand Up @@ -360,7 +362,7 @@ def post_udi_event_response(unit):
start_of_schedule,
end_of_schedule,
resolution=resolution,
belief_time=datetime,
belief_time=prior, # server time if no prior time was sent
soc_at_start=value,
soc_targets=soc_targets,
udi_event_ea=form.get("event"),
Expand Down

0 comments on commit bb5817f

Please sign in to comment.