Skip to content

Add unit query parameter to GET schedule endpoint for unit conversion#1993

Open
Copilot wants to merge 10 commits intomainfrom
copilot/add-schedule-unit-parameter
Open

Add unit query parameter to GET schedule endpoint for unit conversion#1993
Copilot wants to merge 10 commits intomainfrom
copilot/add-schedule-unit-parameter

Conversation

Copy link
Contributor

Copilot AI commented Feb 27, 2026

The GET schedule endpoint always returned values in the sensor's native unit, making it difficult for clients that operate in different (but compatible) units.

Changes

  • flexmeasures/api/v3_0/sensors.py

    • Accept optional unit query param via UnitField in get_schedule
    • Convert schedule values from sensor unit to requested unit using convert_units; return ValidationError (422) if units are incompatible
    • Updated OpenAPI spec to document the new unit parameter
  • flexmeasures/api/v3_0/tests/test_sensor_schedules.py

    • Added test_get_schedule_with_unit covering: default (sensor unit), compatible unit conversion, and incompatible unit rejection
  • Some schema refactoring by @Flix6x to modernize field validation.

Example

GET /api/v3_0/sensors/5/schedules/<uuid>?unit=kW

For a sensor with unit MW, this returns values scaled by 1000 and "unit": "kW" in the response. Requesting an incompatible unit like °C returns a 422.

Original prompt

This section details on the original issue you should resolve

<issue_title>Get schedule in any compatible unit</issue_title>
<issue_description>The endpoint for fetching a schedule for a given sensor, should accept a "unit" field, which should use our unit_utils.py to convert the schedule from the sensor unit to the desired unit.

The PR should include test coverage for the new feature. I imagine updating an existing API test suffices.

This feature will help support FlexMeasures/flexmeasures-client#67</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@read-the-docs-community
Copy link

read-the-docs-community bot commented Feb 27, 2026

Documentation build overview

📚 flexmeasures | 🛠️ Build #31603630 | 📁 Comparing c362a43 against latest (7f2c631)


🔍 Preview build

Show files changed (9 files in total): 📝 9 modified | ➕ 0 added | ➖ 0 deleted
File Status
changelog.html 📝 modified
genindex.html 📝 modified
_autosummary/flexmeasures.api.common.schemas.sensors.html 📝 modified
_autosummary/flexmeasures.api.common.utils.validators.html 📝 modified
_autosummary/flexmeasures.api.v3_0.sensors.html 📝 modified
_autosummary/flexmeasures.data.schemas.scheduling.html 📝 modified
_autosummary/flexmeasures.data.schemas.units.html 📝 modified
api/change_log.html 📝 modified
api/v3_0.html 📝 modified

Co-authored-by: Flix6x <30658763+Flix6x@users.noreply.github.com>
Copilot AI changed the title [WIP] Add unit parameter to fetch schedule endpoint Add unit query parameter to GET schedule endpoint for unit conversion Feb 27, 2026
Signed-off-by: F.N. Claessen <claessen@seita.nl>
Signed-off-by: F.N. Claessen <claessen@seita.nl>
@Flix6x Flix6x marked this pull request as ready for review February 28, 2026 10:21
@Flix6x Flix6x added this to the 0.31.0 milestone Feb 28, 2026
Signed-off-by: F.N. Claessen <claessen@seita.nl>
Signed-off-by: F.N. Claessen <claessen@seita.nl>
Signed-off-by: F.N. Claessen <claessen@seita.nl>
Signed-off-by: F.N. Claessen <claessen@seita.nl>
@Flix6x Flix6x modified the milestones: 0.31.0, 0.32 Feb 28, 2026
@Flix6x Flix6x added API Scheduling Units Deals with unit conversion labels Feb 28, 2026
@Flix6x Flix6x requested a review from nhoening February 28, 2026 21:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

API Scheduling Units Deals with unit conversion

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Get schedule in any compatible unit

2 participants