Skip to content

Commit

Permalink
Merge pull request #663 from timdreier/main
Browse files Browse the repository at this point in the history
feat: added option to navigate from entities
  • Loading branch information
flixlix authored Aug 26, 2024
2 parents b45baae + d119f3b commit 766bd8f
Show file tree
Hide file tree
Showing 40 changed files with 5,287 additions and 4,133 deletions.
8,996 changes: 4,961 additions & 4,035 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

40 changes: 20 additions & 20 deletions src/components/battery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,33 @@ export const batteryElement = (
return html`<div class="circle-container battery">
<div
class="circle"
@click=${(e: { stopPropagation: () => void }) => {
@click=${(e: { stopPropagation: () => void; target: HTMLElement }) => {
const target = entities.battery?.state_of_charge!
? entities.battery?.state_of_charge!
: typeof entities.battery?.entity === "string"
? entities.battery?.entity!
: entities.battery?.entity!.production;
main.openDetails(e, target);
main.openDetails(e, entities.battery?.tap_action, target);
}}
@keyDown=${(e: { key: string; stopPropagation: () => void }) => {
@keyDown=${(e: { key: string; stopPropagation: () => void; target: HTMLElement }) => {
if (e.key === "Enter") {
const target = entities.battery?.state_of_charge!
? entities.battery?.state_of_charge!
: typeof entities.battery!.entity === "string"
? entities.battery!.entity!
: entities.battery!.entity!.production;
main.openDetails(e, target);
main.openDetails(e, entities.battery?.tap_action, target);
}
}}
>
${battery.state_of_charge.state !== null && entities.battery?.show_state_of_charge !== false
? html` <span
@click=${(e: { stopPropagation: () => void }) => {
main.openDetails(e, entities.battery?.state_of_charge!);
@click=${(e: { stopPropagation: () => void; target: HTMLElement }) => {
main.openDetails(e, entities.battery?.tap_action, entities.battery?.state_of_charge!);
}}
@keyDown=${(e: { key: string; stopPropagation: () => void }) => {
@keyDown=${(e: { key: string; stopPropagation: () => void; target: HTMLElement }) => {
if (e.key === "Enter") {
main.openDetails(e, entities.battery?.state_of_charge!);
main.openDetails(e, entities.battery?.tap_action, entities.battery?.state_of_charge!);
}
}}
id="battery-state-of-charge-text"
Expand All @@ -61,12 +61,12 @@ export const batteryElement = (
? html` <ha-icon
id="battery-icon"
.icon=${battery.icon}
@click=${(e: { stopPropagation: () => void }) => {
main.openDetails(e, entities.battery?.state_of_charge!);
@click=${(e: { stopPropagation: () => void; target: HTMLElement }) => {
main.openDetails(e, entities.battery?.tap_action, entities.battery?.state_of_charge!);
}}
@keyDown=${(e: { key: string; stopPropagation: () => void }) => {
@keyDown=${(e: { key: string; stopPropagation: () => void; target: HTMLElement }) => {
if (e.key === "Enter") {
main.openDetails(e, entities.battery?.state_of_charge!);
main.openDetails(e, entities.battery?.tap_action, entities.battery?.state_of_charge!);
}
}}
/>`
Expand All @@ -77,16 +77,16 @@ export const batteryElement = (
(entities.battery?.display_state === "one_way" && battery.state.toBattery !== 0)
? html`<span
class="battery-in"
@click=${(e: { stopPropagation: () => void }) => {
@click=${(e: { stopPropagation: () => void; target: HTMLElement }) => {
const target = typeof entities.battery!.entity === "string" ? entities.battery!.entity! : entities.battery!.entity!.production!;
main.openDetails(e, target);
main.openDetails(e, entities.battery?.tap_action, target);
}}
@keyDown=${(e: { key: string; stopPropagation: () => void }) => {
@keyDown=${(e: { key: string; stopPropagation: () => void; target: HTMLElement }) => {
if (e.key === "Enter") {
const target = typeof entities.battery!.entity === "string" ? entities.battery!.entity! : entities.battery!.entity!.production!;
main.openDetails(e, target);
main.openDetails(e, entities.battery?.tap_action, target);
}
}}
>
Expand All @@ -105,16 +105,16 @@ export const batteryElement = (
(entities.battery?.display_state === "one_way" && (battery.state.toBattery === 0 || battery.state.fromBattery !== 0))
? html`<span
class="battery-out"
@click=${(e: { stopPropagation: () => void }) => {
@click=${(e: { stopPropagation: () => void; target: HTMLElement }) => {
const target = typeof entities.battery!.entity === "string" ? entities.battery!.entity! : entities.battery!.entity!.consumption!;
main.openDetails(e, target);
main.openDetails(e, entities.battery?.tap_action, target);
}}
@keyDown=${(e: { key: string; stopPropagation: () => void }) => {
@keyDown=${(e: { key: string; stopPropagation: () => void; target: HTMLElement }) => {
if (e.key === "Enter") {
const target = typeof entities.battery!.entity === "string" ? entities.battery!.entity! : entities.battery!.entity!.consumption!;
main.openDetails(e, target);
main.openDetails(e, entities.battery?.tap_action, target);
}
}}
>
Expand Down
24 changes: 12 additions & 12 deletions src/components/grid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ export const gridElement = (
return html`<div class="circle-container grid">
<div
class="circle"
@click=${(e: { stopPropagation: () => void }) => {
@click=${(e: { stopPropagation: () => void; target: HTMLElement }) => {
const outageTarget = grid.powerOutage?.entityGenerator ?? entities.grid?.power_outage?.entity;
const target =
grid.powerOutage?.isOutage && outageTarget
? outageTarget
: typeof entities.grid!.entity === "string"
? entities.grid!.entity
: entities.grid!.entity.consumption!;
main.openDetails(e, target);
main.openDetails(e, entities.grid?.tap_action, target);
}}
@keyDown=${(e: { key: string; stopPropagation: () => void }) => {
@keyDown=${(e: { key: string; stopPropagation: () => void; target: HTMLElement }) => {
if (e.key === "Enter") {
const outageTarget = grid.powerOutage?.entityGenerator ?? entities.grid?.power_outage?.entity;
const target =
Expand All @@ -32,7 +32,7 @@ export const gridElement = (
: typeof entities.grid!.entity === "string"
? entities.grid!.entity
: entities.grid!.entity.consumption!;
main.openDetails(e, target);
main.openDetails(e, entities.grid?.tap_action, target);
}
}}
>
Expand All @@ -46,14 +46,14 @@ export const gridElement = (
!grid.powerOutage.isOutage
? html`<span
class="return"
@click=${(e: { stopPropagation: () => void }) => {
@click=${(e: { stopPropagation: () => void; target: HTMLElement }) => {
const target = typeof entities.grid!.entity === "string" ? entities.grid!.entity : entities.grid!.entity.production!;
main.openDetails(e, target);
main.openDetails(e, entities.grid?.tap_action, target);
}}
@keyDown=${(e: { key: string; stopPropagation: () => void }) => {
@keyDown=${(e: { key: string; stopPropagation: () => void; target: HTMLElement }) => {
if (e.key === "Enter") {
const target = typeof entities.grid!.entity === "string" ? entities.grid!.entity : entities.grid!.entity.production!;
main.openDetails(e, target);
main.openDetails(e, entities.grid?.tap_action, target);
}
}}
>
Expand All @@ -76,14 +76,14 @@ export const gridElement = (
(grid.powerOutage.isOutage && !!grid.powerOutage.entityGenerator)
? html` <span
class="consumption"
@click=${(e: { stopPropagation: () => void }) => {
@click=${(e: { stopPropagation: () => void; target: HTMLElement }) => {
const target = typeof entities.grid!.entity === "string" ? entities.grid!.entity : entities.grid!.entity.consumption!;
main.openDetails(e, target);
main.openDetails(e, entities.grid?.tap_action, target);
}}
@keyDown=${(e: { key: string; stopPropagation: () => void }) => {
@keyDown=${(e: { key: string; stopPropagation: () => void; target: HTMLElement }) => {
if (e.key === "Enter") {
const target = typeof entities.grid!.entity === "string" ? entities.grid!.entity : entities.grid!.entity.consumption!;
main.openDetails(e, target);
main.openDetails(e, entities.grid?.tap_action, target);
}
}}
>
Expand Down
8 changes: 4 additions & 4 deletions src/components/home.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ export const homeElement = (
<div
class="circle"
id="home-circle"
@click=${(e: { stopPropagation: () => void }) => {
main.openDetails(e, entities.home?.entity);
@click=${(e: { stopPropagation: () => void; target: HTMLElement }) => {
main.openDetails(e, entities.home?.tap_action, entities.home?.entity);
}}
@keyDown=${(e: { key: string; stopPropagation: () => void }) => {
@keyDown=${(e: { key: string; stopPropagation: () => void; target: HTMLElement }) => {
if (e.key === "Enter") {
main.openDetails(e, entities.home?.entity);
main.openDetails(e, entities.home?.tap_action, entities.home?.entity);
}
}}
>
Expand Down
8 changes: 4 additions & 4 deletions src/components/individualLeftBottomElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ export const individualLeftBottomElement = (
: html` <svg width="80" height="30"></svg> `}
<div
class="circle"
@click=${(e: { stopPropagation: () => void }) => {
main.openDetails(e, individualObj?.entity);
@click=${(e: { stopPropagation: () => void; target: HTMLElement }) => {
main.openDetails(e, individualObj?.field?.tap_action, individualObj?.entity);
}}
@keyDown=${(e: { key: string; stopPropagation: () => void }) => {
@keyDown=${(e: { key: string; stopPropagation: () => void; target: HTMLElement }) => {
if (e.key === "Enter") {
main.openDetails(e, individualObj?.entity);
main.openDetails(e, individualObj?.field?.tap_action, individualObj?.entity);
}
}}
>
Expand Down
8 changes: 4 additions & 4 deletions src/components/individualLeftTopElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ export const individualLeftTopElement = (
<span class="label">${individualObj.name}</span>
<div
class="circle"
@click=${(e: { stopPropagation: () => void }) => {
main.openDetails(e, individualObj?.entity);
@click=${(e: { stopPropagation: () => void; target: HTMLElement }) => {
main.openDetails(e, individualObj?.field?.tap_action, individualObj?.entity);
}}
@keyDown=${(e: { key: string; stopPropagation: () => void }) => {
@keyDown=${(e: { key: string; stopPropagation: () => void; target: HTMLElement }) => {
if (e.key === "Enter") {
main.openDetails(e, individualObj?.entity);
main.openDetails(e, individualObj?.field?.tap_action, individualObj?.entity);
}
}}
>
Expand Down
8 changes: 4 additions & 4 deletions src/components/individualRightBottomElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ export const individualRightBottomElement = (
return html`<div class="circle-container individual-bottom individual-right individual-right-bottom">
<div
class="circle"
@click=${(e: { stopPropagation: () => void }) => {
main.openDetails(e, individualObj?.entity);
@click=${(e: { stopPropagation: () => void; target: HTMLElement }) => {
main.openDetails(e, individualObj?.field?.tap_action, individualObj?.entity);
}}
@keyDown=${(e: { key: string; stopPropagation: () => void }) => {
@keyDown=${(e: { key: string; stopPropagation: () => void; target: HTMLElement }) => {
if (e.key === "Enter") {
main.openDetails(e, individualObj?.entity);
main.openDetails(e, individualObj?.field?.tap_action, individualObj?.entity);
}
}}
>
Expand Down
8 changes: 4 additions & 4 deletions src/components/individualRightTopElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ export const individualRightTopElement = (
<span class="label">${individualObj.name}</span>
<div
class="circle"
@click=${(e: { stopPropagation: () => void }) => {
main.openDetails(e, individualObj?.entity);
@click=${(e: { stopPropagation: () => void; target: HTMLElement }) => {
main.openDetails(e, individualObj?.field?.tap_action, individualObj?.entity);
}}
@keyDown=${(e: { key: string; stopPropagation: () => void }) => {
@keyDown=${(e: { key: string; stopPropagation: () => void; target: HTMLElement }) => {
if (e.key === "Enter") {
main.openDetails(e, individualObj?.entity);
main.openDetails(e, individualObj?.field?.tap_action, individualObj?.entity);
}
}}
>
Expand Down
8 changes: 4 additions & 4 deletions src/components/nonFossil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ export const nonFossilElement = (
<span class="label">${nonFossil.name}</span>
<div
class="circle"
@click=${(e: { stopPropagation: () => void }) => {
main.openDetails(e, entities.fossil_fuel_percentage?.entity);
@click=${(e: { stopPropagation: () => void; target: HTMLElement }) => {
main.openDetails(e, entities.fossil_fuel_percentage?.tap_action, entities.fossil_fuel_percentage?.entity);
}}
@keyDown=${(e: { key: string; stopPropagation: () => void }) => {
@keyDown=${(e: { key: string; stopPropagation: () => void; target: HTMLElement }) => {
if (e.key === "Enter") {
main.openDetails(e, entities.fossil_fuel_percentage?.entity);
main.openDetails(e, entities.fossil_fuel_percentage?.tap_action, entities.fossil_fuel_percentage?.entity);
}
}}
>
Expand Down
8 changes: 4 additions & 4 deletions src/components/solar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ export const solarElement = (
<span class="label">${solar.name}</span>
<div
class="circle"
@click=${(e: { stopPropagation: () => void }) => {
main.openDetails(e, solar.entity);
@click=${(e: { stopPropagation: () => void; target: HTMLElement }) => {
main.openDetails(e, solar.tap_action, solar.entity);
}}
@keyDown=${(e: { key: string; stopPropagation: () => void }) => {
@keyDown=${(e: { key: string; stopPropagation: () => void; target: HTMLElement }) => {
if (e.key === "Enter") {
main.openDetails(e, solar.entity);
main.openDetails(e, solar.tap_action, solar.entity);
}
}}
>
Expand Down
13 changes: 7 additions & 6 deletions src/components/spans/baseSecondarySpan.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { html } from "lit";
import { PowerFlowCardPlusConfig } from "../../power-flow-card-plus-config";
import { PowerFlowCardPlus } from "../../power-flow-card-plus";
import { offlineStr } from "../../type";
import { ActionConfig } from "custom-card-helpers";

type BaseSecondarySpan = {
main: PowerFlowCardPlus;
Expand All @@ -10,19 +10,20 @@ type BaseSecondarySpan = {
value?: string;
entityId?: string;
icon?: string;
tap_action?: ActionConfig;
};

export const baseSecondarySpan = ({ main, className, template, value, entityId, icon }: BaseSecondarySpan) => {
export const baseSecondarySpan = ({ main, className, template, value, entityId, icon, tap_action }: BaseSecondarySpan) => {
if (value && offlineStr.includes(value)) return html``;
if (value || template) {
return html`<span
class="secondary-info ${className}"
@click=${(e: { stopPropagation: () => void }) => {
main.openDetails(e, entityId);
@click=${(e: { stopPropagation: () => void; key?: string | undefined; target: HTMLElement }) => {
main.openDetails(e, tap_action, entityId);
}}
@keyDown=${(e: { key: string; stopPropagation: () => void }) => {
@keyDown=${(e: { stopPropagation: () => void; key?: string | undefined; target: HTMLElement }) => {
if (e.key === "Enter") {
main.openDetails(e, entityId);
main.openDetails(e, tap_action, entityId);
}
}}
>
Expand Down
4 changes: 3 additions & 1 deletion src/components/spans/generalSecondarySpan.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { html } from "lit";
import { baseSecondarySpan } from "./baseSecondarySpan";
import { HomeAssistant } from "custom-card-helpers";
import { ActionConfig, HomeAssistant } from "custom-card-helpers";
import { displayValue } from "../../utils/displayValue";
import { PowerFlowCardPlus } from "../../power-flow-card-plus";
import { TemplatesObj } from "../../type";
Expand All @@ -22,6 +22,7 @@ export const generalSecondarySpan = (
unit_white_space: boolean | undefined;
decimals: number | undefined;
accept_negative: boolean | undefined;
tap_action?: ActionConfig | undefined;
};
},
key: string
Expand All @@ -39,6 +40,7 @@ export const generalSecondarySpan = (
accept_negative: field.secondary.accept_negative,
watt_threshold: config.watt_threshold,
}),
tap_action: field.secondary.tap_action,
template: templatesObj[`${key}Secondary`],
})}`
: ""}`;
Expand Down
1 change: 1 addition & 0 deletions src/components/spans/individualSecondarySpan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export const individualSecondarySpan = (
icon: individual?.secondary?.icon || undefined,
value,
template: templatesObj.individual[index] || undefined,
tap_action: individual?.secondary?.tap_action || undefined,
})}`
: ""}`;
};
Loading

0 comments on commit 766bd8f

Please sign in to comment.