Skip to content

Commit 82f4dfa

Browse files
authored
fix: clear stale modem dashboard state on config change (#186)
1 parent 5e6531a commit 82f4dfa

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

app/main.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ def start_polling():
212212
if poll_thread and poll_thread.is_alive():
213213
poll_stop.set()
214214
poll_thread.join(timeout=10)
215+
web.reset_modem_state()
215216
poll_stop = threading.Event()
216217
poll_thread = threading.Thread(
217218
target=polling_loop, args=(config_mgr, storage, poll_stop), daemon=True

app/web.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,21 @@ def get_state() -> dict:
581581
return dict(_state)
582582

583583

584+
def reset_modem_state():
585+
"""Clear modem-specific dashboard state before switching drivers.
586+
587+
Keeps unrelated collector data like speedtest/weather cache intact so
588+
the dashboard only drops the modem-derived sections while a new poll
589+
is starting.
590+
"""
591+
with _state_lock:
592+
_state["analysis"] = None
593+
_state["last_update"] = None
594+
_state["error"] = None
595+
_state["connection_info"] = None
596+
_state["device_info"] = None
597+
598+
584599
@app.route("/sw.js")
585600
def service_worker():
586601
return send_from_directory(app.static_folder, "sw.js", mimetype="application/javascript")
@@ -733,4 +748,3 @@ def add_security_headers(response):
733748
# ── Blueprint Registration ──
734749
from .blueprints import register_blueprints
735750
register_blueprints(app)
736-

tests/test_web.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import io
44
import json
55
import pytest
6-
from app.web import app, update_state, init_config, init_storage
6+
from app.web import app, update_state, init_config, init_storage, reset_modem_state, get_state
77
from app.config import ConfigManager
88
from app.storage import SnapshotStorage
99
from app.modules.bnetz.storage import BnetzStorage
@@ -208,6 +208,24 @@ def test_health_ok(self, client, sample_analysis):
208208
assert data["status"] == "ok"
209209
assert data["docsis_health"] == "good"
210210

211+
def test_reset_modem_state_clears_stale_dashboard_data(self, client, sample_analysis):
212+
update_state(
213+
analysis=sample_analysis,
214+
device_info={"model": "Generic Router"},
215+
connection_info={"connection_type": "generic"},
216+
speedtest_latest={"download_mbps": 230.5},
217+
)
218+
219+
reset_modem_state()
220+
state = get_state()
221+
222+
assert state["analysis"] is None
223+
assert state["device_info"] is None
224+
assert state["connection_info"] is None
225+
assert state["last_update"] is None
226+
assert state["error"] is None
227+
assert state["speedtest_latest"] == {"download_mbps": 230.5}
228+
211229

212230
class TestExportEndpoint:
213231
def test_export_no_data(self, client):

0 commit comments

Comments
 (0)