Fix wellness sync crash on None body battery levels
Guard bb variable scope and filter None entries from bodyBatteryValuesArray before subtraction in _compute_body_battery_hires. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -252,6 +252,7 @@ def sync_wellness(garmin, user_id: int, since: Optional[datetime], db,
|
|||||||
_set(row, "weight_kg", round(bwf / 1000 if bwf > 300 else bwf, 2))
|
_set(row, "weight_kg", round(bwf / 1000 if bwf > 300 else bwf, 2))
|
||||||
|
|
||||||
# Body battery — store summary + fine-grained timeline
|
# Body battery — store summary + fine-grained timeline
|
||||||
|
bb = None
|
||||||
if bb_raw:
|
if bb_raw:
|
||||||
bb = _parse_body_battery(bb_raw, day_str)
|
bb = _parse_body_battery(bb_raw, day_str)
|
||||||
if bb:
|
if bb:
|
||||||
@@ -374,7 +375,11 @@ def _compute_body_battery_hires(bb_values, intraday_hr):
|
|||||||
if not bb_values or not intraday_hr or len(bb_values) < 2:
|
if not bb_values or not intraday_hr or len(bb_values) < 2:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
bb = sorted(bb_values, key=lambda x: x[0])
|
# Drop entries with None timestamp or level — raw API data can have gaps
|
||||||
|
bb = sorted([v for v in bb_values if v[0] is not None and v[1] is not None],
|
||||||
|
key=lambda x: x[0])
|
||||||
|
if len(bb) < 2:
|
||||||
|
return None
|
||||||
hr = sorted(intraday_hr, key=lambda x: x[0])
|
hr = sorted(intraday_hr, key=lambda x: x[0])
|
||||||
|
|
||||||
hr_vals = [bpm for _, bpm in hr if bpm is not None and bpm > 0]
|
hr_vals = [bpm for _, bpm in hr if bpm is not None and bpm > 0]
|
||||||
|
|||||||
Reference in New Issue
Block a user