diff --git a/custom_components/tibber_prices/binary_sensor/attributes.py b/custom_components/tibber_prices/binary_sensor/attributes.py index ae56eca..a057444 100644 --- a/custom_components/tibber_prices/binary_sensor/attributes.py +++ b/custom_components/tibber_prices/binary_sensor/attributes.py @@ -127,7 +127,7 @@ def get_price_intervals_attributes( | { "period_position": i, "period_count_total": total_filtered, - "periods_remaining": total_filtered - i, + "period_count_remaining": total_filtered - i, } for i, period in enumerate(filtered_periods, 1) ] @@ -266,8 +266,8 @@ def add_detail_attributes(attributes: dict, current_period: dict) -> None: attributes["period_position"] = current_period["period_position"] if "period_count_total" in current_period: attributes["period_count_total"] = current_period["period_count_total"] - if "periods_remaining" in current_period: - attributes["periods_remaining"] = current_period["periods_remaining"] + if "period_count_remaining" in current_period: + attributes["period_count_remaining"] = current_period["period_count_remaining"] def add_period_count_attributes( @@ -421,7 +421,7 @@ def build_final_attributes_simple( 2. Core decision attributes (level, rating_level, rating_difference_%) 3. Price statistics (price_mean, price_median, price_min, price_max, price_spread, volatility) 4. Price differences (period_price_diff_from_daily_min, period_price_diff_from_daily_min_%) - 5. Detail information (period_interval_count, period_position, period_count_total, periods_remaining) + 5. Detail information (period_interval_count, period_position, period_count_total, period_count_remaining) 6. Relaxation information (relaxation_active, relaxation_level, relaxation_threshold_original_%, relaxation_threshold_applied_%) - only if current period was relaxed 7. Calculation summary (min_periods_configured, flat_days_detected, diff --git a/custom_components/tibber_prices/binary_sensor/core.py b/custom_components/tibber_prices/binary_sensor/core.py index fe3ca45..57c865f 100644 --- a/custom_components/tibber_prices/binary_sensor/core.py +++ b/custom_components/tibber_prices/binary_sensor/core.py @@ -73,7 +73,7 @@ class TibberPricesBinarySensor(TibberPricesEntity, BinarySensorEntity, RestoreEn "period_price_diff_from_daily_min", "period_price_diff_from_daily_min_%", "period_count_total", - "periods_remaining", + "period_count_remaining", } ) diff --git a/custom_components/tibber_prices/binary_sensor/types.py b/custom_components/tibber_prices/binary_sensor/types.py index 5b297ed..98f3b9d 100644 --- a/custom_components/tibber_prices/binary_sensor/types.py +++ b/custom_components/tibber_prices/binary_sensor/types.py @@ -105,7 +105,7 @@ class PeriodSummary(TypedDict, total=False): period_interval_count: int # Number of intervals in period period_position: int # Period position (1-based) period_count_total: int # Total number of periods - periods_remaining: int # Remaining periods after this one + period_count_remaining: int # Remaining periods after this one # Relaxation information (priority 6 - only if period was relaxed) relaxation_active: bool # Whether this period was found via relaxation @@ -125,7 +125,7 @@ class PeriodAttributes(BaseAttributes, total=False): 2. Core decision attributes (level, rating_level, rating_difference_%) 3. Price statistics (price_mean, price_median, price_min, price_max, price_spread, volatility) 4. Price comparison (period_price_diff_from_daily_min, period_price_diff_from_daily_min_%) - 5. Detail information (period_interval_count, period_position, period_count_total, periods_remaining) + 5. Detail information (period_interval_count, period_position, period_count_total, period_count_remaining) 6. Relaxation information (only if period was relaxed) 7. Meta information (periods list) """ @@ -156,7 +156,7 @@ class PeriodAttributes(BaseAttributes, total=False): period_interval_count: int # Number of intervals in current/next period period_position: int # Period position (1-based) period_count_total: int # Total number of periods found - periods_remaining: int # Remaining periods after current/next one + period_count_remaining: int # Remaining periods after current/next one # Relaxation information (priority 6 - only if period was relaxed) relaxation_active: bool # Whether current/next period was found via relaxation diff --git a/custom_components/tibber_prices/coordinator/period_handlers/period_overlap.py b/custom_components/tibber_prices/coordinator/period_handlers/period_overlap.py index 5490023..ec43e5f 100644 --- a/custom_components/tibber_prices/coordinator/period_handlers/period_overlap.py +++ b/custom_components/tibber_prices/coordinator/period_handlers/period_overlap.py @@ -56,7 +56,7 @@ def recalculate_period_metadata(periods: list[dict], *, time: TibberPricesTimeSe """ Recalculate period metadata after merging periods. - Updates period_position, period_count_total, and periods_remaining for all periods + Updates period_position, period_count_total, and period_count_remaining for all periods based on chronological order. This must be called after resolve_period_overlaps() to ensure metadata @@ -79,7 +79,7 @@ def recalculate_period_metadata(periods: list[dict], *, time: TibberPricesTimeSe for position, period in enumerate(periods, 1): period["period_position"] = position period["period_count_total"] = total_periods - period["periods_remaining"] = total_periods - position + period["period_count_remaining"] = total_periods - position def merge_adjacent_periods(period1: dict, period2: dict) -> dict: diff --git a/custom_components/tibber_prices/coordinator/period_handlers/period_statistics.py b/custom_components/tibber_prices/coordinator/period_handlers/period_statistics.py index 8ce6f37..dbd9289 100644 --- a/custom_components/tibber_prices/coordinator/period_handlers/period_statistics.py +++ b/custom_components/tibber_prices/coordinator/period_handlers/period_statistics.py @@ -179,7 +179,7 @@ def build_period_summary_dict( "period_interval_count": period_data.period_length, "period_position": period_data.period_idx, "period_count_total": period_data.total_periods, - "periods_remaining": period_data.total_periods - period_data.period_idx, + "period_count_remaining": period_data.total_periods - period_data.period_idx, } # Add period price difference attributes based on sensor type (step 4) diff --git a/custom_components/tibber_prices/sensor/core.py b/custom_components/tibber_prices/sensor/core.py index 3ea0410..43add84 100644 --- a/custom_components/tibber_prices/sensor/core.py +++ b/custom_components/tibber_prices/sensor/core.py @@ -173,7 +173,7 @@ class TibberPricesSensor(TibberPricesEntity, RestoreSensor): "period_price_diff_from_daily_min", "period_price_diff_from_daily_min_%", "period_count_total", - "periods_remaining", + "period_count_remaining", } ) diff --git a/docs/developer/docs/recorder-optimization.md b/docs/developer/docs/recorder-optimization.md index e602f7d..60d5aa0 100644 --- a/docs/developer/docs/recorder-optimization.md +++ b/docs/developer/docs/recorder-optimization.md @@ -137,7 +137,7 @@ class TibberPricesSensor(TibberPricesEntity, SensorEntity): ### 7. Redundant/Derived Data -**Attributes:** `price_spread`, `volatility`, `diff_%`, `rating_difference_%`, `period_price_diff_from_daily_min`, `period_price_diff_from_daily_min_%`, `period_count_total`, `periods_remaining` +**Attributes:** `price_spread`, `volatility`, `diff_%`, `rating_difference_%`, `period_price_diff_from_daily_min`, `period_price_diff_from_daily_min_%`, `period_count_total`, `period_count_remaining` **Reason:** - Can be calculated from other attributes @@ -146,7 +146,7 @@ class TibberPricesSensor(TibberPricesEntity, SensorEntity): **Impact:** ~100-200 bytes saved per state change -**Example:** `price_spread = price_max - price_min` (both are recorded, so spread can be calculated). `periods_remaining = period_count_total - period_position` (both components are recorded). +**Example:** `price_spread = price_max - price_min` (both are recorded, so spread can be calculated). `period_count_remaining = period_count_total - period_position` (both components are recorded). ## Attributes That ARE Recorded