hass.tibber_prices/custom_components/tibber_prices/sensor/attributes/trend.py
Julian Pawlowski b1b41be9aa feat(sensors)!: rename trend change countdown sensor for naming consistency
Renamed trend_change_in_minutes → next_price_trend_change_in to align
with its sibling sensor next_price_trend_change (timestamp variant).

Follows the established best/peak price naming pattern where related
sensors share a common prefix (e.g. best_price_next_start_time /
best_price_next_in_minutes).

Updated entity key, translation key, friendly names (all 5 languages),
custom translations, coordinator constants, attribute routing, and
cache-clear mapping.

BREAKING CHANGE: Entity ID changes from
sensor.<home>_trend_change_in_minutes to
sensor.<home>_next_price_trend_change_in. Automations and dashboards
referencing the old entity ID must be updated.

Impact: Users with automations or dashboard cards referencing the old
sensor name need to update references. The sensor retains identical
functionality and attributes.
2026-04-10 09:08:27 +00:00

44 lines
2 KiB
Python

"""Trend attribute builders for Tibber Prices sensors."""
from __future__ import annotations
from typing import TYPE_CHECKING, Any
if TYPE_CHECKING:
from custom_components.tibber_prices.coordinator.time_service import TibberPricesTimeService
from .timing import add_period_timing_attributes
from .volatility import add_volatility_attributes
def _add_timing_or_volatility_attributes(
attributes: dict,
key: str,
cached_data: dict,
native_value: Any = None,
*,
time: TibberPricesTimeService,
) -> None:
"""Add attributes for timing or volatility sensors."""
if key.endswith("_volatility"):
add_volatility_attributes(attributes=attributes, cached_data=cached_data, time=time)
else:
add_period_timing_attributes(attributes=attributes, key=key, state_value=native_value, time=time)
def _add_cached_trend_attributes(attributes: dict, key: str, cached_data: dict) -> None:
"""Add cached trend attributes if available."""
if key.startswith("price_outlook_") and cached_data.get("trend_attributes"):
attributes.update(cached_data["trend_attributes"])
elif key.startswith("price_trajectory_") and cached_data.get("trajectory_attributes"):
attributes.update(cached_data["trajectory_attributes"])
elif key == "current_price_trend" and cached_data.get("current_trend_attributes"):
# Add cached attributes (timestamp already set by platform)
attributes.update(cached_data["current_trend_attributes"])
elif key == "next_price_trend_change" and cached_data.get("trend_change_attributes"):
# Add cached attributes (timestamp already set by platform)
# State contains the timestamp of the trend change itself
attributes.update(cached_data["trend_change_attributes"])
elif key == "next_price_trend_change_in" and cached_data.get("trend_change_attributes"):
# Duration sensor shares same cached attributes as the timestamp sensor
attributes.update(cached_data["trend_change_attributes"])