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

View File

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