2 Commits
Author SHA1 Message Date
tliu93 f4cea3874b test(energy-cost): pin local_now in future-window summarize test
frontend / frontend (push) Failing after 6m38s
pytest / test (push) Successful in 20m16s
docker-image / build-and-push (push) Successful in 13m32s
test_future_window_counts_0_days relied on the real wall-clock date and assumed
7/1→8/1 2026 was entirely in the future; once that range started elapsing the
window counted fixed-fee days and the assertion failed. Pin local_now to
June 25 2026 (as the sibling window tests already do) so the case stays
deterministic.
2026-07-17 18:49:26 +02:00
tliu93 134f0abb5f fix(tibber): fetch newest price slots via priceInfoRange last:192
priceInfoRange is a Relay-style cursor connection over the subscription's
entire price history. With no cursor, first:96 returned the OLDEST 96 slots,
anchored at the subscription start date — a fixed window that never advanced.
For a contract added mid-period this meant refresh_prices kept re-upserting the
same day-one slots forever, so GET /api/energy/prices found nothing in the
today+tomorrow window and the UI showed "No Tibber price points available".

Use last:192 to return the newest 192 quarter-hourly slots (2 days), which ends
at the latest published slot and advances daily, fully covering the prices
endpoint's today+tomorrow window.
2026-07-17 18:49:26 +02:00
2 changed files with 23 additions and 10 deletions
+17 -9
View File
@@ -31,18 +31,24 @@ _TIBBER_API_URL = "https://api.tibber.com/v1-beta/gql"
_DEFAULT_TIMEOUT = 15.0
# GraphQL query to fetch a range of 15-minute price nodes.
# ``priceInfoRange(resolution: QUARTER_HOURLY, first: 96)`` fetches up to
# 96 quarter-hourly slots which covers today + tomorrow (2 × 24 × 4 = 192 max,
# but the Tibber API typically starts from the current slot and returns at
# most the remaining hours of today plus tomorrow, so 96 is a good cap for
# "today + tomorrow").
# ``priceInfoRange`` is a Relay-style cursor connection over the subscription's
# entire available price history. With no before/after cursor:
# * ``first: N`` returns the OLDEST N nodes (anchored at the subscription
# start date) — a fixed window that never advances, so it is WRONG for
# "current + upcoming" prices.
# * ``last: N`` returns the NEWEST N nodes (ending at the latest published
# slot: tomorrow 23:45 once day-ahead prices are out, else today 23:45).
# We want the newest slots, so we use ``last``. 192 = 2 days × 24 h × 4 slots,
# which fully covers the "today + tomorrow" window that GET /api/energy/prices
# queries (the earliest of the 192 newest slots reaches back past today 00:00
# UTC in either publish state).
_PRICE_RANGE_QUERY = """
{
viewer {
homes {
id
currentSubscription {
priceInfoRange(resolution: QUARTER_HOURLY, first: 96) {
priceInfoRange(resolution: QUARTER_HOURLY, last: 192) {
nodes {
startsAt
total
@@ -232,9 +238,11 @@ def fetch_price_range(
) -> list[PricePoint]:
"""Fetch a range of 15-minute price nodes from the Tibber API.
Sends the ``priceInfoRange(resolution: QUARTER_HOURLY, first: 96)`` query
and parses every returned node into a ``PricePoint``. The number of nodes
is not assumed — all returned nodes are parsed regardless of count.
Sends the ``priceInfoRange(resolution: QUARTER_HOURLY, last: 192)`` query
and parses every returned node into a ``PricePoint``. ``last`` (not
``first``) is used so the newest slots are returned; ``first`` would anchor
at the subscription start date and never advance. The number of nodes is
not assumed — all returned nodes are parsed regardless of count.
Parameters
----------
+6 -1
View File
@@ -1263,6 +1263,9 @@ class TestSummarizePrincipleC:
def test_future_window_counts_0_days(self, energy_db: Session) -> None:
"""A fully future window (all local dates > today) counts 0 days.
Pins ``local_now`` to June 25 2026 noon AMS so the 7/1→8/1 window is
genuinely in the future regardless of the actual wall-clock date
(mirrors the sibling window tests, which all pin ``local_now``).
Matches table row: 7/1→8/1 (all future) → 0 days.
"""
eff_utc = _ams_midnight(2026, 6, 1)
@@ -1270,7 +1273,9 @@ class TestSummarizePrincipleC:
start = _ams_midnight(2026, 7, 1)
end = _ams_midnight(2026, 8, 1)
result = self._run_summarize_ams(energy_db, start, end)
# Pin local_now to June 25 2026 noon AMS so 7/1→8/1 stays fully future.
pinned_now = datetime(2026, 6, 25, 12, 0, 0, tzinfo=_ams())
result = self._run_summarize_ams(energy_db, start, end, pinned_now=pinned_now)
assert result["fixed_costs"] == 0.0, (
f"All-future window must count 0 days; got fixed_costs={result['fixed_costs']}"