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) }}
+
+