From 0db706b675c0c0fb145943794fba4a10deeac59d Mon Sep 17 00:00:00 2001 From: Codegnosis Date: Mon, 22 Jan 2024 12:44:40 +0000 Subject: [PATCH] fix - use correct UoM for battery power --- package.json | 2 +- src/givtcp-battery-card.ts | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 6471f95..0149c80 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "givtcp-battery-card", - "version": "0.2.0", + "version": "0.2.1", "description": "Lovelace card to display GivTCP battery info", "private": true, "type": "module", diff --git a/src/givtcp-battery-card.ts b/src/givtcp-battery-card.ts index b4adb63..596b99f 100644 --- a/src/givtcp-battery-card.ts +++ b/src/givtcp-battery-card.ts @@ -217,6 +217,10 @@ export class GivTCPBatteryCard extends LitElement implements LovelaceCard { return (uom === DISPLAY_UNITS.W || uom === DISPLAY_UNITS.WH); } + isPowerUom(uom: string): boolean { + return (uom === DISPLAY_UNITS.W || uom === DISPLAY_UNITS.KW); + } + getGivTcpStats(state: string, uomRaw: string | undefined): GivTcpStats { const displayType = (this.config.display_type !== undefined) ? this.config.display_type : DISPLAY_TYPE; const displayAbsPower = (this.config.display_abs_power !== undefined) ? this.config.display_abs_power : DISPLAY_ABS_POWER; @@ -229,8 +233,8 @@ export class GivTCPBatteryCard extends LitElement implements LovelaceCard { const kValue = this.isWorWh(uom) ? this.convertToKillo(rawAsNum, 3) : rawAsNum; const displayK = this.convertToKillo(value, dp); - const displayUom = this.isWorWh(uom) ? uom : this.getStandardisedUom(`k${uom}`); - const displayKUom = this.isWorWh(uom) ? this.getStandardisedUom(`k${uom}`) : uom; + const displayUom = this.isPowerUom(uom) ? DISPLAY_UNITS.W : DISPLAY_UNITS.WH; + const displayKUom = this.isPowerUom(uom) ? DISPLAY_UNITS.KW : DISPLAY_UNITS.KWH; let display = 0; let displayStr = "";