Skip to content

v0.1.47

Choose a tag to compare

@mrebbert mrebbert released this 04 Sep 05:55
· 86 commits to main since this release
53c7984

Bugfix: market-prices timestamps auto-align to resolution boundary

The v4 endpoint `GET /api/v4/systems/{id}/charts/market-prices` started rejecting non-aligned `from`/`to` query params with HTTP 422 "Validation failed" (error_code 100006). For `resolution=1h`, both timestamps must land on a whole hour; for `resolution=15m`, on a 15-minute slot. Timestamp format itself is unchanged (`%Y-%m-%dT%H:%M:%SZ` and `.000Z` both still accepted equally).

Symptoms hitting anyone querying `get_prices()`:

  • `1k5 prices` in the CLI failed with a 422 traceback (end was `23:59:59`).
  • Any direct SDK caller (Home Assistant integration, custom scripts) with a natural range like today 00:00 – today 23:59:59 hit the same 422.

Fix

Inside `System.get_prices()`, a new module-level helper `_align_price_range(start, end, resolution)` snaps `start` down and `end` up to the resolution grid before the request. Callers can keep passing natural human ranges — the SDK guarantees alignment. Unknown resolutions pass through unchanged so the API surfaces its own error rather than the SDK masking one.

Verified live

```
get_prices(today 00:00, today 23:59:59, "1h")
→ 25 hourly slots, no 422
```

Regression protection

Five new tests:

  • `TestGetPrices::test_snaps_unaligned_end_up_to_next_1h_boundary`
  • `TestGetPrices::test_snaps_unaligned_start_down_and_end_up`
  • `TestGetPrices::test_snaps_15m_resolution_to_quarter_hour`
  • `TestGetPrices::test_already_aligned_timestamps_pass_through_unchanged`
  • `TestCmdPrices::test_end_is_hour_aligned_next_midnight`

343 tests pass, ruff clean.

Unchanged

  • Public API surface (`get_prices` signature, `MarketPrices` model fields)
  • CLI usage (`1k5 prices [--resolution 1h|15m]`)
  • All other endpoints

Install

```
pip install onekommafive==0.1.47
```