Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 23, 2026

The FlexMeasures API returns JSON-encoded fields (attributes, flex_context, flex_model) as strings. Methods like get_assets(), get_asset(), get_sensor(), and get_sensors() previously returned these as-is, requiring manual parsing by callers.

Changes

New parameter parse_json_fields (default: None)

  • None (default): Returns JSON strings with deprecation warning
  • True: Parses JSON strings into Python dicts
  • False: Returns JSON strings without warning

Example usage:

# Old behavior (with deprecation warning)
assets = await client.get_assets()
attrs = json.loads(assets[0]["attributes"])  # Manual parsing required

# New behavior (opt-in)
assets = await client.get_assets(parse_json_fields=True)
attrs = assets[0]["attributes"]  # Already a dict

# Explicit old behavior (no warning)
assets = await client.get_assets(parse_json_fields=False)

Implementation details:

  • Added helper functions _parse_json_field(), _parse_asset_json_fields(), _parse_sensor_json_fields()
  • Silently handles malformed JSON by leaving fields as strings and logging at debug level
  • Updated internal get_asset() call in scheduler code to use parsed fields
  • Added test coverage for both parsing modes

Affected fields:

  • Assets: attributes, flex_context, flex_model
  • Sensors: attributes

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

Copilot AI and others added 6 commits January 23, 2026 14:52
Co-authored-by: Flix6x <30658763+Flix6x@users.noreply.github.com>
Co-authored-by: Flix6x <30658763+Flix6x@users.noreply.github.com>
Co-authored-by: Flix6x <30658763+Flix6x@users.noreply.github.com>
Co-authored-by: Flix6x <30658763+Flix6x@users.noreply.github.com>
Co-authored-by: Flix6x <30658763+Flix6x@users.noreply.github.com>
Co-authored-by: Flix6x <30658763+Flix6x@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix loading JSON fields and update client behaviour Add backward-compatible JSON field parsing to asset and sensor methods Jan 23, 2026
Copilot AI requested a review from Flix6x January 23, 2026 15:03
@Flix6x Flix6x marked this pull request as ready for review January 23, 2026 15:05
Signed-off-by: F.N. Claessen <felix@seita.nl>
@Flix6x Flix6x merged commit 2bf9397 into fix/load-json-fields Jan 23, 2026
8 checks passed
@Flix6x Flix6x deleted the copilot/sub-pr-164 branch January 23, 2026 15:11
Flix6x added a commit that referenced this pull request Jan 23, 2026
* fix: load JSON fields

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

* Add backward-compatible JSON field parsing to asset and sensor methods (#165)

* Initial plan

* Add parse_json_fields parameter to asset and sensor methods

Co-authored-by: Flix6x <30658763+Flix6x@users.noreply.github.com>

* Address code review feedback: add logging and use helper function

Co-authored-by: Flix6x <30658763+Flix6x@users.noreply.github.com>

* Improve code: use lazy logging and consistent parsing logic

Co-authored-by: Flix6x <30658763+Flix6x@users.noreply.github.com>

* Fix edge case handling and improve test formatting

Co-authored-by: Flix6x <30658763+Flix6x@users.noreply.github.com>

* Add proper error handling for JSON parsing in custom scheduler

Co-authored-by: Flix6x <30658763+Flix6x@users.noreply.github.com>

* Improve comment clarity for defensive programming

Co-authored-by: Flix6x <30658763+Flix6x@users.noreply.github.com>

* style: flake8

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

---------

Signed-off-by: F.N. Claessen <felix@seita.nl>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Flix6x <30658763+Flix6x@users.noreply.github.com>
Co-authored-by: F.N. Claessen <felix@seita.nl>

---------

Signed-off-by: F.N. Claessen <felix@seita.nl>
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants