🧹 remove unused configs when empty (#2347)

* Remove unused configs when empty

* Handle unused numbers & fix glance entities

* Sneak in the chunk names
This commit is contained in:
Ian Richardson 2018-12-18 04:15:32 -06:00 committed by Paulus Schoutsen
parent 849ed80e78
commit c47ba65c3b
24 changed files with 119 additions and 65 deletions

View File

@ -41,7 +41,7 @@ export interface Config extends LovelaceCardConfig {
class HuiAlarmPanelCard extends hassLocalizeLitMixin(LitElement) class HuiAlarmPanelCard extends hassLocalizeLitMixin(LitElement)
implements LovelaceCard { implements LovelaceCard {
public static async getConfigElement() { public static async getConfigElement() {
await import("../editor/config-elements/hui-alarm-panel-card-editor"); await import(/* webpackChunkName: "hui-alarm-panel-card-editor" */ "../editor/config-elements/hui-alarm-panel-card-editor");
return document.createElement("hui-alarm-panel-card-editor"); return document.createElement("hui-alarm-panel-card-editor");
} }

View File

@ -40,7 +40,7 @@ export interface Config extends LovelaceCardConfig {
class HuiEntitiesCard extends hassLocalizeLitMixin(LitElement) class HuiEntitiesCard extends hassLocalizeLitMixin(LitElement)
implements LovelaceCard { implements LovelaceCard {
public static async getConfigElement(): Promise<LovelaceCardEditor> { public static async getConfigElement(): Promise<LovelaceCardEditor> {
await import("../editor/config-elements/hui-entities-card-editor"); await import(/* webpackChunkName: "hui-entities-card-editor" */ "../editor/config-elements/hui-entities-card-editor");
return document.createElement("hui-entities-card-editor"); return document.createElement("hui-entities-card-editor");
} }

View File

@ -47,7 +47,7 @@ export const severityMap = {
class HuiGaugeCard extends LitElement implements LovelaceCard { class HuiGaugeCard extends LitElement implements LovelaceCard {
public static async getConfigElement(): Promise<LovelaceCardEditor> { public static async getConfigElement(): Promise<LovelaceCardEditor> {
await import("../editor/config-elements/hui-gauge-card-editor"); await import(/* webpackChunkName: "hui-gauge-card-editor" */ "../editor/config-elements/hui-gauge-card-editor");
return document.createElement("hui-gauge-card-editor"); return document.createElement("hui-gauge-card-editor");
} }
public static getStubConfig(): object { public static getStubConfig(): object {

View File

@ -41,7 +41,7 @@ export interface Config extends LovelaceCardConfig {
export class HuiGlanceCard extends hassLocalizeLitMixin(LitElement) export class HuiGlanceCard extends hassLocalizeLitMixin(LitElement)
implements LovelaceCard { implements LovelaceCard {
public static async getConfigElement(): Promise<LovelaceCardEditor> { public static async getConfigElement(): Promise<LovelaceCardEditor> {
await import("../editor/config-elements/hui-glance-card-editor"); await import(/* webpackChunkName: "hui-glance-card-editor" */ "../editor/config-elements/hui-glance-card-editor");
return document.createElement("hui-glance-card-editor"); return document.createElement("hui-glance-card-editor");
} }
public static getStubConfig(): object { public static getStubConfig(): object {

View File

@ -15,7 +15,7 @@ export interface Config extends LovelaceCardConfig {
export class HuiIframeCard extends LitElement implements LovelaceCard { export class HuiIframeCard extends LitElement implements LovelaceCard {
public static async getConfigElement(): Promise<LovelaceCardEditor> { public static async getConfigElement(): Promise<LovelaceCardEditor> {
await import("../editor/config-elements/hui-iframe-card-editor"); await import(/* webpackChunkName: "hui-iframe-card-editor" */ "../editor/config-elements/hui-iframe-card-editor");
return document.createElement("hui-iframe-card-editor"); return document.createElement("hui-iframe-card-editor");
} }
public static getStubConfig(): object { public static getStubConfig(): object {

View File

@ -48,7 +48,7 @@ export interface Config extends LovelaceCardConfig {
export class HuiLightCard extends hassLocalizeLitMixin(LitElement) export class HuiLightCard extends hassLocalizeLitMixin(LitElement)
implements LovelaceCard { implements LovelaceCard {
public static async getConfigElement(): Promise<LovelaceCardEditor> { public static async getConfigElement(): Promise<LovelaceCardEditor> {
await import("../editor/config-elements/hui-light-card-editor"); await import(/* webpackChunkName: "hui-light-card-editor" */ "../editor/config-elements/hui-light-card-editor");
return document.createElement("hui-light-card-editor"); return document.createElement("hui-light-card-editor");
} }
public static getStubConfig(): object { public static getStubConfig(): object {

View File

@ -15,7 +15,7 @@ export interface Config extends LovelaceCardConfig {
export class HuiMarkdownCard extends LitElement implements LovelaceCard { export class HuiMarkdownCard extends LitElement implements LovelaceCard {
public static async getConfigElement(): Promise<LovelaceCardEditor> { public static async getConfigElement(): Promise<LovelaceCardEditor> {
await import("../editor/config-elements/hui-markdown-card-editor"); await import(/* webpackChunkName: "hui-markdown-card-editor" */ "../editor/config-elements/hui-markdown-card-editor");
return document.createElement("hui-markdown-card-editor"); return document.createElement("hui-markdown-card-editor");
} }
public static getStubConfig(): object { public static getStubConfig(): object {

View File

@ -9,7 +9,7 @@ export const Config = {
class HuiMediaControlCard extends LegacyWrapperCard { class HuiMediaControlCard extends LegacyWrapperCard {
static async getConfigElement() { static async getConfigElement() {
await import("../editor/config-elements/hui-media-control-card-editor"); await import(/* webpackChunkName: "hui-media-control-card-editor" */ "../editor/config-elements/hui-media-control-card-editor");
return document.createElement("hui-media-control-card-editor"); return document.createElement("hui-media-control-card-editor");
} }

View File

@ -10,7 +10,7 @@ export const Config = {
class HuiPlantStatusCard extends LegacyWrapperCard { class HuiPlantStatusCard extends LegacyWrapperCard {
static async getConfigElement() { static async getConfigElement() {
await import("../editor/config-elements/hui-plant-status-card-editor"); await import(/* webpackChunkName: "hui-plant-status-card-editor" */ "../editor/config-elements/hui-plant-status-card-editor");
return document.createElement("hui-plant-status-card-editor"); return document.createElement("hui-plant-status-card-editor");
} }

View File

@ -146,7 +146,7 @@ export interface Config extends LovelaceCardConfig {
class HuiSensorCard extends LitElement implements LovelaceCard { class HuiSensorCard extends LitElement implements LovelaceCard {
public static async getConfigElement(): Promise<LovelaceCardEditor> { public static async getConfigElement(): Promise<LovelaceCardEditor> {
await import("../editor/config-elements/hui-sensor-card-editor"); await import(/* webpackChunkName: "hui-sensor-card-editor" */ "../editor/config-elements/hui-sensor-card-editor");
return document.createElement("hui-sensor-card-editor"); return document.createElement("hui-sensor-card-editor");
} }

View File

@ -26,7 +26,7 @@ export interface Config extends LovelaceCardConfig {
class HuiShoppingListCard extends hassLocalizeLitMixin(LitElement) class HuiShoppingListCard extends hassLocalizeLitMixin(LitElement)
implements LovelaceCard { implements LovelaceCard {
public static async getConfigElement(): Promise<LovelaceCardEditor> { public static async getConfigElement(): Promise<LovelaceCardEditor> {
await import("../editor/config-elements/hui-shopping-list-editor"); await import(/* webpackChunkName: "hui-shopping-list-editor" */ "../editor/config-elements/hui-shopping-list-editor");
return document.createElement("hui-shopping-list-card-editor"); return document.createElement("hui-shopping-list-card-editor");
} }
public static getStubConfig(): object { public static getStubConfig(): object {

View File

@ -58,7 +58,7 @@ function formatTemp(temps: string[]): string {
export class HuiThermostatCard extends hassLocalizeLitMixin(LitElement) export class HuiThermostatCard extends hassLocalizeLitMixin(LitElement)
implements LovelaceCard { implements LovelaceCard {
public static async getConfigElement(): Promise<LovelaceCardEditor> { public static async getConfigElement(): Promise<LovelaceCardEditor> {
await import("../editor/config-elements/hui-thermostat-card-editor"); await import(/* webpackChunkName: "hui-thermostat-card-editor" */ "../editor/config-elements/hui-thermostat-card-editor");
return document.createElement("hui-thermostat-card-editor"); return document.createElement("hui-thermostat-card-editor");
} }

View File

@ -173,11 +173,15 @@ export class HuiAlarmPanelCardEditor extends hassLocalizeLitMixin(LitElement)
return; return;
} }
if (target.configValue) { if (target.configValue) {
if (target.value === "") {
delete this._config[target.configValue!];
} else {
this._config = { this._config = {
...this._config, ...this._config,
[target.configValue!]: target.value, [target.configValue!]: target.value,
}; };
} }
}
fireEvent(this, "config-changed", { config: this._config }); fireEvent(this, "config-changed", { config: this._config });
} }
} }

View File

@ -115,12 +115,16 @@ export class HuiEntitiesCardEditor extends hassLocalizeLitMixin(LitElement)
this._config.entities = ev.detail.entities; this._config.entities = ev.detail.entities;
this._configEntities = processEditorEntities(this._config.entities); this._configEntities = processEditorEntities(this._config.entities);
} else if (target.configValue) { } else if (target.configValue) {
if (target.value === "") {
delete this._config[target.configValue!];
} else {
this._config = { this._config = {
...this._config, ...this._config,
[target.configValue]: [target.configValue]:
target.checked !== undefined ? target.checked : target.value, target.checked !== undefined ? target.checked : target.value,
}; };
} }
}
fireEvent(this, "config-changed", { config: this._config }); fireEvent(this, "config-changed", { config: this._config });
} }

View File

@ -218,12 +218,19 @@ export class HuiGaugeCardEditor extends hassLocalizeLitMixin(LitElement)
const target = ev.target! as EditorTarget; const target = ev.target! as EditorTarget;
if (target.configValue) { if (target.configValue) {
if (
target.value === "" ||
(target.type === "number" && isNaN(Number(target.value)))
) {
delete this._config[target.configValue!];
} else {
let value: any = target.value; let value: any = target.value;
if (target.type === "number") { if (target.type === "number") {
value = Number(value); value = Number(value);
} }
this._config = { ...this._config, [target.configValue!]: value }; this._config = { ...this._config, [target.configValue!]: value };
} }
}
fireEvent(this, "config-changed", { config: this._config }); fireEvent(this, "config-changed", { config: this._config });
} }
} }

View File

@ -64,8 +64,8 @@ export class HuiGlanceCardEditor extends hassLocalizeLitMixin(LitElement)
return this._config!.theme || "Backend-selected"; return this._config!.theme || "Backend-selected";
} }
get _columns(): string { get _columns(): number {
return this._config!.columns ? String(this._config!.columns) : ""; return this._config!.columns || NaN;
} }
protected render(): TemplateResult { protected render(): TemplateResult {
@ -126,13 +126,19 @@ export class HuiGlanceCardEditor extends hassLocalizeLitMixin(LitElement)
} }
const target = ev.target! as EditorTarget; const target = ev.target! as EditorTarget;
if (this[`_${target.configValue}`] === target.value) { if (target.configValue && this[`_${target.configValue}`] === target.value) {
return; return;
} }
if (ev.detail && ev.detail.entities) { if (ev.detail && ev.detail.entities) {
this._config.entities = ev.detail.entities; this._config.entities = ev.detail.entities;
this._configEntities = processEditorEntities(this._config.entities); this._configEntities = processEditorEntities(this._config.entities);
} else if (target.configValue) { } else if (target.configValue) {
if (
target.value === "" ||
(target.type === "number" && isNaN(Number(target.value)))
) {
delete this._config[target.configValue!];
} else {
let value: any = target.value; let value: any = target.value;
if (target.type === "number") { if (target.type === "number") {
value = Number(value); value = Number(value);
@ -143,6 +149,7 @@ export class HuiGlanceCardEditor extends hassLocalizeLitMixin(LitElement)
target.checked !== undefined ? target.checked : value, target.checked !== undefined ? target.checked : value,
}; };
} }
}
fireEvent(this, "config-changed", { config: this._config }); fireEvent(this, "config-changed", { config: this._config });
} }
} }

View File

@ -92,8 +92,12 @@ export class HuiIframeCardEditor extends hassLocalizeLitMixin(LitElement)
return; return;
} }
if (target.configValue) { if (target.configValue) {
if (target.value === "") {
delete this._config[target.configValue!];
} else {
this._config = { ...this._config, [target.configValue!]: value }; this._config = { ...this._config, [target.configValue!]: value };
} }
}
fireEvent(this, "config-changed", { config: this._config }); fireEvent(this, "config-changed", { config: this._config });
} }
} }

View File

@ -91,11 +91,15 @@ export class HuiLightCardEditor extends hassLocalizeLitMixin(LitElement)
return; return;
} }
if (target.configValue) { if (target.configValue) {
if (target.value === "") {
delete this._config[target.configValue!];
} else {
this._config = { this._config = {
...this._config, ...this._config,
[target.configValue!]: target.value, [target.configValue!]: target.value,
}; };
} }
}
fireEvent(this, "config-changed", { config: this._config }); fireEvent(this, "config-changed", { config: this._config });
} }
} }

View File

@ -77,11 +77,15 @@ export class HuiMarkdownCardEditor extends hassLocalizeLitMixin(LitElement)
return; return;
} }
if (target.configValue) { if (target.configValue) {
if (target.value === "") {
delete this._config[target.configValue!];
} else {
this._config = { this._config = {
...this._config, ...this._config,
[target.configValue!]: target.value, [target.configValue!]: target.value,
}; };
} }
}
fireEvent(this, "config-changed", { config: this._config }); fireEvent(this, "config-changed", { config: this._config });
} }
} }

View File

@ -62,11 +62,15 @@ export class HuiMediaControlCardEditor extends hassLocalizeLitMixin(LitElement)
return; return;
} }
if (target.configValue) { if (target.configValue) {
if (target.value === "") {
delete this._config[target.configValue!];
} else {
this._config = { this._config = {
...this._config, ...this._config,
[target.configValue!]: target.value, [target.configValue!]: target.value,
}; };
} }
}
fireEvent(this, "config-changed", { config: this._config }); fireEvent(this, "config-changed", { config: this._config });
} }
} }

View File

@ -79,11 +79,15 @@ export class HuiPlantStatusCardEditor extends hassLocalizeLitMixin(LitElement)
return; return;
} }
if (target.configValue) { if (target.configValue) {
if (target.value === "") {
delete this._config[target.configValue!];
} else {
this._config = { this._config = {
...this._config, ...this._config,
[target.configValue!]: target.value, [target.configValue!]: target.value,
}; };
} }
}
fireEvent(this, "config-changed", { config: this._config }); fireEvent(this, "config-changed", { config: this._config });
} }
} }

View File

@ -171,14 +171,18 @@ export class HuiSensorCardEditor extends hassLocalizeLitMixin(LitElement)
return; return;
} }
if (target.configValue) { if (target.configValue) {
if (
target.value === "" ||
(target.type === "number" && isNaN(Number(target.value)))
) {
delete this._config[target.configValue!];
} else {
let value: any = target.value; let value: any = target.value;
if (target.type === "number") { if (target.type === "number") {
value = Number(value); value = Number(value);
} }
this._config = { this._config = { ...this._config, [target.configValue!]: value };
...this._config, }
[target.configValue!]: value,
};
} }
fireEvent(this, "config-changed", { config: this._config }); fireEvent(this, "config-changed", { config: this._config });
} }

View File

@ -60,11 +60,15 @@ export class HuiShoppingListEditor extends hassLocalizeLitMixin(LitElement)
return; return;
} }
if (target.configValue) { if (target.configValue) {
if (target.value === "") {
delete this._config[target.configValue!];
} else {
this._config = { this._config = {
...this._config, ...this._config,
[target.configValue!]: target.value, [target.configValue!]: target.value,
}; };
} }
}
fireEvent(this, "config-changed", { config: this._config }); fireEvent(this, "config-changed", { config: this._config });
} }
} }

View File

@ -91,8 +91,12 @@ export class HuiThermostatCardEditor extends hassLocalizeLitMixin(LitElement)
return; return;
} }
if (target.configValue) { if (target.configValue) {
if (target.value === "") {
delete this._config[target.configValue!];
} else {
this._config = { ...this._config, [target.configValue!]: target.value }; this._config = { ...this._config, [target.configValue!]: target.value };
} }
}
fireEvent(this, "config-changed", { config: this._config }); fireEvent(this, "config-changed", { config: this._config });
} }
} }