refactor(colors, icons): enhance trend-related color and icon handling
Some checks are pending
Deploy Docusaurus Documentation (Dual Sites) / Build and Deploy Documentation Sites (push) Waiting to run
Lint / Ruff (push) Waiting to run
Validate / Hassfest validation (push) Waiting to run
Validate / HACS validation (push) Waiting to run

Updated color and icon logic to include additional keys for price trends, outlooks, and trajectories. This improves the visual representation of price changes in the UI.

Impact: Users will see more accurate color coding and icons for price trends and forecasts.
This commit is contained in:
Julian Pawlowski 2026-04-14 09:22:34 +00:00
parent ff08df24e7
commit 9efa7809d0
2 changed files with 6 additions and 2 deletions

View file

@ -65,10 +65,14 @@ def get_icon_color(
return BINARY_SENSOR_COLOR_MAPPING[key].get(state_key)
# Trend sensor colors (based on trend state)
if key.startswith("price_trend_") and isinstance(state_value, str):
if (
key.startswith(("price_trend_", "price_outlook_", "price_trajectory_")) or key == "current_price_trend"
) and isinstance(state_value, str):
trend_colors = {
"strongly_rising": "var(--error-color)",
"rising": "var(--error-color)", # Red/Orange for rising prices
"falling": "var(--success-color)", # Green for falling prices
"strongly_falling": "var(--success-color)",
"stable": "var(--state-icon-color)", # Default gray for stable
}
return trend_colors.get(state_value)

View file

@ -91,7 +91,7 @@ def get_trend_icon(key: str, value: Any) -> str | None:
if key == "next_price_trend_change":
return None # Will be handled by sensor's icon property using attributes
if not key.startswith("price_trend_") and key != "current_price_trend":
if not key.startswith(("price_trend_", "price_outlook_", "price_trajectory_")) and key != "current_price_trend":
return None
if not isinstance(value, str):