feat: add floating power cards for all powered furniture
This commit is contained in:
1 parent
6bd3598779
commit
4967dd7950
19 files changed
+1125
-810
No files matched your search
@@ -22,6 +22,7 @@ import type { RoomClimateCard } from "./room-climate-card.ts";
|
||||
import { fromCelsius, tempUnit } from "../devices.ts";
|
||||
import { trendButton } from "../components/trend-button.ts";
|
||||
import { loggedEntities } from "../trend-data.ts";
|
||||
import type { FurniturePowerCard } from "./furniture-power-card.ts";
|
||||
|
||||
export interface HouseCard {
|
||||
kind: "house";
|
||||
@@ -64,7 +65,7 @@ export interface HeatPumpCard {
|
||||
pump: HeatPumpInfo;
|
||||
}
|
||||
|
||||
export type LiveCard = HouseCard | CarCard | MediaCard | PrinterCard | HeatPumpCard | RoomClimateCard;
|
||||
export type LiveCard = HouseCard | CarCard | MediaCard | PrinterCard | HeatPumpCard | RoomClimateCard | FurniturePowerCard;
|
||||
|
||||
/** A button on a card was pressed: the 3D view calls the service (with extra data such as the volume). */
|
||||
export type LiveCardAction = (domain: string, service: string, entity: string, data?: Record<string, unknown>) => void;
|
||||
@@ -327,14 +328,26 @@ function roomClimateCard(hass: HomeAssistant | undefined, c: RoomClimateCard, i:
|
||||
</div>`;
|
||||
}
|
||||
|
||||
function furniturePowerCard(hass: HomeAssistant | undefined, c: FurniturePowerCard, i: number): TemplateResult {
|
||||
const power = c.power === null ? "–" : `${c.power < 0 ? "−" : ""}${watts(hass, c.power)}`;
|
||||
return html`<div class="live-card live-card-power" data-i=${i} data-furniture=${c.id} role="group" aria-label=${c.name}>
|
||||
<div class="live-power-name">${c.name}</div><div class="live-row"><span aria-hidden="true">⚡</span><b>${power}</b>${trendButton(hass, [c.powerEntity], c.name)}</div>
|
||||
</div>`;
|
||||
}
|
||||
|
||||
export function renderLhCards(hass: HomeAssistant | undefined, cards: readonly LiveCard[], act: LiveCardAction, fold?: LiveCardFold, climateOnly = false): TemplateResult | typeof nothing {
|
||||
if (!cards.length) return nothing;
|
||||
return html`<div class="live-cards">
|
||||
${cards.map((c, i) => (c.kind === "roomclimate" ? roomClimateCard(hass, c, i) : climateOnly ? nothing : c.kind === "house" ? houseCard(hass, c, i, fold) : c.kind === "car" ? carCard(hass, c, i, act) : c.kind === "printer" ? printerCard(hass, c, i) : c.kind === "heatpump" ? heatPumpCard(hass, c, i) : mediaCard(hass, c, i, act)))}
|
||||
${cards.map((c, i) => (c.kind === "roomclimate" ? roomClimateCard(hass, c, i) : c.kind === "power" ? furniturePowerCard(hass, c, i) : climateOnly ? nothing : c.kind === "house" ? houseCard(hass, c, i, fold) : c.kind === "car" ? carCard(hass, c, i, act) : c.kind === "printer" ? printerCard(hass, c, i) : c.kind === "heatpump" ? heatPumpCard(hass, c, i) : mediaCard(hass, c, i, act)))}
|
||||
</div>`;
|
||||
}
|
||||
|
||||
export const liveCardStyles = css`
|
||||
.live-card.live-card-power { display:grid; gap:4px; min-width:90px; max-width:220px; box-sizing:border-box; }
|
||||
.live-power-name { font-size:11px; color:var(--nf-muted); overflow:hidden; text-overflow:ellipsis; }
|
||||
.live-card-power .live-row { align-items:center; gap:6px; }
|
||||
.live-card-power .live-row b { margin-left:auto; color:color-mix(in srgb,#ffca8a 80%,var(--nf-text)); font-variant-numeric:tabular-nums; }
|
||||
.live-card-power nf-trend-button { margin-left:0; }
|
||||
.live-cards {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
|
||||
Reference in new issue
Block a user