Skip to content

Commit 5938e15

Browse files
authored
Update predbat-table-card.js
Refactored net-power-column code to tighten up some potential issues
1 parent 8abfb13 commit 5938e15

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

predbat-table-card.js

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,30 +1263,47 @@ class PredbatTableCard extends HTMLElement {
12631263
newTRObject["import-export-column"] = [newTRObject[headerClassesArray[1]], newTRObject[headerClassesArray[2]]];
12641264

12651265
// net-power-column
1266-
let pvValue = newTRObject[headerClassesArray[5]].value.replace(/[]/g, '');
1267-
1266+
1267+
const loadIndex = headerClassesArray.indexOf("load-column");
1268+
const pvIndex = headerClassesArray.indexOf("pv-column");
12681269
const carIndex = headerClassesArray.indexOf("car-column");
12691270
const iBoostIndex = headerClassesArray.indexOf("iboost-column");
1270-
1271+
1272+
let pvValue = 0;
1273+
let loadValue = 0;
12711274
let carValue = 0;
12721275
let iBoostValue = 0;
12731276

1277+
if(pvIndex !== -1){
1278+
pvValue = newTRObject[headerClassesArray[pvIndex]].value.replace(/[]/g, '');
1279+
if(pvValue.length === 0 || Number.isNaN(parseFloat(pvValue)))
1280+
pvValue = 0;
1281+
}
1282+
1283+
if(loadIndex !== -1){
1284+
loadValue = newTRObject[headerClassesArray[loadIndex]].value;
1285+
if(loadValue.length === 0 || Number.isNaN(parseFloat(loadValue)))
1286+
loadValue = 0;
1287+
}
1288+
12741289
if(carIndex !== -1){
12751290
carValue = newTRObject[headerClassesArray[carIndex]].value;
12761291
if(carValue.length === 0)
12771292
carValue = 0;
12781293
}
12791294
if(iBoostIndex !== -1){
12801295
iBoostValue = newTRObject[headerClassesArray[iBoostIndex]].value;
1281-
if(iBoostValue.length === 0)
1296+
if(iBoostValue.length === 0 || Number.isNaN(parseFloat(iBoostValue)))
12821297
iBoostValue = 0;
12831298
}
1284-
if(pvValue.length === 0)
1285-
pvValue = 0;
1286-
const netPower = (parseFloat(pvValue) - parseFloat(newTRObject[headerClassesArray[6]].value) - parseFloat(carValue) - parseFloat(iBoostValue)).toFixed(2);
1299+
1300+
//console.log(parseFloat(pvValue) + " " + parseFloat(loadValue) + " " + parseFloat(carValue) + " " + parseFloat(iBoostValue));
1301+
1302+
const netPower = (parseFloat(pvValue) - parseFloat(loadValue) - parseFloat(carValue) - parseFloat(iBoostValue)).toFixed(2);
12871303
const positiveColor = "#3AEE85";
12881304
const negativeColor = "#F18261";
12891305
let adjustedColor;
1306+
12901307
if(netPower > 0){
12911308
adjustedColor = positiveColor;
12921309
if(this.getLightMode(hassDarkMode) === false && this.config.old_skool !== true)

0 commit comments

Comments
 (0)