Skip to content

Commit 24ff33a

Browse files
committed
fix: use str2time() instead of datetime.fromisoformat() in is_running() and load_plan()
datetime.fromisoformat() on Python 3.9/3.10 rejects ISO strings with colon-less UTC offsets (e.g. '+0100'), which raises ValueError inside is_running() and reports a false unhealthy status, and drops the saved plan in load_plan(). str2time() in utils.py already parses these formats across Python versions via a strptime fallback. Also widens the is_running() except clause to (ValueError, TypeError) to match load_plan(). Fixes #5181
1 parent d7d8c60 commit 24ff33a

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

‎apps/predbat/predbat.py‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
from config import APPS_SCHEMA, CONFIG_ITEMS
7878
import debug_history
7979
from utils import (
80+
str2time,
8081
minutes_since_yesterday,
8182
minutes_since_midnight,
8283
dp1,
@@ -843,7 +844,7 @@ def load_plan(self):
843844
return
844845

845846
try:
846-
saved_dt = datetime.fromisoformat(saved_updated)
847+
saved_dt = str2time(saved_updated)
847848
except (ValueError, TypeError):
848849
self.log("Warning: Saved plan timestamp is invalid, ignoring")
849850
return
@@ -1984,8 +1985,8 @@ def is_running(self):
19841985
return False
19851986

19861987
try:
1987-
predbat_last_updated = datetime.fromisoformat(predbat_last_updated)
1988-
except ValueError:
1988+
predbat_last_updated = str2time(predbat_last_updated)
1989+
except (ValueError, TypeError):
19891990
return False
19901991

19911992
# Check if the last updated time is within the last 15 minutes. An install upgraded

0 commit comments

Comments
 (0)