From 6521aa7bdd0d383de17b6e1fe7fee68b7d117cef Mon Sep 17 00:00:00 2001 From: Julian Pawlowski Date: Fri, 14 Nov 2025 09:39:37 +0000 Subject: [PATCH] feat(sensor): add dynamic icon support for price trend sensors --- custom_components/tibber_prices/sensor.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/custom_components/tibber_prices/sensor.py b/custom_components/tibber_prices/sensor.py index 9f648e7..f58e6d4 100644 --- a/custom_components/tibber_prices/sensor.py +++ b/custom_components/tibber_prices/sensor.py @@ -1718,6 +1718,25 @@ class TibberPricesSensor(TibberPricesEntity, SensorEntity): return format_price_unit_minor(currency) + @property + def icon(self) -> str | None: + """Return the icon based on sensor type and state.""" + # Dynamic icons for trend sensors + if self.entity_description.key.startswith("price_trend_"): + match self.native_value: + case "rising": + return "mdi:trending-up" + case "falling": + return "mdi:trending-down" + case "stable": + return "mdi:trending-neutral" + case _: + # Fallback to static icon if value is None or unknown + return self.entity_description.icon + + # For all other sensors, use static icon from entity description + return self.entity_description.icon + @property async def async_extra_state_attributes(self) -> dict | None: """Return additional state attributes asynchronously."""