Add scenes and scripts as buttons in footer of area cards (#10673)

* Add scenes and scripts as chips in footer of area cards

* Remove unused chips config type

* Update src/panels/lovelace/common/generate-lovelace-config.ts

Co-authored-by: Zack Barett <arnett.zackary@gmail.com>

* Fix typing

Co-authored-by: Zack Barett <arnett.zackary@gmail.com>
This commit is contained in:
Paulus Schoutsen 2021-11-21 20:59:56 -08:00 committed by GitHub
parent 3bcf225380
commit 45efee28b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 5 deletions

View File

@ -25,6 +25,7 @@ import {
ThermostatCardConfig, ThermostatCardConfig,
} from "../cards/types"; } from "../cards/types";
import { LovelaceRowConfig } from "../entity-rows/types"; import { LovelaceRowConfig } from "../entity-rows/types";
import { ButtonsHeaderFooterConfig } from "../header-footer/types";
const HIDE_DOMAIN = new Set([ const HIDE_DOMAIN = new Set([
"automation", "automation",
@ -97,6 +98,8 @@ export const computeCards = (
? `${entityCardOptions.title} `.toLowerCase() ? `${entityCardOptions.title} `.toLowerCase()
: undefined; : undefined;
const footerEntities: ButtonsHeaderFooterConfig["entities"] = [];
for (const [entityId, stateObj] of states) { for (const [entityId, stateObj] of states) {
const domain = computeDomain(entityId); const domain = computeDomain(entityId);
@ -143,6 +146,12 @@ export const computeCards = (
show_forecast: false, show_forecast: false,
}; };
cards.push(cardConfig); cards.push(cardConfig);
} else if (domain === "scene" || domain === "script") {
footerEntities.push({
entity: entityId,
show_icon: true,
show_name: true,
});
} else if ( } else if (
domain === "sensor" && domain === "sensor" &&
stateObj?.attributes.device_class === SENSOR_DEVICE_CLASS_BATTERY stateObj?.attributes.device_class === SENSOR_DEVICE_CLASS_BATTERY
@ -168,12 +177,19 @@ export const computeCards = (
} }
} }
if (entities.length > 0) { if (entities.length > 0 || footerEntities.length > 0) {
cards.unshift({ const card: EntitiesCardConfig = {
type: "entities", type: "entities",
entities, entities,
...entityCardOptions, ...entityCardOptions,
}); };
if (footerEntities.length > 0) {
card.footer = {
type: "buttons",
entities: footerEntities,
} as ButtonsHeaderFooterConfig;
}
cards.unshift(card);
} }
if (cards.length < 2) { if (cards.length < 2) {

View File

@ -1,15 +1,17 @@
import { ActionConfig } from "../../../data/lovelace"; import { ActionConfig } from "../../../data/lovelace";
import { EntityConfig } from "../entity-rows/types"; import { EntitiesCardEntityConfig } from "../cards/types";
export interface LovelaceHeaderFooterConfig { export interface LovelaceHeaderFooterConfig {
type: string; type: string;
} }
export interface ButtonsHeaderFooterConfig extends LovelaceHeaderFooterConfig { export interface ButtonsHeaderFooterConfig extends LovelaceHeaderFooterConfig {
entities: Array<string | EntityConfig>; type: "buttons";
entities: Array<string | EntitiesCardEntityConfig>;
} }
export interface GraphHeaderFooterConfig extends LovelaceHeaderFooterConfig { export interface GraphHeaderFooterConfig extends LovelaceHeaderFooterConfig {
type: "graph";
entity: string; entity: string;
detail?: number; detail?: number;
hours_to_show?: number; hours_to_show?: number;
@ -20,6 +22,7 @@ export interface GraphHeaderFooterConfig extends LovelaceHeaderFooterConfig {
} }
export interface PictureHeaderFooterConfig extends LovelaceHeaderFooterConfig { export interface PictureHeaderFooterConfig extends LovelaceHeaderFooterConfig {
type: "picture";
image: string; image: string;
tap_action?: ActionConfig; tap_action?: ActionConfig;
hold_action?: ActionConfig; hold_action?: ActionConfig;