From fe5af68f8e539e15f84c964019ceb8d124896137 Mon Sep 17 00:00:00 2001 From: Julian Pawlowski Date: Fri, 14 Nov 2025 09:52:28 +0000 Subject: [PATCH] feat(sensor): add icon color determination based on price trend state --- custom_components/tibber_prices/sensor.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/custom_components/tibber_prices/sensor.py b/custom_components/tibber_prices/sensor.py index f58e6d4..9c9ac91 100644 --- a/custom_components/tibber_prices/sensor.py +++ b/custom_components/tibber_prices/sensor.py @@ -1307,6 +1307,13 @@ class TibberPricesSensor(TibberPricesEntity, SensorEntity): current_price, future_avg, threshold_rising=threshold_rising, threshold_falling=threshold_falling ) + # Determine icon color based on trend state + icon_color = { + "rising": "var(--error-color)", # Red/Orange for rising prices (expensive) + "falling": "var(--success-color)", # Green for falling prices (cheaper) + "stable": "var(--state-icon-color)", # Default gray for stable prices + }.get(trend_state, "var(--state-icon-color)") + # Store attributes in sensor-specific dictionary AND cache the trend value self._trend_attributes = { "timestamp": next_interval_start.isoformat(), @@ -1315,6 +1322,7 @@ class TibberPricesSensor(TibberPricesEntity, SensorEntity): "interval_count": hours * 4, "threshold_rising": threshold_rising, "threshold_falling": threshold_falling, + "icon_color": icon_color, } # Calculate additional attributes for better granularity