Theme Addition (#2178)

This commit is contained in:
Zack Arnett 2018-12-04 13:49:46 -05:00 committed by Paulus Schoutsen
parent 1d7f574b9b
commit 8274284294

View File

@ -13,6 +13,7 @@ import { LovelaceCardConfig } from "../../../data/lovelace";
import { HomeAssistant } from "../../../types";
import { fireEvent } from "../../../common/dom/fire_event";
import applyThemesOnElement from "../../../common/dom/apply_themes_on_element";
import computeStateName from "../../../common/entity/compute_state_name";
import stateIcon from "../../../common/entity/state_icon";
@ -139,6 +140,7 @@ interface Config extends LovelaceCardConfig {
graph?: string;
unit?: string;
detail?: number;
theme?: string;
hours_to_show?: number;
}
@ -163,6 +165,7 @@ class HuiSensorCard extends LitElement implements LovelaceCard {
const cardConfig = {
detail: 1,
theme: "default",
hours_to_show: 24,
...config,
};
@ -262,10 +265,15 @@ class HuiSensorCard extends LitElement implements LovelaceCard {
}
protected updated(changedProps: PropertyValues) {
if (this._config && this._config.graph !== "line") {
if (!this._config || this._config.graph !== "line" || !this.hass) {
return;
}
const oldHass = changedProps.get("hass") as HomeAssistant | undefined;
if (!oldHass || oldHass.themes !== this.hass.themes) {
applyThemesOnElement(this, this.hass.themes, this._config!.theme);
}
const minute = 60000;
if (changedProps.has("_config")) {
this._getHistory();