Exclude retired batteries from dashboard warnings
This commit is contained in:
@@ -95,7 +95,7 @@ def create_app(config_object="config"):
|
|||||||
and b.tested_capacity_mah < 0.8 * b.capacity_mah
|
and b.tested_capacity_mah < 0.8 * b.capacity_mah
|
||||||
],
|
],
|
||||||
"low_pct": [
|
"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 b.battery_percentage is not None and b.battery_percentage < 20
|
||||||
] if ha_client.enabled else [],
|
] if ha_client.enabled else [],
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,7 @@
|
|||||||
<div class="text-muted">Retired</div>
|
<div class="text-muted">Retired</div>
|
||||||
</div>
|
</div>
|
||||||
{% if ha_enabled %}
|
{% 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 low_pct %}
|
||||||
<a href="#needs-attention"
|
<a href="#needs-attention"
|
||||||
onclick="var d=document.getElementById('needs-attention');d.open=true;"
|
onclick="var d=document.getElementById('needs-attention');d.open=true;"
|
||||||
@@ -248,7 +248,7 @@
|
|||||||
<td data-label="Bat %" class="col-ha-pct" style="display:none;"
|
<td data-label="Bat %" class="col-ha-pct" style="display:none;"
|
||||||
data-sort-col="ha-pct" data-sort="{{ b.battery_percentage if b.battery_percentage is not none else '' }}">
|
data-sort-col="ha-pct" data-sort="{{ b.battery_percentage if b.battery_percentage is not none else '' }}">
|
||||||
{% if b.battery_percentage is not none %}
|
{% if b.battery_percentage is not none %}
|
||||||
{% if b.battery_percentage < 20 %}
|
{% if b.battery_percentage < 20 and b.status != 'retired' %}
|
||||||
<span class="badge badge-warning" title="Low — consider replacing">⚠ {{ b.battery_percentage }}%</span>
|
<span class="badge badge-warning" title="Low — consider replacing">⚠ {{ b.battery_percentage }}%</span>
|
||||||
{% else %}{{ b.battery_percentage }}%{% endif %}
|
{% else %}{{ b.battery_percentage }}%{% endif %}
|
||||||
{% else %}—{% endif %}
|
{% else %}—{% endif %}
|
||||||
|
|||||||
@@ -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
|
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):
|
def test_device_detail_shows_ha_field(ha_client_f):
|
||||||
ha_client_f.post("/device/add", data={"name": "Dev E", "battery_slots": "1"})
|
ha_client_f.post("/device/add", data={"name": "Dev E", "battery_slots": "1"})
|
||||||
resp = ha_client_f.get("/device/1")
|
resp = ha_client_f.get("/device/1")
|
||||||
|
|||||||
Reference in New Issue
Block a user