mirror of
https://github.com/home-assistant/frontend.git
synced 2026-04-18 07:56:44 +01:00
Add light toggle button to home area view (#30301)
This commit is contained in:
@@ -15,6 +15,7 @@ import type {
|
|||||||
EmptyStateCardConfig,
|
EmptyStateCardConfig,
|
||||||
HeadingCardConfig,
|
HeadingCardConfig,
|
||||||
} from "../../cards/types";
|
} from "../../cards/types";
|
||||||
|
import type { ButtonHeadingBadgeConfig } from "../../heading-badges/types";
|
||||||
import { computeAreaTileCardConfig } from "../areas/helpers/areas-strategy-helper";
|
import { computeAreaTileCardConfig } from "../areas/helpers/areas-strategy-helper";
|
||||||
import {
|
import {
|
||||||
getSummaryLabel,
|
getSummaryLabel,
|
||||||
@@ -95,6 +96,15 @@ export class HomeAreaViewStrategy extends ReactiveElement {
|
|||||||
} = entitiesBySummary;
|
} = entitiesBySummary;
|
||||||
|
|
||||||
if (light.length > 0) {
|
if (light.length > 0) {
|
||||||
|
const anyOnCondition = {
|
||||||
|
condition: "or" as const,
|
||||||
|
conditions: light.map((entityId) => ({
|
||||||
|
condition: "state" as const,
|
||||||
|
entity: entityId,
|
||||||
|
state: "on",
|
||||||
|
})),
|
||||||
|
};
|
||||||
|
|
||||||
sections.push({
|
sections.push({
|
||||||
type: "grid",
|
type: "grid",
|
||||||
cards: [
|
cards: [
|
||||||
@@ -108,6 +118,40 @@ export class HomeAreaViewStrategy extends ReactiveElement {
|
|||||||
navigation_path: "/light?historyBack=1",
|
navigation_path: "/light?historyBack=1",
|
||||||
}
|
}
|
||||||
: undefined,
|
: undefined,
|
||||||
|
badges: [
|
||||||
|
{
|
||||||
|
type: "button",
|
||||||
|
icon: "mdi:power",
|
||||||
|
text: hass.localize("ui.panel.lovelace.strategy.light.off"),
|
||||||
|
tap_action: {
|
||||||
|
action: "perform-action",
|
||||||
|
perform_action: "light.turn_on",
|
||||||
|
target: {
|
||||||
|
area_id: config.area,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
visibility: [
|
||||||
|
{
|
||||||
|
condition: "not",
|
||||||
|
conditions: [anyOnCondition],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
} satisfies ButtonHeadingBadgeConfig,
|
||||||
|
{
|
||||||
|
type: "button",
|
||||||
|
icon: "mdi:power",
|
||||||
|
color: "orange",
|
||||||
|
text: hass.localize("ui.panel.lovelace.strategy.light.on"),
|
||||||
|
tap_action: {
|
||||||
|
action: "perform-action",
|
||||||
|
perform_action: "light.turn_off",
|
||||||
|
target: {
|
||||||
|
area_id: config.area,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
visibility: [anyOnCondition],
|
||||||
|
} satisfies ButtonHeadingBadgeConfig,
|
||||||
|
],
|
||||||
} satisfies HeadingCardConfig,
|
} satisfies HeadingCardConfig,
|
||||||
...light.map(computeTileCard),
|
...light.map(computeTileCard),
|
||||||
],
|
],
|
||||||
|
|||||||
Reference in New Issue
Block a user