mirror of
https://github.com/jpawlowski/hass.tibber_prices.git
synced 2026-03-29 21:03:40 +00:00
feat(sensor): add dynamic icon support for price trend sensors
This commit is contained in:
parent
3a9234ffbf
commit
6521aa7bdd
1 changed files with 19 additions and 0 deletions
|
|
@ -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."""
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue