mirror of
https://github.com/home-assistant/frontend.git
synced 2025-11-08 02:19:43 +00:00
Rename history chart to trend graph (#26854)
* Rename history chart to trend graph * rename element and prettier --------- Co-authored-by: Bram Kragten <mail@bramkragten.nl>
This commit is contained in:
@@ -11,11 +11,11 @@ import { coordinatesMinimalResponseCompressedState } from "../common/graph/coord
|
|||||||
import "../components/hui-graph-base";
|
import "../components/hui-graph-base";
|
||||||
import type { LovelaceCardFeature } from "../types";
|
import type { LovelaceCardFeature } from "../types";
|
||||||
import type {
|
import type {
|
||||||
HistoryChartCardFeatureConfig,
|
TrendGraphCardFeatureConfig,
|
||||||
LovelaceCardFeatureContext,
|
LovelaceCardFeatureContext,
|
||||||
} from "./types";
|
} from "./types";
|
||||||
|
|
||||||
export const supportsHistoryChartCardFeature = (
|
export const supportsTrendGraphCardFeature = (
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
context: LovelaceCardFeatureContext
|
context: LovelaceCardFeatureContext
|
||||||
) => {
|
) => {
|
||||||
@@ -27,7 +27,9 @@ export const supportsHistoryChartCardFeature = (
|
|||||||
return domain === "sensor" && isNumericFromAttributes(stateObj.attributes);
|
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
|
class HuiHistoryChartCardFeature
|
||||||
extends SubscribeMixin(LitElement)
|
extends SubscribeMixin(LitElement)
|
||||||
implements LovelaceCardFeature
|
implements LovelaceCardFeature
|
||||||
@@ -37,20 +39,19 @@ class HuiHistoryChartCardFeature
|
|||||||
|
|
||||||
@property({ attribute: false }) public context?: LovelaceCardFeatureContext;
|
@property({ attribute: false }) public context?: LovelaceCardFeatureContext;
|
||||||
|
|
||||||
@state() private _config?: HistoryChartCardFeatureConfig;
|
@state() private _config?: TrendGraphCardFeatureConfig;
|
||||||
|
|
||||||
@state() private _coordinates?: [number, number][];
|
@state() private _coordinates?: [number, number][];
|
||||||
|
|
||||||
private _interval?: number;
|
private _interval?: number;
|
||||||
|
|
||||||
static getStubConfig(): HistoryChartCardFeatureConfig {
|
static getStubConfig(): TrendGraphCardFeatureConfig {
|
||||||
return {
|
return {
|
||||||
type: "history-chart",
|
type: "trend-graph",
|
||||||
hours_to_show: 24,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public setConfig(config: HistoryChartCardFeatureConfig): void {
|
public setConfig(config: TrendGraphCardFeatureConfig): void {
|
||||||
if (!config) {
|
if (!config) {
|
||||||
throw new Error("Invalid configuration");
|
throw new Error("Invalid configuration");
|
||||||
}
|
}
|
||||||
@@ -78,7 +79,7 @@ class HuiHistoryChartCardFeature
|
|||||||
!this._config ||
|
!this._config ||
|
||||||
!this.hass ||
|
!this.hass ||
|
||||||
!this.context ||
|
!this.context ||
|
||||||
!supportsHistoryChartCardFeature(this.hass, this.context)
|
!supportsTrendGraphCardFeature(this.hass, this.context)
|
||||||
) {
|
) {
|
||||||
return nothing;
|
return nothing;
|
||||||
}
|
}
|
||||||
@@ -109,19 +110,22 @@ class HuiHistoryChartCardFeature
|
|||||||
) {
|
) {
|
||||||
return () => Promise.resolve();
|
return () => Promise.resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const hourToShow = this._config.hours_to_show ?? DEFAULT_HOURS_TO_SHOW;
|
||||||
|
|
||||||
return subscribeHistoryStatesTimeWindow(
|
return subscribeHistoryStatesTimeWindow(
|
||||||
this.hass!,
|
this.hass!,
|
||||||
(historyStates) => {
|
(historyStates) => {
|
||||||
this._coordinates =
|
this._coordinates =
|
||||||
coordinatesMinimalResponseCompressedState(
|
coordinatesMinimalResponseCompressedState(
|
||||||
historyStates[this.context!.entity_id!],
|
historyStates[this.context!.entity_id!],
|
||||||
this._config!.hours_to_show ?? 24,
|
hourToShow,
|
||||||
500,
|
500,
|
||||||
2,
|
2,
|
||||||
undefined
|
undefined
|
||||||
) || [];
|
) || [];
|
||||||
},
|
},
|
||||||
this._config!.hours_to_show ?? 24,
|
hourToShow,
|
||||||
[this.context!.entity_id!]
|
[this.context!.entity_id!]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -148,6 +152,6 @@ class HuiHistoryChartCardFeature
|
|||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
interface HTMLElementTagNameMap {
|
interface HTMLElementTagNameMap {
|
||||||
"hui-history-chart-card-feature": HuiHistoryChartCardFeature;
|
"hui-trend-graph-card-feature": HuiHistoryChartCardFeature;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -187,9 +187,9 @@ export interface UpdateActionsCardFeatureConfig {
|
|||||||
backup?: "yes" | "no" | "ask";
|
backup?: "yes" | "no" | "ask";
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface HistoryChartCardFeatureConfig {
|
export interface TrendGraphCardFeatureConfig {
|
||||||
type: "history-chart";
|
type: "trend-graph";
|
||||||
hours_to_show: number;
|
hours_to_show?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const AREA_CONTROLS = [
|
export const AREA_CONTROLS = [
|
||||||
@@ -239,7 +239,7 @@ export type LovelaceCardFeatureConfig =
|
|||||||
| FanOscillateCardFeatureConfig
|
| FanOscillateCardFeatureConfig
|
||||||
| FanPresetModesCardFeatureConfig
|
| FanPresetModesCardFeatureConfig
|
||||||
| FanSpeedCardFeatureConfig
|
| FanSpeedCardFeatureConfig
|
||||||
| HistoryChartCardFeatureConfig
|
| TrendGraphCardFeatureConfig
|
||||||
| HumidifierToggleCardFeatureConfig
|
| HumidifierToggleCardFeatureConfig
|
||||||
| HumidifierModesCardFeatureConfig
|
| HumidifierModesCardFeatureConfig
|
||||||
| LawnMowerCommandsCardFeatureConfig
|
| LawnMowerCommandsCardFeatureConfig
|
||||||
@@ -251,7 +251,7 @@ export type LovelaceCardFeatureConfig =
|
|||||||
| MediaPlayerVolumeSliderCardFeatureConfig
|
| MediaPlayerVolumeSliderCardFeatureConfig
|
||||||
| NumericInputCardFeatureConfig
|
| NumericInputCardFeatureConfig
|
||||||
| SelectOptionsCardFeatureConfig
|
| SelectOptionsCardFeatureConfig
|
||||||
| HistoryChartCardFeatureConfig
|
| TrendGraphCardFeatureConfig
|
||||||
| TargetHumidityCardFeatureConfig
|
| TargetHumidityCardFeatureConfig
|
||||||
| TargetTemperatureCardFeatureConfig
|
| TargetTemperatureCardFeatureConfig
|
||||||
| ToggleCardFeatureConfig
|
| ToggleCardFeatureConfig
|
||||||
|
|||||||
@@ -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-water-heater-operation-modes-card-feature";
|
||||||
import "../card-features/hui-area-controls-card-feature";
|
import "../card-features/hui-area-controls-card-feature";
|
||||||
import "../card-features/hui-bar-gauge-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 type { LovelaceCardFeatureConfig } from "../card-features/types";
|
||||||
import {
|
import {
|
||||||
@@ -75,7 +75,7 @@ const TYPES = new Set<LovelaceCardFeatureConfig["type"]>([
|
|||||||
"media-player-volume-slider",
|
"media-player-volume-slider",
|
||||||
"numeric-input",
|
"numeric-input",
|
||||||
"select-options",
|
"select-options",
|
||||||
"history-chart",
|
"trend-graph",
|
||||||
"target-humidity",
|
"target-humidity",
|
||||||
"target-temperature",
|
"target-temperature",
|
||||||
"toggle",
|
"toggle",
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ import { supportsMediaPlayerPlaybackCardFeature } from "../../card-features/hui-
|
|||||||
import { supportsMediaPlayerVolumeSliderCardFeature } from "../../card-features/hui-media-player-volume-slider-card-feature";
|
import { supportsMediaPlayerVolumeSliderCardFeature } from "../../card-features/hui-media-player-volume-slider-card-feature";
|
||||||
import { supportsNumericInputCardFeature } from "../../card-features/hui-numeric-input-card-feature";
|
import { supportsNumericInputCardFeature } from "../../card-features/hui-numeric-input-card-feature";
|
||||||
import { supportsSelectOptionsCardFeature } from "../../card-features/hui-select-options-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 { supportsTargetHumidityCardFeature } from "../../card-features/hui-target-humidity-card-feature";
|
||||||
import { supportsTargetTemperatureCardFeature } from "../../card-features/hui-target-temperature-card-feature";
|
import { supportsTargetTemperatureCardFeature } from "../../card-features/hui-target-temperature-card-feature";
|
||||||
import { supportsToggleCardFeature } from "../../card-features/hui-toggle-card-feature";
|
import { supportsToggleCardFeature } from "../../card-features/hui-toggle-card-feature";
|
||||||
@@ -100,7 +100,7 @@ const UI_FEATURE_TYPES = [
|
|||||||
"media-player-volume-slider",
|
"media-player-volume-slider",
|
||||||
"numeric-input",
|
"numeric-input",
|
||||||
"select-options",
|
"select-options",
|
||||||
"history-chart",
|
"trend-graph",
|
||||||
"target-humidity",
|
"target-humidity",
|
||||||
"target-temperature",
|
"target-temperature",
|
||||||
"toggle",
|
"toggle",
|
||||||
@@ -168,7 +168,7 @@ const SUPPORTS_FEATURE_TYPES: Record<
|
|||||||
"media-player-volume-slider": supportsMediaPlayerVolumeSliderCardFeature,
|
"media-player-volume-slider": supportsMediaPlayerVolumeSliderCardFeature,
|
||||||
"numeric-input": supportsNumericInputCardFeature,
|
"numeric-input": supportsNumericInputCardFeature,
|
||||||
"select-options": supportsSelectOptionsCardFeature,
|
"select-options": supportsSelectOptionsCardFeature,
|
||||||
"history-chart": supportsHistoryChartCardFeature,
|
"trend-graph": supportsTrendGraphCardFeature,
|
||||||
"target-humidity": supportsTargetHumidityCardFeature,
|
"target-humidity": supportsTargetHumidityCardFeature,
|
||||||
"target-temperature": supportsTargetTemperatureCardFeature,
|
"target-temperature": supportsTargetTemperatureCardFeature,
|
||||||
toggle: supportsToggleCardFeature,
|
toggle: supportsToggleCardFeature,
|
||||||
|
|||||||
@@ -48,13 +48,13 @@ const processAreasForClimate = (
|
|||||||
if (area.temperature_entity_id) {
|
if (area.temperature_entity_id) {
|
||||||
cards.push({
|
cards.push({
|
||||||
...computeTileCard(area.temperature_entity_id),
|
...computeTileCard(area.temperature_entity_id),
|
||||||
features: [{ type: "history-chart" }],
|
features: [{ type: "trend-graph" }],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (area.humidity_entity_id) {
|
if (area.humidity_entity_id) {
|
||||||
cards.push({
|
cards.push({
|
||||||
...computeTileCard(area.humidity_entity_id),
|
...computeTileCard(area.humidity_entity_id),
|
||||||
features: [{ type: "history-chart" }],
|
features: [{ type: "trend-graph" }],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8206,8 +8206,8 @@
|
|||||||
"bar-gauge": {
|
"bar-gauge": {
|
||||||
"label": "Bar gauge"
|
"label": "Bar gauge"
|
||||||
},
|
},
|
||||||
"history-chart": {
|
"trend-graph": {
|
||||||
"label": "History chart"
|
"label": "Trend graph"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user