Skip to content

Commit ce42810

Browse files
committed
fix(types): Add 'display' property to CalculatedElementDef and fix variable typing
1 parent 3c07714 commit ce42810

3 files changed

Lines changed: 33 additions & 15 deletions

File tree

dist/system-flow-card.js

Lines changed: 13 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/system-flow-card.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,15 @@ export class SystemFlowCard extends LitElement {
137137

138138
private elementValueArrows = (element: CalculatedElementDef) => html`
139139
<div class="value-row">
140-
${element.calculations.systemTotal
140+
${element.calculations.systemTotal || (element as any).display
141141
? html`
142142
${!['left', 'middle'].includes(element.position) ? this.elementArrows(element.calculations.systemTotal, element.position, this.getElementColor(element)) : null}
143-
<span style="white-space: nowrap;">${this.displayValue(element.calculations.systemTotal, element.position !== 'middle', this.getElementUnit(element), 0)}</span>
143+
<span style="white-space: nowrap;">${this.displayValue(
144+
(element as any).display !== undefined ? (element as any).display : element.calculations.systemTotal,
145+
element.position !== 'middle',
146+
this.getElementUnit(element),
147+
0
148+
)}</span>
144149
${element.position === 'left' ? this.elementArrows(element.calculations.systemTotal, element.position, this.getElementColor(element)) : null}
145150
` : null
146151
}
@@ -212,8 +217,20 @@ export class SystemFlowCard extends LitElement {
212217
systemPower *= -1;
213218
}
214219

220+
// [CUSTOM FIX] Allow overriding the system display value with a specific entity
221+
// FIX: We explicitly tell TypeScript this variable can be a 'string' or 'undefined'
222+
let systemDisplayOverride: string | undefined = undefined;
223+
224+
if ((this._config.system as any)?.override && (this._config.system as any)?.value) {
225+
const overrideEntity = this.getEntity((this._config.system as any).value);
226+
if (overrideEntity) {
227+
systemDisplayOverride = overrideEntity.state;
228+
}
229+
}
230+
215231
elements.push({
216232
value: 'system',
233+
display: systemDisplayOverride, // Now valid because we updated type.ts
217234
...(this._config.system?.unit ? { unit: this._config.system.unit } : null),
218235
icon: this._config.system?.icon || 'mdi:house',
219236
...(this._config.system?.extra ? { extra: this._config.system.extra } : null),

src/type.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export type CalculatedElementDef = ElementDef & {
2626
left?: string,
2727
right?: string
2828
},
29+
display?: string | number;
2930
calculations: {
3031
toSystem: number,
3132
fromSystem: number | null,

0 commit comments

Comments
 (0)