diff --git a/app.py b/app.py
index 3c6246c..9f13ee1 100644
--- a/app.py
+++ b/app.py
@@ -95,7 +95,7 @@ def create_app(config_object="config"):
and b.tested_capacity_mah < 0.8 * b.capacity_mah
],
"low_pct": [
- b for b in batteries
+ b for b in active
if b.battery_percentage is not None and b.battery_percentage < 20
] if ha_client.enabled else [],
}
diff --git a/templates/dashboard.html b/templates/dashboard.html
index f909a8d..17631eb 100644
--- a/templates/dashboard.html
+++ b/templates/dashboard.html
@@ -27,7 +27,7 @@
Retired
{% if ha_enabled %}
- {% set low_pct = batteries | selectattr('battery_percentage', 'ne', none) | selectattr('battery_percentage', 'lt', 20) | list %}
+ {% set low_pct = batteries | rejectattr('status', 'equalto', 'retired') | selectattr('battery_percentage', 'ne', none) | selectattr('battery_percentage', 'lt', 20) | list %}
{% if low_pct %}
{% if b.battery_percentage is not none %}
- {% if b.battery_percentage < 20 %}
+ {% if b.battery_percentage < 20 and b.status != 'retired' %}
⚠ {{ b.battery_percentage }}%
{% else %}{{ b.battery_percentage }}%{% endif %}
{% else %}—{% endif %}
diff --git a/tests/test_ha_integration.py b/tests/test_ha_integration.py
index 2c639f2..f5bfa14 100644
--- a/tests/test_ha_integration.py
+++ b/tests/test_ha_integration.py
@@ -302,6 +302,46 @@ def test_dashboard_no_warning_for_high_percentage(ha_app, ha_client_f):
assert b"col-ha-pct" in resp.data # column rendered
+def test_retired_battery_excluded_from_low_pct_warning(ha_app, ha_client_f):
+ ha_client_f.post("/battery/add", data={"brand": "X", "count": "1"})
+
+ from sqlalchemy import create_engine
+ from sqlalchemy.orm import sessionmaker
+ from models import Battery
+ engine = create_engine(ha_app.config["SQLALCHEMY_DATABASE_URI"])
+ s = sessionmaker(bind=engine)()
+ b = s.get(Battery, 1)
+ b.battery_percentage = 15
+ s.commit()
+ s.close()
+
+ ha_client_f.post("/battery/1/retire")
+
+ resp = ha_client_f.get("/")
+ assert b"consider replacing" not in resp.data # no ⚠ badge in table
+ assert b"Low Battery" not in resp.data # no summary card
+
+
+def test_retired_battery_excluded_from_needs_attention_section(ha_app, ha_client_f):
+ ha_client_f.post("/battery/add", data={"brand": "LowCap", "count": "1"})
+
+ from sqlalchemy import create_engine
+ from sqlalchemy.orm import sessionmaker
+ from models import Battery
+ engine = create_engine(ha_app.config["SQLALCHEMY_DATABASE_URI"])
+ s = sessionmaker(bind=engine)()
+ b = s.get(Battery, 1)
+ b.capacity_mah = 2000
+ b.tested_capacity_mah = 1500 # 75% — below 80% threshold
+ s.commit()
+ s.close()
+
+ ha_client_f.post("/battery/1/retire")
+
+ resp = ha_client_f.get("/")
+ assert b"needs-attention" not in resp.data
+
+
def test_device_detail_shows_ha_field(ha_client_f):
ha_client_f.post("/device/add", data={"name": "Dev E", "battery_slots": "1"})
resp = ha_client_f.get("/device/1")