diff --git a/package.json b/package.json
index 2a45ea0..be83db1 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "power-flow-card-plus",
- "version": "0.2.0-414",
+ "version": "0.2.0",
"description": "A power flow card for Home Assistant",
"keywords": [
"home-assistant",
diff --git a/src/components/battery.ts b/src/components/battery.ts
index c35944f..5e9b5cd 100644
--- a/src/components/battery.ts
+++ b/src/components/battery.ts
@@ -1,10 +1,11 @@
import { html } from "lit";
import { PowerFlowCardPlus } from "../power-flow-card-plus";
-import { ConfigEntities } from "../power-flow-card-plus-config";
+import { ConfigEntities, PowerFlowCardPlusConfig } from "../power-flow-card-plus-config";
import { displayValue } from "../utils/displayValue";
export const batteryElement = (
main: PowerFlowCardPlus,
+ config: PowerFlowCardPlusConfig,
{
battery,
entities,
@@ -52,7 +53,9 @@ export const batteryElement = (
battery.state_of_charge.state,
battery.state_of_charge.unit,
battery.state_of_charge.unit_white_space,
- battery.state_of_charge.decimals
+ battery.state_of_charge.decimals,
+ undefined,
+ config.watt_threshold
)}
`
: null}
@@ -87,7 +90,15 @@ export const batteryElement = (
}}
>
- ${displayValue(main.hass, battery.state.toBattery)}`
: ""}
${entities.battery?.display_state === "two_way" ||
@@ -110,7 +121,15 @@ export const batteryElement = (
}}
>
- ${displayValue(main.hass, battery.state.fromBattery)}`
: ""}
diff --git a/src/components/grid.ts b/src/components/grid.ts
index 04feaaa..2eedecb 100644
--- a/src/components/grid.ts
+++ b/src/components/grid.ts
@@ -3,10 +3,11 @@ import { PowerFlowCardPlus } from "../power-flow-card-plus";
import { displayValue } from "../utils/displayValue";
import { generalSecondarySpan } from "./spans/generalSecondarySpan";
import { TemplatesObj } from "../type";
-import { ConfigEntities } from "../power-flow-card-plus-config";
+import { ConfigEntities, PowerFlowCardPlusConfig } from "../power-flow-card-plus-config";
export const gridElement = (
main: PowerFlowCardPlus,
+ config: PowerFlowCardPlusConfig,
{ entities, grid, templatesObj }: { entities: ConfigEntities; grid: any; templatesObj: TemplatesObj }
) => {
return html`
@@ -35,7 +36,7 @@ export const gridElement = (
}
}}
>
- ${generalSecondarySpan(main.hass, main, templatesObj, grid, "grid")}
+ ${generalSecondarySpan(main.hass, main, config, templatesObj, grid, "grid")}
${(entities.grid?.display_state === "two_way" ||
entities.grid?.display_state === undefined ||
@@ -57,7 +58,8 @@ export const gridElement = (
}}
>
- ${displayValue(main.hass, grid.state.toGrid)}
+
+ ${displayValue(main.hass, grid.state.toGrid, grid.unit, grid.unit_white_space, grid.decimals, undefined, config.watt_threshold)}
`
: null}
${((entities.grid?.display_state === "two_way" ||
@@ -80,7 +82,8 @@ export const gridElement = (
}
}}
>
- ${displayValue(main.hass, grid.state.fromGrid)}
+
+ ${displayValue(main.hass, grid.state.fromGrid, grid.unit, grid.unit_white_space, grid.decimals, undefined, config.watt_threshold)}
`
: ""}
${grid.powerOutage?.isOutage && !grid.powerOutage?.entityGenerator ? html`${grid.powerOutage.name}` : ""}
diff --git a/src/components/home.ts b/src/components/home.ts
index 62f5043..cd40446 100644
--- a/src/components/home.ts
+++ b/src/components/home.ts
@@ -50,7 +50,7 @@ export const homeElement = (
}
}}
>
- ${generalSecondarySpan(main.hass, main, templatesObj, home, "home")}
+ ${generalSecondarySpan(main.hass, main, config, templatesObj, home, "home")}
${homeUsageToDisplay}
`;
diff --git a/src/components/spans/baseSecondarySpan.ts b/src/components/spans/baseSecondarySpan.ts
index a48b6d5..d817875 100644
--- a/src/components/spans/baseSecondarySpan.ts
+++ b/src/components/spans/baseSecondarySpan.ts
@@ -1,6 +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";
type BaseSecondarySpan = {
main: PowerFlowCardPlus;
@@ -12,6 +13,7 @@ type BaseSecondarySpan = {
};
export const baseSecondarySpan = ({ main, className, template, value, entityId, icon }: BaseSecondarySpan) => {
+ if (value && offlineStr.includes(value)) return html``;
if (value || template) {
return html` {
if (!field) return "";
if (field?.state === undefined) return "";
- return displayValue(this.hass, field?.state, field?.unit, field?.unit_white_space, field?.decimals);
+ // return displayValue(this.hass, field?.state, field?.unit, field?.unit_white_space, field?.decimals);
+ return displayValue(this.hass, field?.state, field?.unit, field?.unit_white_space, field?.decimals, undefined, this._config.watt_threshold);
};
const individualKeys = ["left-top", "left-bottom", "right-top", "right-bottom"];
@@ -524,7 +557,7 @@ export class PowerFlowCardPlus extends LitElement {
templatesObj,
})}
${solar.has
- ? solarElement(this, {
+ ? solarElement(this, this._config, {
entities,
solar,
templatesObj,
@@ -554,7 +587,7 @@ export class PowerFlowCardPlus extends LitElement {
: html``}
${grid.has
- ? gridElement(this, {
+ ? gridElement(this, this._config, {
entities,
grid,
templatesObj,
@@ -581,7 +614,7 @@ export class PowerFlowCardPlus extends LitElement {
? html`
- ${battery.has ? batteryElement(this, { battery, entities }) : html`
`}
+ ${battery.has ? batteryElement(this, this._config, { battery, entities }) : html`
`}
${individualFieldLeftBottom
? individualLeftBottomElement(this, this.hass, this._config, {
displayState: getIndividualDisplayState(individualFieldLeftBottom),
diff --git a/src/type.ts b/src/type.ts
index a20e37d..97d240e 100644
--- a/src/type.ts
+++ b/src/type.ts
@@ -137,3 +137,6 @@ export type GridObject = {
};
};
};
+
+export type OfflineStr = "unavailable" | "unknown";
+export const offlineStr = ["unavailable", "unknown"];
diff --git a/src/utils/displayNonFossilState.ts b/src/utils/displayNonFossilState.ts
index 0a60658..f171c70 100644
--- a/src/utils/displayNonFossilState.ts
+++ b/src/utils/displayNonFossilState.ts
@@ -36,15 +36,13 @@ export const displayNonFossilState = (
nonFossilFuelWatts = 0;
}
}
- result = displayValue(hass, nonFossilFuelWatts, undefined, unitWhiteSpace);
- } else {
- let nonFossilFuelPercentage: number = 100 - (getEntityState(hass, entityFossil) ?? 0);
- if (displayZeroTolerance) {
- if (nonFossilFuelPercentage < displayZeroTolerance) {
- nonFossilFuelPercentage = 0;
- }
+ return displayValue(hass, nonFossilFuelWatts, undefined, unitWhiteSpace, 0, undefined, config.watt_threshold);
+ }
+ let nonFossilFuelPercentage: number = 100 - (getEntityState(hass, entityFossil) ?? 0);
+ if (displayZeroTolerance) {
+ if (nonFossilFuelPercentage < displayZeroTolerance) {
+ nonFossilFuelPercentage = 0;
}
- result = displayValue(hass, nonFossilFuelPercentage, unitOfMeasurement, unitWhiteSpace, 0);
}
- return result;
+ return displayValue(hass, nonFossilFuelPercentage, undefined, unitWhiteSpace, 0, undefined, config.watt_threshold);
};
diff --git a/src/utils/displayValue.ts b/src/utils/displayValue.ts
index ea8c61b..c511730 100644
--- a/src/utils/displayValue.ts
+++ b/src/utils/displayValue.ts
@@ -7,17 +7,20 @@ export const displayValue = (
unit?: string | undefined,
unitWhiteSpace?: boolean | undefined,
decimals?: number | undefined,
- accept_negative?: boolean | undefined
+ accept_negative?: boolean | undefined,
+ watt_threshold: number | undefined = 1000
): string => {
if (value === null) return "0";
if (!isNumberValue(value)) return value.toString();
const valueInNumber = Number(value);
- const isKW = unit === undefined && valueInNumber >= 1000;
+
+ const isKW = unit === undefined && valueInNumber >= watt_threshold;
const transformValue = (v: number) => (!accept_negative ? Math.abs(v) : v);
const v = formatNumber(transformValue(isKW ? round(valueInNumber / 1000, decimals ?? 2) : round(valueInNumber, decimals ?? 0)), hass.locale);
+
return `${v}${unitWhiteSpace === false ? "" : " "}${unit || (isKW ? "kW" : "W")}`;
};