mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-19 15:26:36 +00:00
Tweak how scenes behave in generated lovelace (#10730)
This commit is contained in:
parent
990ad1bb67
commit
49e39644f3
@ -87,7 +87,8 @@ const splitByAreas = (
|
|||||||
|
|
||||||
export const computeCards = (
|
export const computeCards = (
|
||||||
states: Array<[string, HassEntity?]>,
|
states: Array<[string, HassEntity?]>,
|
||||||
entityCardOptions: Partial<EntitiesCardConfig>
|
entityCardOptions: Partial<EntitiesCardConfig>,
|
||||||
|
renderFooterEntities = true
|
||||||
): LovelaceCardConfig[] => {
|
): LovelaceCardConfig[] => {
|
||||||
const cards: LovelaceCardConfig[] = [];
|
const cards: LovelaceCardConfig[] = [];
|
||||||
|
|
||||||
@ -146,12 +147,28 @@ export const computeCards = (
|
|||||||
show_forecast: false,
|
show_forecast: false,
|
||||||
};
|
};
|
||||||
cards.push(cardConfig);
|
cards.push(cardConfig);
|
||||||
} else if (domain === "scene" || domain === "script") {
|
} else if (
|
||||||
footerEntities.push({
|
renderFooterEntities &&
|
||||||
|
(domain === "scene" || domain === "script")
|
||||||
|
) {
|
||||||
|
const conf: typeof footerEntities[0] = {
|
||||||
entity: entityId,
|
entity: entityId,
|
||||||
show_icon: true,
|
show_icon: true,
|
||||||
show_name: true,
|
show_name: true,
|
||||||
});
|
};
|
||||||
|
let name: string | undefined;
|
||||||
|
if (
|
||||||
|
titlePrefix &&
|
||||||
|
stateObj &&
|
||||||
|
// eslint-disable-next-line no-cond-assign
|
||||||
|
(name = stripPrefixFromEntityName(
|
||||||
|
computeStateName(stateObj),
|
||||||
|
titlePrefix
|
||||||
|
))
|
||||||
|
) {
|
||||||
|
conf.name = name;
|
||||||
|
}
|
||||||
|
footerEntities.push(conf);
|
||||||
} else if (
|
} else if (
|
||||||
domain === "sensor" &&
|
domain === "sensor" &&
|
||||||
stateObj?.attributes.device_class === SENSOR_DEVICE_CLASS_BATTERY
|
stateObj?.attributes.device_class === SENSOR_DEVICE_CLASS_BATTERY
|
||||||
@ -177,6 +194,12 @@ export const computeCards = (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If we ended up with footer entities but no normal entities,
|
||||||
|
// render the footer entities as normal entities.
|
||||||
|
if (entities.length === 0 && footerEntities.length > 0) {
|
||||||
|
return computeCards(states, entityCardOptions, false);
|
||||||
|
}
|
||||||
|
|
||||||
if (entities.length > 0 || footerEntities.length > 0) {
|
if (entities.length > 0 || footerEntities.length > 0) {
|
||||||
const card: EntitiesCardConfig = {
|
const card: EntitiesCardConfig = {
|
||||||
type: "entities",
|
type: "entities",
|
||||||
|
@ -65,6 +65,8 @@ export class HuiButtonsBase extends LitElement {
|
|||||||
:host {
|
:host {
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: space-evenly;
|
justify-content: space-evenly;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
padding: 0 8px;
|
||||||
}
|
}
|
||||||
div {
|
div {
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import { html, LitElement, TemplateResult } from "lit";
|
import { html, LitElement, TemplateResult } from "lit";
|
||||||
import { customElement, property, state } from "lit/decorators";
|
import { customElement, property, state } from "lit/decorators";
|
||||||
|
import { computeDomain } from "../../../common/entity/compute_domain";
|
||||||
import { HomeAssistant } from "../../../types";
|
import { HomeAssistant } from "../../../types";
|
||||||
import { processConfigEntities } from "../common/process-config-entities";
|
import { processConfigEntities } from "../common/process-config-entities";
|
||||||
import "../components/hui-buttons-base";
|
import "../components/hui-buttons-base";
|
||||||
@ -26,11 +27,21 @@ export class HuiButtonsHeaderFooter
|
|||||||
|
|
||||||
public setConfig(config: ButtonsHeaderFooterConfig): void {
|
public setConfig(config: ButtonsHeaderFooterConfig): void {
|
||||||
this._configEntities = processConfigEntities(config.entities).map(
|
this._configEntities = processConfigEntities(config.entities).map(
|
||||||
(entityConfig) => ({
|
(entityConfig) => {
|
||||||
|
const conf = {
|
||||||
tap_action: { action: "toggle" },
|
tap_action: { action: "toggle" },
|
||||||
hold_action: { action: "more-info" },
|
hold_action: { action: "more-info" },
|
||||||
...entityConfig,
|
...entityConfig,
|
||||||
})
|
};
|
||||||
|
if (computeDomain(entityConfig.entity) === "scene") {
|
||||||
|
conf.tap_action = {
|
||||||
|
action: "call-service",
|
||||||
|
service: "scene.turn_on",
|
||||||
|
target: { entity_id: conf.entity },
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return conf;
|
||||||
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user