feat(sensor): add dynamic icon support for price trend sensors

This commit is contained in:
Julian Pawlowski 2025-11-14 09:39:37 +00:00
parent 3a9234ffbf
commit 6521aa7bdd

View file

@ -1718,6 +1718,25 @@ class TibberPricesSensor(TibberPricesEntity, SensorEntity):
return format_price_unit_minor(currency) 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 @property
async def async_extra_state_attributes(self) -> dict | None: async def async_extra_state_attributes(self) -> dict | None:
"""Return additional state attributes asynchronously.""" """Return additional state attributes asynchronously."""