From f3f4bcfe451a32e3b79c8aaa94be205d4e50b173 Mon Sep 17 00:00:00 2001 From: Paul Bottein Date: Wed, 3 Sep 2025 12:56:05 +0200 Subject: [PATCH] Rename history chart to trend graph (#26854) * Rename history chart to trend graph * rename element and prettier --------- Co-authored-by: Bram Kragten --- ...ure.ts => hui-trend-graph-card-feature.ts} | 28 +++++++++++-------- src/panels/lovelace/card-features/types.ts | 10 +++---- .../create-card-feature-element.ts | 4 +-- .../hui-card-features-editor.ts | 6 ++-- .../home/home-climate-view-strategy.ts | 4 +-- src/translations/en.json | 4 +-- 6 files changed, 30 insertions(+), 26 deletions(-) rename src/panels/lovelace/card-features/{hui-history-chart-card-feature.ts => hui-trend-graph-card-feature.ts} (85%) diff --git a/src/panels/lovelace/card-features/hui-history-chart-card-feature.ts b/src/panels/lovelace/card-features/hui-trend-graph-card-feature.ts similarity index 85% rename from src/panels/lovelace/card-features/hui-history-chart-card-feature.ts rename to src/panels/lovelace/card-features/hui-trend-graph-card-feature.ts index f2b3f47d5f..803f5d8fe4 100644 --- a/src/panels/lovelace/card-features/hui-history-chart-card-feature.ts +++ b/src/panels/lovelace/card-features/hui-trend-graph-card-feature.ts @@ -11,11 +11,11 @@ import { coordinatesMinimalResponseCompressedState } from "../common/graph/coord import "../components/hui-graph-base"; import type { LovelaceCardFeature } from "../types"; import type { - HistoryChartCardFeatureConfig, + TrendGraphCardFeatureConfig, LovelaceCardFeatureContext, } from "./types"; -export const supportsHistoryChartCardFeature = ( +export const supportsTrendGraphCardFeature = ( hass: HomeAssistant, context: LovelaceCardFeatureContext ) => { @@ -27,7 +27,9 @@ export const supportsHistoryChartCardFeature = ( return domain === "sensor" && isNumericFromAttributes(stateObj.attributes); }; -@customElement("hui-history-chart-card-feature") +const DEFAULT_HOURS_TO_SHOW = 24; + +@customElement("hui-trend-graph-card-feature") class HuiHistoryChartCardFeature extends SubscribeMixin(LitElement) implements LovelaceCardFeature @@ -37,20 +39,19 @@ class HuiHistoryChartCardFeature @property({ attribute: false }) public context?: LovelaceCardFeatureContext; - @state() private _config?: HistoryChartCardFeatureConfig; + @state() private _config?: TrendGraphCardFeatureConfig; @state() private _coordinates?: [number, number][]; private _interval?: number; - static getStubConfig(): HistoryChartCardFeatureConfig { + static getStubConfig(): TrendGraphCardFeatureConfig { return { - type: "history-chart", - hours_to_show: 24, + type: "trend-graph", }; } - public setConfig(config: HistoryChartCardFeatureConfig): void { + public setConfig(config: TrendGraphCardFeatureConfig): void { if (!config) { throw new Error("Invalid configuration"); } @@ -78,7 +79,7 @@ class HuiHistoryChartCardFeature !this._config || !this.hass || !this.context || - !supportsHistoryChartCardFeature(this.hass, this.context) + !supportsTrendGraphCardFeature(this.hass, this.context) ) { return nothing; } @@ -109,19 +110,22 @@ class HuiHistoryChartCardFeature ) { return () => Promise.resolve(); } + + const hourToShow = this._config.hours_to_show ?? DEFAULT_HOURS_TO_SHOW; + return subscribeHistoryStatesTimeWindow( this.hass!, (historyStates) => { this._coordinates = coordinatesMinimalResponseCompressedState( historyStates[this.context!.entity_id!], - this._config!.hours_to_show ?? 24, + hourToShow, 500, 2, undefined ) || []; }, - this._config!.hours_to_show ?? 24, + hourToShow, [this.context!.entity_id!] ); } @@ -148,6 +152,6 @@ class HuiHistoryChartCardFeature declare global { interface HTMLElementTagNameMap { - "hui-history-chart-card-feature": HuiHistoryChartCardFeature; + "hui-trend-graph-card-feature": HuiHistoryChartCardFeature; } } diff --git a/src/panels/lovelace/card-features/types.ts b/src/panels/lovelace/card-features/types.ts index 7dcf1fb225..6d550bab98 100644 --- a/src/panels/lovelace/card-features/types.ts +++ b/src/panels/lovelace/card-features/types.ts @@ -187,9 +187,9 @@ export interface UpdateActionsCardFeatureConfig { backup?: "yes" | "no" | "ask"; } -export interface HistoryChartCardFeatureConfig { - type: "history-chart"; - hours_to_show: number; +export interface TrendGraphCardFeatureConfig { + type: "trend-graph"; + hours_to_show?: number; } export const AREA_CONTROLS = [ @@ -239,7 +239,7 @@ export type LovelaceCardFeatureConfig = | FanOscillateCardFeatureConfig | FanPresetModesCardFeatureConfig | FanSpeedCardFeatureConfig - | HistoryChartCardFeatureConfig + | TrendGraphCardFeatureConfig | HumidifierToggleCardFeatureConfig | HumidifierModesCardFeatureConfig | LawnMowerCommandsCardFeatureConfig @@ -251,7 +251,7 @@ export type LovelaceCardFeatureConfig = | MediaPlayerVolumeSliderCardFeatureConfig | NumericInputCardFeatureConfig | SelectOptionsCardFeatureConfig - | HistoryChartCardFeatureConfig + | TrendGraphCardFeatureConfig | TargetHumidityCardFeatureConfig | TargetTemperatureCardFeatureConfig | ToggleCardFeatureConfig diff --git a/src/panels/lovelace/create-element/create-card-feature-element.ts b/src/panels/lovelace/create-element/create-card-feature-element.ts index 03fa268289..2b0e319587 100644 --- a/src/panels/lovelace/create-element/create-card-feature-element.ts +++ b/src/panels/lovelace/create-element/create-card-feature-element.ts @@ -36,7 +36,7 @@ import "../card-features/hui-valve-position-card-feature"; import "../card-features/hui-water-heater-operation-modes-card-feature"; import "../card-features/hui-area-controls-card-feature"; import "../card-features/hui-bar-gauge-card-feature"; -import "../card-features/hui-history-chart-card-feature"; +import "../card-features/hui-trend-graph-card-feature"; import type { LovelaceCardFeatureConfig } from "../card-features/types"; import { @@ -75,7 +75,7 @@ const TYPES = new Set([ "media-player-volume-slider", "numeric-input", "select-options", - "history-chart", + "trend-graph", "target-humidity", "target-temperature", "toggle", diff --git a/src/panels/lovelace/editor/config-elements/hui-card-features-editor.ts b/src/panels/lovelace/editor/config-elements/hui-card-features-editor.ts index c75c3721ad..11183d9dc6 100644 --- a/src/panels/lovelace/editor/config-elements/hui-card-features-editor.ts +++ b/src/panels/lovelace/editor/config-elements/hui-card-features-editor.ts @@ -46,7 +46,7 @@ import { supportsMediaPlayerPlaybackCardFeature } from "../../card-features/hui- import { supportsMediaPlayerVolumeSliderCardFeature } from "../../card-features/hui-media-player-volume-slider-card-feature"; import { supportsNumericInputCardFeature } from "../../card-features/hui-numeric-input-card-feature"; import { supportsSelectOptionsCardFeature } from "../../card-features/hui-select-options-card-feature"; -import { supportsHistoryChartCardFeature } from "../../card-features/hui-history-chart-card-feature"; +import { supportsTrendGraphCardFeature } from "../../card-features/hui-trend-graph-card-feature"; import { supportsTargetHumidityCardFeature } from "../../card-features/hui-target-humidity-card-feature"; import { supportsTargetTemperatureCardFeature } from "../../card-features/hui-target-temperature-card-feature"; import { supportsToggleCardFeature } from "../../card-features/hui-toggle-card-feature"; @@ -100,7 +100,7 @@ const UI_FEATURE_TYPES = [ "media-player-volume-slider", "numeric-input", "select-options", - "history-chart", + "trend-graph", "target-humidity", "target-temperature", "toggle", @@ -168,7 +168,7 @@ const SUPPORTS_FEATURE_TYPES: Record< "media-player-volume-slider": supportsMediaPlayerVolumeSliderCardFeature, "numeric-input": supportsNumericInputCardFeature, "select-options": supportsSelectOptionsCardFeature, - "history-chart": supportsHistoryChartCardFeature, + "trend-graph": supportsTrendGraphCardFeature, "target-humidity": supportsTargetHumidityCardFeature, "target-temperature": supportsTargetTemperatureCardFeature, toggle: supportsToggleCardFeature, diff --git a/src/panels/lovelace/strategies/home/home-climate-view-strategy.ts b/src/panels/lovelace/strategies/home/home-climate-view-strategy.ts index 80df571287..b779480b9f 100644 --- a/src/panels/lovelace/strategies/home/home-climate-view-strategy.ts +++ b/src/panels/lovelace/strategies/home/home-climate-view-strategy.ts @@ -48,13 +48,13 @@ const processAreasForClimate = ( if (area.temperature_entity_id) { cards.push({ ...computeTileCard(area.temperature_entity_id), - features: [{ type: "history-chart" }], + features: [{ type: "trend-graph" }], }); } if (area.humidity_entity_id) { cards.push({ ...computeTileCard(area.humidity_entity_id), - features: [{ type: "history-chart" }], + features: [{ type: "trend-graph" }], }); } diff --git a/src/translations/en.json b/src/translations/en.json index 491bf38b76..522d0638d3 100644 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -8206,8 +8206,8 @@ "bar-gauge": { "label": "Bar gauge" }, - "history-chart": { - "label": "History chart" + "trend-graph": { + "label": "Trend graph" } } },