Skip to content

create_storage_flex_context sends prices as consumption-price/production-price, so SoC minima can be relaxed - #298

Merged
Flix6x merged 3 commits into
mainfrom
fix/flex-context-price-fields
Dec 1, 2026
Merged

Flix6x merged 3 commits into
mainfrom
fix/flex-context-price-fields

Conversation

@Flix6x

@Flix6x Flix6x commented Nov 24, 2026

Copy link
Copy Markdown
Member

Problem

create_storage_flex_context wrote the deprecated consumption-price-sensor and production-price-sensor fields.
FlexMeasures relaxes SoC constraints by default (with a default breach price), but it skips that while the deprecated fields are used,
and it rejects relax-soc-constraints or an explicit soc-minima-breach-price next to them (checked on v1.1.2), also when these are set on the asset's own flex-context.
So a schedule built with this helper kept hard SoC minima, and failed as infeasible whenever they could not be met.

The FlexMeasures Home Assistant integration used this helper, and fixed this on its side in FlexMeasures/flexmeasures-ha-integration#34 (v0.4.3).

Fix

  • Send the prices as consumption-price: {"sensor": <id>} and production-price: {"sensor": <id>}.
    The function's parameters stay the same.
  • These fields need FlexMeasures v0.23.0 or up; the changelog says so.
  • Add a docstring to the helper.

Verification

  • Full suite: 873 passed.
  • With client.py reverted to main, the updated tests fail (2 failed).
  • pre-commit passes.

🤖 Generated with Claude Code

…oduction-price

It wrote the deprecated `consumption-price-sensor` and `production-price-sensor` fields.
FlexMeasures does not fill in its default SoC breach prices while those fields are used,
and it rejects relaxation settings next to them,
so a schedule built with this helper failed as infeasible whenever its SoC minima could not be met.

The prices now go out as `consumption-price: {"sensor": <id>}` and `production-price: {"sensor": <id>}`,
which FlexMeasures supports from v0.23.0 on.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: F.N. Claessen <claessen@seita.nl>
@Flix6x Flix6x added this to the 0.11.0 milestone Nov 24, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: F.N. Claessen <claessen@seita.nl>
@coveralls

coveralls commented Nov 24, 2026 •

Copy link
Copy Markdown

Coverage Report for CI Build 46740059869

Coverage remained the same at 96.21%

Details

  • Coverage remained the same as the base build.
  • Patch coverage: 2 of 2 lines across 1 file are fully covered (100%).
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 3430
Covered Lines: 3300
Line Coverage: 96.21%
Coverage Strength: 4.42 hits per line

💛 - Coveralls

@Flix6x Flix6x left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A self-review of #298, at its head 3a03be9, checked against FlexMeasures v1.1.3.

The fix holds. Scheduling a test battery with the flex-context this helper returns:

  • With a soc-minima the battery can't reach, the old fields made the schedule fail as infeasible. With the new fields it is scheduled, and the shortfall is priced at the default breach price.
  • Adding relax-soc-constraints: true was refused next to the old fields ("Please switch to using consumption-price…"); it is accepted now.
  • relax-soc-constraints: false still keeps the minima hard (infeasible), as it should.
  • One more thing it fixes: if the asset's own flex-context has a consumption-price, the old fields made every schedule fail ("Must pass either consumption-price or consumption-price-sensor."), even with reachable minima. With the new fields the request's price simply takes precedence.

The two changed tests fail with main's client.py and pass with this PR; the full suite passes (873), and so does CI. The new fields arrived in FlexMeasures v0.23.0, as the changelog says, and several client methods already need v0.28.0, so nobody loses support. Nothing else in the client sends the deprecated fields.

We'll add the asset flex-context case to the changelog entry, on this branch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: F.N. Claessen <claessen@seita.nl>
@Flix6x
Flix6x merged commit 535bada into main Dec 1, 2026
19 checks passed
@Flix6x
Flix6x deleted the fix/flex-context-price-fields branch December 1, 2026 20:41
@Flix6x

Flix6x commented Dec 1, 2026

Copy link
Copy Markdown
Member Author

Follow-ups from the review:

  • push-fix, changelog clause for the asset flex-context price failure: pushed in fe894a8 (changelog only, so it has no test of its own).
  • merge: all checks passed on fe894a8, so I squash-merged this PR as 535bada. There was no approving review because this is the author's own PR, and the branch doesn't require one.

Flix6x added a commit that referenced this pull request Dec 5, 2026
…hangelog entries as additions

Three of the four Fixed entries fixed things this PR itself added, never released, and refresh_forecasts is new;
they join Added, split into five bullets.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: F.N. Claessen <claessen@seita.nl>
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