From c7b7c24a7e86e6c2d30b7fd4736ab6b31173f6a0 Mon Sep 17 00:00:00 2001 From: Darek Date: Tue, 14 Apr 2026 18:49:07 -0500 Subject: [PATCH] Add needs-attention alerts, last charged, health %, quick charge, sortable columns --- app.py | 25 ++++++- templates/dashboard.html | 150 ++++++++++++++++++++++++++++++++++++--- 2 files changed, 162 insertions(+), 13 deletions(-) diff --git a/app.py b/app.py index 0f490d3..3c6246c 100644 --- a/app.py +++ b/app.py @@ -76,17 +76,38 @@ def create_app(config_object="config"): ] devices = db.query(Device).order_by(Device.name).all() devices_with_slots = [d for d in devices if d.installed_count() < d.battery_slots] - one_year_ago = (date.today() - timedelta(days=365)).isoformat() + today = date.today() + one_year_ago = (today - timedelta(days=365)).isoformat() total_charges = db.query(func.count(ChargeLog.id)).scalar() or 0 charges_last_year = (db.query(func.count(ChargeLog.id)) .filter(ChargeLog.charged_date >= one_year_ago) .scalar()) or 0 + last_charged_map = { + r[0]: r[1] + for r in db.query(ChargeLog.battery_id, func.max(ChargeLog.charged_date)) + .group_by(ChargeLog.battery_id).all() + } + active = [b for b in batteries if b.status in ("available", "installed")] + needs_attention = { + "low_capacity": [ + b for b in active + if b.tested_capacity_mah and b.capacity_mah + and b.tested_capacity_mah < 0.8 * b.capacity_mah + ], + "low_pct": [ + b for b in batteries + if b.battery_percentage is not None and b.battery_percentage < 20 + ] if ha_client.enabled else [], + } return render_template("dashboard.html", batteries=batteries, storage_locations=storage_locations, devices=devices, devices_with_slots=devices_with_slots, ha_enabled=ha_client.enabled, total_charges=total_charges, - charges_last_year=charges_last_year) + charges_last_year=charges_last_year, + last_charged_map=last_charged_map, + needs_attention=needs_attention, + today=today) # ------------------------------------------------------------------ # # Battery — add diff --git a/templates/dashboard.html b/templates/dashboard.html index 18fe9ee..c08c727 100644 --- a/templates/dashboard.html +++ b/templates/dashboard.html @@ -44,12 +44,49 @@ {% endif %} +{% set na_low_cap = needs_attention.low_capacity %} +{% set na_low_pct = needs_attention.low_pct %} +{% if na_low_cap or na_low_pct %} +
+ + + Needs Attention  {{ (na_low_cap|length) + (na_low_pct|length) }} + +
+ {% if na_low_cap %} +
+
Low Capacity (<80%)
+ {% for b in na_low_cap %} +
+ {{ b.label }} + — {{ (b.tested_capacity_mah / b.capacity_mah * 100)|int }}% of rated +
+ {% endfor %} +
+ {% endif %} + {% if na_low_pct %} +
+
Low Battery %
+ {% for b in na_low_pct %} +
+ {{ b.label }} + — {{ b.battery_percentage }}% +
+ {% endfor %} +
+ {% endif %} +
+
+{% endif %} +