Skip to content

Commit af96ae2

Browse files
Add DCB data only if available to avoid crash (#86)
1 parent a199eb4 commit af96ae2

File tree

1 file changed

+30
-16
lines changed

1 file changed

+30
-16
lines changed

e3dc/_e3dc.py

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,8 +1209,6 @@ def get_battery_data(self, batIndex=None, dcbs=None, keepAlive=False):
12091209
"maxChargeCurrent": <max charge current>,
12101210
"maxDischargeCurrent": <max discharge current>,
12111211
"maxDcbCellTemp": <max DCB cell temp>,
1212-
"measuredResistance": <measured resistance>,
1213-
"measuredResistanceRun": <measure resistance (RUN)>,
12141212
"minDcbCellTemp": <min DCB cell temp>,
12151213
"moduleVoltage": <module voltage>,
12161214
"rc": <rc>,
@@ -1380,23 +1378,39 @@ def get_battery_data(self, batIndex=None, dcbs=None, keepAlive=False):
13801378
)
13811379

13821380
info = rscpFindTag(req, RscpTag.BAT_DCB_INFO)
1381+
# For some devices, no info for the DCBs exists. Skip those.
1382+
if info is None or len(info) < 3 or info[1] == "Error":
1383+
continue
13831384

1384-
temperatures_raw = rscpFindTagIndex(
1385-
rscpFindTag(req, RscpTag.BAT_DCB_ALL_CELL_TEMPERATURES),
1386-
RscpTag.BAT_DATA,
1387-
)
1385+
# Initialize default values for DCB
1386+
sensorCount = 0
13881387
temperatures = []
1389-
sensorCount = rscpFindTagIndex(info, RscpTag.BAT_DCB_NR_SENSOR)
1390-
for sensor in range(0, sensorCount):
1391-
temperatures.append(round(temperatures_raw[sensor][2], 2))
1392-
1393-
voltages_raw = rscpFindTagIndex(
1394-
rscpFindTag(req, RscpTag.BAT_DCB_ALL_CELL_VOLTAGES), RscpTag.BAT_DATA
1395-
)
1388+
seriesCellCount = 0
13961389
voltages = []
1397-
seriesCellCount = rscpFindTagIndex(info, RscpTag.BAT_DCB_NR_SERIES_CELL)
1398-
for cell in range(0, seriesCellCount):
1399-
voltages.append(round(voltages_raw[cell][2], 2))
1390+
1391+
# Set temperatures, if available for the device
1392+
temps = rscpFindTag(req, RscpTag.BAT_DCB_ALL_CELL_TEMPERATURES)
1393+
if temps is not None and len(temps) == 3 and temps[1] != "Error":
1394+
temperatures_raw = rscpFindTagIndex(
1395+
rscpFindTag(req, RscpTag.BAT_DCB_ALL_CELL_TEMPERATURES),
1396+
RscpTag.BAT_DATA,
1397+
)
1398+
temperatures = []
1399+
sensorCount = rscpFindTagIndex(info, RscpTag.BAT_DCB_NR_SENSOR)
1400+
for sensor in range(0, sensorCount):
1401+
temperatures.append(round(temperatures_raw[sensor][2], 2))
1402+
1403+
# Set voltages, if available for the device
1404+
voltages = rscpFindTag(req, RscpTag.BAT_DCB_ALL_CELL_VOLTAGES)
1405+
if voltages is not None and len(voltages) == 3 and voltages[1] != "Error":
1406+
voltages_raw = rscpFindTagIndex(
1407+
rscpFindTag(req, RscpTag.BAT_DCB_ALL_CELL_VOLTAGES),
1408+
RscpTag.BAT_DATA,
1409+
)
1410+
voltages = []
1411+
seriesCellCount = rscpFindTagIndex(info, RscpTag.BAT_DCB_NR_SERIES_CELL)
1412+
for cell in range(0, seriesCellCount):
1413+
voltages.append(round(voltages_raw[cell][2], 2))
14001414

14011415
dcbobj = {
14021416
"current": rscpFindTagIndex(info, RscpTag.BAT_DCB_CURRENT),

0 commit comments

Comments
 (0)