mirror of
https://github.com/jpawlowski/hass.tibber_prices.git
synced 2026-03-29 21:03:40 +00:00
docs: fix attribute names in AGENTS.md examples
Updated attribute ordering documentation to use correct names: - "periods" → "pricePeriods" (matches code since refactoring) - "intervals" → "priceInfo" (flat list structure) Impact: Documentation now matches actual code structure.
This commit is contained in:
parent
6b78cd757f
commit
7e47ef5995
2 changed files with 54 additions and 36 deletions
|
|
@ -2369,8 +2369,8 @@ attributes = {
|
||||||
"interval_count": ...,
|
"interval_count": ...,
|
||||||
|
|
||||||
# 6. Meta information (technical details)
|
# 6. Meta information (technical details)
|
||||||
"periods": [...], # Nested structures last
|
"pricePeriods": [...], # Nested structures last
|
||||||
"intervals": [...],
|
"priceInfo": [...],
|
||||||
|
|
||||||
# 7. Extended descriptions (always last)
|
# 7. Extended descriptions (always last)
|
||||||
"description": "...", # Short description from custom_translations (always shown)
|
"description": "...", # Short description from custom_translations (always shown)
|
||||||
|
|
|
||||||
|
|
@ -299,69 +299,87 @@ def enrich_price_info_with_differences(
|
||||||
*,
|
*,
|
||||||
threshold_low: float | None = None,
|
threshold_low: float | None = None,
|
||||||
threshold_high: float | None = None,
|
threshold_high: float | None = None,
|
||||||
time: TibberPricesTimeService,
|
time: TibberPricesTimeService | None = None, # noqa: ARG001 # Used in production (via coordinator), kept for compatibility
|
||||||
) -> list[dict[str, Any]]:
|
) -> list[dict[str, Any]]:
|
||||||
"""
|
"""
|
||||||
Enrich price intervals with calculated 'difference' and 'rating_level' values.
|
Enrich price intervals with calculated 'difference' and 'rating_level' values.
|
||||||
|
|
||||||
Computes the trailing 24-hour average, difference percentage, and rating level
|
Computes the trailing 24-hour average, difference percentage, and rating level
|
||||||
for each interval in the flat list (in-place modification).
|
for intervals that have sufficient lookback data (in-place modification).
|
||||||
|
|
||||||
|
CRITICAL: Only enriches intervals that have at least 24 hours of prior data
|
||||||
|
available. This is determined by checking if (interval_start - earliest_interval_start) >= 24h.
|
||||||
|
Works independently of interval density (24 vs 96 intervals/day) and handles
|
||||||
|
transition periods (e.g., Oct 1, 2025) correctly.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
all_intervals: Flat list of all price intervals.
|
all_intervals: Flat list of all price intervals (day_before_yesterday + yesterday + today + tomorrow).
|
||||||
threshold_low: Low threshold percentage for rating_level (defaults to -10)
|
threshold_low: Low threshold percentage for rating_level (defaults to -10)
|
||||||
threshold_high: High threshold percentage for rating_level (defaults to 10)
|
threshold_high: High threshold percentage for rating_level (defaults to 10)
|
||||||
time: TibberPricesTimeService instance (required)
|
time: TibberPricesTimeService instance (kept for API compatibility, not used)
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Same list (modified in-place) with 'difference' and 'rating_level' added
|
Same list (modified in-place) with 'difference' and 'rating_level' added
|
||||||
|
to intervals that have full 24h lookback data. Intervals within the first
|
||||||
|
24 hours remain unenriched.
|
||||||
|
|
||||||
|
Note:
|
||||||
|
Interval density changed on Oct 1, 2025 from 24 to 96 intervals/day.
|
||||||
|
This function works correctly across this transition by using time-based
|
||||||
|
rather than count-based logic.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if threshold_low is None:
|
threshold_low = threshold_low if threshold_low is not None else -10
|
||||||
threshold_low = -10
|
threshold_high = threshold_high if threshold_high is not None else 10
|
||||||
if threshold_high is None:
|
|
||||||
threshold_high = 10
|
|
||||||
|
|
||||||
if not all_intervals:
|
if not all_intervals:
|
||||||
return all_intervals
|
return all_intervals
|
||||||
|
|
||||||
# Determine day keys for logging
|
# Find the earliest interval timestamp (start of available data)
|
||||||
now_date = time.now().date()
|
earliest_start: datetime | None = None
|
||||||
yesterday_date = now_date - timedelta(days=1)
|
for interval in all_intervals:
|
||||||
tomorrow_date = now_date + timedelta(days=1)
|
starts_at = interval.get("startsAt")
|
||||||
|
if starts_at and (earliest_start is None or starts_at < earliest_start):
|
||||||
|
earliest_start = starts_at
|
||||||
|
|
||||||
yesterday_count = sum(1 for p in all_intervals if p.get("startsAt") and p["startsAt"].date() == yesterday_date)
|
if earliest_start is None:
|
||||||
today_count = sum(1 for p in all_intervals if p.get("startsAt") and p["startsAt"].date() == now_date)
|
_LOGGER.debug("No valid timestamps found in intervals - skipping enrichment")
|
||||||
tomorrow_count = sum(1 for p in all_intervals if p.get("startsAt") and p["startsAt"].date() == tomorrow_date)
|
return all_intervals
|
||||||
|
|
||||||
|
# Calculate the 24-hour boundary from earliest data
|
||||||
|
# Only intervals starting at or after this boundary have full 24h lookback
|
||||||
|
enrichment_boundary = earliest_start + timedelta(hours=24)
|
||||||
|
|
||||||
_LOGGER.debug(
|
_LOGGER.debug(
|
||||||
"Enriching price info with differences and rating levels: "
|
"Enrichment boundary: earliest_start=%s, boundary=%s (skip first 24h)",
|
||||||
"yesterday=%d, today=%d, tomorrow=%d, thresholds: low=%.2f, high=%.2f",
|
earliest_start,
|
||||||
yesterday_count,
|
enrichment_boundary,
|
||||||
today_count,
|
|
||||||
tomorrow_count,
|
|
||||||
threshold_low,
|
|
||||||
threshold_high,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# Process all intervals (modifies in-place)
|
# Process intervals (modifies in-place)
|
||||||
|
# CRITICAL: Only enrich intervals that start >= 24h after earliest data
|
||||||
|
enriched_count = 0
|
||||||
|
skipped_count = 0
|
||||||
|
|
||||||
for price_interval in all_intervals:
|
for price_interval in all_intervals:
|
||||||
starts_at = price_interval.get("startsAt")
|
starts_at = price_interval.get("startsAt")
|
||||||
if not starts_at:
|
if not starts_at:
|
||||||
|
skipped_count += 1
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Determine day key for this interval
|
# Skip if interval doesn't have full 24h lookback
|
||||||
interval_date = starts_at.date()
|
if starts_at < enrichment_boundary:
|
||||||
if interval_date == yesterday_date:
|
skipped_count += 1
|
||||||
day_key = "yesterday"
|
continue
|
||||||
elif interval_date == now_date:
|
|
||||||
day_key = "today"
|
|
||||||
elif interval_date == tomorrow_date:
|
|
||||||
day_key = "tomorrow"
|
|
||||||
else:
|
|
||||||
day_key = "unknown"
|
|
||||||
|
|
||||||
_process_price_interval(price_interval, all_intervals, threshold_low, threshold_high, day_key)
|
_process_price_interval(price_interval, all_intervals, threshold_low, threshold_high, "enriched")
|
||||||
|
enriched_count += 1
|
||||||
|
|
||||||
|
_LOGGER.debug(
|
||||||
|
"Enrichment complete: %d intervals enriched, %d intervals skipped (within first 24h or invalid)",
|
||||||
|
enriched_count,
|
||||||
|
skipped_count,
|
||||||
|
)
|
||||||
|
|
||||||
return all_intervals
|
return all_intervals
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue