Skip to content

Commit 75fd9f0

Browse files
fix(output): split a History status at its earliest warning marker
split_status_warning() tried ', warn:' before ', error:' and so on, rather than taking whichever came first. A status like 'Charging, Error: ... , Warn: ...' was cut at the later marker, so the flag's tooltip showed only the tail of the error and the state part kept the error text. Take the minimum index across all markers instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 0298b14 commit 75fd9f0

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

‎apps/predbat/output.py‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,11 @@ def split_status_warning(status):
105105
# recognised, bare and behind a state alike.
106106
if lowered.startswith("warn:") or lowered.startswith("warn -") or lowered.startswith("error:"):
107107
return "", status
108-
for marker in (", warn:", ", warn -", ", error:"):
109-
index = lowered.find(marker)
110-
if index >= 0:
111-
return status[:index].strip(), status[index + 2 :].strip()
108+
# Split at the earliest marker, whichever kind: the warning text may itself mention another one.
109+
indices = [index for index in (lowered.find(marker) for marker in (", warn:", ", warn -", ", error:")) if index >= 0]
110+
if indices:
111+
index = min(indices)
112+
return status[:index].strip(), status[index + 2 :].strip()
112113
return status, ""
113114

114115

‎apps/predbat/tests/test_calculate_yesterday.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2246,6 +2246,7 @@ def _test_split_status_warning(my_predbat, failed):
22462246
("Freeze exporting, Hold for car, Error: Inverter 0 unable to read Export window", "Freeze exporting, Hold for car"),
22472247
("Warn - Unable to fetch data from sensor.outdoor_temperature", ""),
22482248
("Exporting, Warn - Unable to fetch data from sensor.outdoor_temperature", "Exporting"),
2249+
("Charging, Error: Exception raised in fetch, Warn: retrying", "Charging"),
22492250
]
22502251
for status, expected in cases:
22512252
result = split_status_warning(status)[0]
@@ -2259,6 +2260,10 @@ def _test_split_status_warning(my_predbat, failed):
22592260
("Warn - Unable to fetch data from sensor.outdoor_temperature", "Warn - Unable to fetch data from sensor.outdoor_temperature"),
22602261
("Exporting, Warn - Unable to fetch data from sensor.outdoor_temperature", "Warn - Unable to fetch data from sensor.outdoor_temperature"),
22612262
("Exporting, Warn: Return bad float value unavailable from car_charging_soc", "Warn: Return bad float value unavailable from car_charging_soc"),
2263+
# The split is at the first marker, whichever kind it is, so a warning that mentions another
2264+
# marker later on is kept whole rather than cut at that later marker
2265+
("Charging, Error: Exception raised in fetch, Warn: retrying", "Error: Exception raised in fetch, Warn: retrying"),
2266+
("Charging, Warn - Unable to fetch data, Error: timeout", "Warn - Unable to fetch data, Error: timeout"),
22622267
]
22632268
for status, expected in warning_cases:
22642269
result = split_status_warning(status)[1]

0 commit comments

Comments
 (0)