Exclude retired batteries from dashboard warnings

This commit is contained in:
2026-04-14 19:40:11 -05:00
parent 5d8fb5aa68
commit e4130bb329
3 changed files with 43 additions and 3 deletions
+40
View File
@@ -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")