feat(sfm): the page's Call Home tab by serial -- state and audited On / Off (phase 4)
device_routing.js (Node-tested): call_home_state / call_home_on / call_home_off
routes (serial required); controlsFor gains callHomeChange (by serial, a
confirmed Series 3 or 4) and callHomeRead now covers a Series 4 by serial;
serialPanes gains callHomeForm / callHomeBox; callHomeRows renders the switch
(On / Off / 'Unknown (byte 5 = 0xNN)'), dial string and series;
changeErrorText takes the whole label ('Start monitoring', 'Enable call-home').
sfm_webapp.js: by serial the Call Home tab hides the legacy multi-field form
(Series 3 by host only) and shows the unit's switch with On / Off. Each asks
confirm(), sends one audited change, reports it with changeSummary /
changeErrorText, then re-reads quietly so the change's own result stays on
screen. A different unit's switch is never left showing. The new buttons are
wired with addEventListener, not onclick= (no inline JS).
Checked in jsdom against the real page: placeholder, read, Off (confirm, the
disable route, 'confirmed -- enabled -> disabled'), a serial edit clearing it,
legacy mode unchanged, no script errors.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SyJ2ip3Krb6dtdv2cXua44
This commit is contained in:
1 parent
06fa56db09
commit
84c142f36c
4 files changed
+151
-23
No files matched your search
+12
-1
@@ -1141,6 +1141,16 @@
|
||||
═══════════════════════════════════════════════════════════════════ -->
|
||||
<div id="tab-call-home" class="tab-pane">
|
||||
|
||||
<div id="ch-serial" style="display:none; margin-bottom:12px">
|
||||
<div class="cfg-section-title">On the unit (by serial)</div>
|
||||
<div class="dev-table" id="ch-state"></div>
|
||||
<div class="cfg-actions" style="margin-top:8px">
|
||||
<button class="btn btn-success" id="ch-on-btn" disabled>Call-home On</button>
|
||||
<button class="btn btn-ghost" id="ch-off-btn" disabled>Call-home Off</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="ch-legacy">
|
||||
<div class="cfg-grid">
|
||||
|
||||
<!-- Enable / dial -->
|
||||
@@ -1243,11 +1253,12 @@
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="cfg-actions">
|
||||
<button class="btn btn-ghost" id="ch-read-btn" onclick="readCallHome()" disabled>Read from Device</button>
|
||||
<button class="btn btn-success" id="ch-write-btn" onclick="writeCallHome()" disabled>Write to Device</button>
|
||||
<button class="btn btn-ghost" onclick="clearCallHomeForm()">Clear Form</button>
|
||||
<button class="btn btn-ghost" id="ch-clear-btn" onclick="clearCallHomeForm()">Clear Form</button>
|
||||
<span id="ch-status"></span>
|
||||
<span id="ch-series-note" style="color:var(--text-dim)"></span>
|
||||
</div>
|
||||
|
||||
@@ -44,6 +44,9 @@ const DEVICE_ROUTES = {
|
||||
slow_drip: ['POST', '/device/stop_monitoring_slow_drip', false],
|
||||
call_home_read: ['GET', '/device/call_home', false],
|
||||
call_home_write: ['POST', '/device/call_home', false],
|
||||
call_home_state: ['GET', '/device/call_home/state', true],
|
||||
call_home_on: ['POST', '/device/call_home/enable', true],
|
||||
call_home_off: ['POST', '/device/call_home/disable', true],
|
||||
config_write: ['POST', '/device/config', false],
|
||||
event_waveform: ['GET', '/device/event/{index}/waveform', false],
|
||||
event_file: ['GET', '/device/event/{index}/blastware_file', false],
|
||||
@@ -82,10 +85,13 @@ function controlsFor(unit) {
|
||||
startStop: serialMode && (series === 3 || series === 4),
|
||||
hangup: series === 4,
|
||||
diagnostics: series === 3,
|
||||
callHomeRead: series === 3,
|
||||
// by host, the legacy read is Series 3's; by serial, both series (phase 4)
|
||||
callHomeRead: series === 3 || (serialMode && series === 4),
|
||||
callHomeChange: serialMode && (series === 3 || series === 4),
|
||||
configWrite: false,
|
||||
callHomeWrite: false,
|
||||
reasons: { configWrite: 'Coming in phase 5 (#46)', callHomeWrite: 'Coming in phase 4' },
|
||||
reasons: { configWrite: 'Coming in phase 5 (#46)',
|
||||
callHomeWrite: 'By serial: use Call-home On / Off (audited). Other call-home fields wait for the THOR round.' },
|
||||
};
|
||||
}
|
||||
|
||||
@@ -178,18 +184,28 @@ function deviceErrorText(status, body, unit, statusText) {
|
||||
return status === 504 && !(body || {}).sent && unit && unit.host ? `${text} — ${NO_REPLY_HINT}` : text;
|
||||
}
|
||||
|
||||
// A start/stop that went out (or may have) is not "failed": its body carries
|
||||
// `sent` (ChangeUnconfirmed, bench finding #10), and its message says what the
|
||||
// unit did and names the audit record.
|
||||
function changeErrorText(verb, status, body, unit, statusText) {
|
||||
if ((body || {}).sent) return `${verb} monitoring not confirmed: ${errorDetail(body, statusText)}`;
|
||||
return `${verb} monitoring failed: ${deviceErrorText(status, body, unit, statusText)}`;
|
||||
// A change that went out (or may have) is not "failed": its body carries `sent`
|
||||
// (ChangeUnconfirmed, bench finding #10), and its message says what the unit
|
||||
// did and names the audit record. `label` is the whole name: "Start monitoring",
|
||||
// "Enable call-home".
|
||||
function changeErrorText(label, status, body, unit, statusText) {
|
||||
if ((body || {}).sent) return `${label} not confirmed: ${errorDetail(body, statusText)}`;
|
||||
return `${label} failed: ${deviceErrorText(status, body, unit, statusText)}`;
|
||||
}
|
||||
|
||||
// By serial, settings are read-only until phase 5: no empty legacy edit form or
|
||||
// legacy tables, and the settings box shows from the start (#6, #12).
|
||||
function serialPanes(bySerial, settingsRead) {
|
||||
return { configForm: !bySerial, settingsBox: bySerial, settingsPlaceholder: bySerial && !settingsRead,
|
||||
legacyDeviceTables: !bySerial };
|
||||
legacyDeviceTables: !bySerial, callHomeForm: !bySerial, callHomeBox: bySerial };
|
||||
}
|
||||
|
||||
// A unit's call-home switch, read by serial (phase 4). `enabled` null is an
|
||||
// enable byte never measured -- shown with the byte, never as On or Off.
|
||||
function callHomeRows(state) {
|
||||
const s = state || {};
|
||||
const sw = s.enabled === true ? 'On' : s.enabled === false ? 'Off'
|
||||
: `Unknown (byte 5 = ${(s.detail || {}).byte5 ?? '?'})`;
|
||||
return [['Call-home', sw], ['Dial string', s.dial_string || '—'], ['Series', s.series]];
|
||||
}
|
||||
/* </device-routing> */
|
||||
@@ -96,11 +96,71 @@ function applyControls() {
|
||||
hw.disabled = !c.callHomeWrite; hw.title = c.reasons.callHomeWrite;
|
||||
const chr = document.getElementById('ch-read-btn');
|
||||
chr.disabled = !c.callHomeRead;
|
||||
const s4 = series === 4 ? 'Not yet available for Series 4' : '';
|
||||
const s4 = series === 4 && !c.callHomeRead ? "Series 4: type the unit's serial to read its call-home" : '';
|
||||
chr.title = s4;
|
||||
document.getElementById('ch-series-note').textContent = s4;
|
||||
for (const id of ['ch-on-btn', 'ch-off-btn']) {
|
||||
document.getElementById(id).disabled = !c.callHomeChange || changeInFlight;
|
||||
}
|
||||
setMonitorButtons();
|
||||
applyConfigPanes();
|
||||
applyCallHomePanes();
|
||||
}
|
||||
|
||||
// The Call Home tab by serial (phase 4): the unit's switch and audited On / Off;
|
||||
// the legacy multi-field form is Series 3 by host only.
|
||||
let callHomeShownFor = null;
|
||||
function applyCallHomePanes() {
|
||||
const serial = normSerial(currentUnit().serial);
|
||||
const p = serialPanes(Boolean(serial), false);
|
||||
document.getElementById('ch-legacy').style.display = p.callHomeForm ? '' : 'none';
|
||||
document.getElementById('ch-serial').style.display = p.callHomeBox ? 'block' : 'none';
|
||||
document.getElementById('ch-write-btn').hidden = !p.callHomeForm;
|
||||
document.getElementById('ch-clear-btn').hidden = !p.callHomeForm;
|
||||
if (p.callHomeBox && callHomeShownFor !== serial) {
|
||||
callHomeShownFor = null;
|
||||
renderTextTable('ch-state', [['Call-home', 'Not read yet — press Read from Device']]);
|
||||
}
|
||||
}
|
||||
|
||||
// `quiet`: the re-read after a change -- the change's own result stays on screen.
|
||||
async function readCallHomeBySerial({ quiet = false } = {}) {
|
||||
const btn = document.getElementById('ch-read-btn');
|
||||
btn.disabled = true;
|
||||
if (!quiet) setChStatus('Reading call-home from the unit…');
|
||||
try {
|
||||
const st = await deviceFetch('call_home_state');
|
||||
renderTextTable('ch-state', callHomeRows(st));
|
||||
callHomeShownFor = normSerial(st.serial);
|
||||
if (!quiet) setChStatus(`Call-home read from ${st.serial}.`, 'ok');
|
||||
} catch (e) {
|
||||
if (!quiet) setChStatus(`Read failed: ${e.message}`, 'error');
|
||||
else renderTextTable('ch-state', [['Call-home', `Re-read failed: ${e.message}`]]);
|
||||
} finally {
|
||||
btn.disabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
// One audited send, never retried; the body says what the unit did.
|
||||
async function changeCallHome(on) {
|
||||
const serial = normSerial(currentUnit().serial);
|
||||
const label = on ? 'Enable call-home' : 'Disable call-home';
|
||||
if (!confirm(`Turn call-home ${on ? 'ON' : 'OFF'} on ${serial}?`)) return;
|
||||
changeInFlight = true; applyControls();
|
||||
setChStatus(`${label}…`);
|
||||
try {
|
||||
const r = await deviceRequest(on ? 'call_home_on' : 'call_home_off');
|
||||
const body = await r.json().catch(() => ({}));
|
||||
setChStatus(body.outcome ? changeSummary(body)
|
||||
: changeErrorText(label, r.status, body, currentUnit(), r.statusText),
|
||||
r.ok ? 'ok' : 'error');
|
||||
} catch (e) {
|
||||
// No reply is not "nothing sent": the request may have reached the unit.
|
||||
setChStatus(`${label}: no reply from SFM (${e.message}) — it may have been sent; `
|
||||
+ `check the unit's state and GET /db/device_commands`, 'error');
|
||||
}
|
||||
changeInFlight = false; applyControls();
|
||||
await readCallHomeBySerial({ quiet: true });
|
||||
}
|
||||
|
||||
// The Config tab by serial (#6): settings are read-only until phase 5, so the
|
||||
@@ -444,7 +504,7 @@ async function changeMonitoring(action) {
|
||||
if (body.outcome) {
|
||||
setStatus(changeSummary(body), r.ok ? 'ok' : 'error');
|
||||
} else {
|
||||
setStatus(changeErrorText(verb, r.status, body, currentUnit(), r.statusText), 'error');
|
||||
setStatus(changeErrorText(`${verb} monitoring`, r.status, body, currentUnit(), r.statusText), 'error');
|
||||
}
|
||||
} catch (e) {
|
||||
// No reply is not "nothing sent": the request may have reached the unit.
|
||||
@@ -862,6 +922,7 @@ function clearCallHomeForm() {
|
||||
|
||||
async function readCallHome() {
|
||||
if (!devHost()) { setChStatus('Not connected.', 'error'); return; }
|
||||
if (serialMode()) { await readCallHomeBySerial(); return; }
|
||||
setChStatus('Reading call home config from device…');
|
||||
document.getElementById('ch-read-btn').disabled = true;
|
||||
try {
|
||||
@@ -2275,6 +2336,9 @@ document.getElementById('api-base').value = window.location.origin;
|
||||
for (const id of ['dev-serial', 'dev-host', 'dev-port']) {
|
||||
document.getElementById(id).addEventListener('input', () => { unitConfirmed = null; applyControls(); });
|
||||
}
|
||||
// New controls are wired here, not with onclick= in the HTML (no inline JS).
|
||||
document.getElementById('ch-on-btn').addEventListener('click', () => changeCallHome(true));
|
||||
document.getElementById('ch-off-btn').addEventListener('click', () => changeCallHome(false));
|
||||
applyControls();
|
||||
|
||||
// Reflect any persisted mic-unit preference in the header pill on load
|
||||
|
||||
@@ -28,7 +28,8 @@ NODE = shutil.which("node")
|
||||
pytestmark = pytest.mark.skipif(NODE is None, reason="node is not installed; the page-logic tests need it")
|
||||
|
||||
EXPORTS = ["seriesFromSerial", "unitQuery", "deviceUrl", "confirmedSeries", "controlsFor", "eventView", "settingsRows", "perIndexLive", "escapeHtml",
|
||||
"changeSummary", "downloadSummary", "firmwareLabel", "deviceErrorText", "changeErrorText", "serialPanes"]
|
||||
"changeSummary", "downloadSummary", "firmwareLabel", "deviceErrorText", "changeErrorText", "serialPanes",
|
||||
"callHomeRows"]
|
||||
|
||||
|
||||
def _block() -> str:
|
||||
@@ -108,7 +109,8 @@ def test_controls_confirmed_series3():
|
||||
|
||||
def test_controls_confirmed_series4():
|
||||
c = run(["controlsFor", [_with(S4, {"serial": "UM20147", "series": 4})]])[0]
|
||||
assert (c["hangup"], c["startStop"], c["diagnostics"], c["callHomeRead"]) == (True, True, False, False)
|
||||
# phase 4: by serial a Micromate's call-home reads through /device/call_home/state
|
||||
assert (c["hangup"], c["startStop"], c["diagnostics"], c["callHomeRead"]) == (True, True, False, True)
|
||||
|
||||
|
||||
def test_controls_confirmation_drops_when_the_serial_changes():
|
||||
@@ -124,11 +126,13 @@ def test_controls_a_legacy_identify_confirms_without_a_typed_serial():
|
||||
assert s == 3 and c["diagnostics"] is True and c["startStop"] is False # start/stop needs a serial
|
||||
|
||||
|
||||
def test_controls_writes_wait_for_phases_4_and_5():
|
||||
def test_controls_config_waits_for_phase_5_and_the_legacy_call_home_form_stays_off():
|
||||
for unit in (_with(S3, {"serial": "BE9441", "series": 3}), _with(S4, {"serial": "UM20147", "series": 4})):
|
||||
c = run(["controlsFor", [unit]])[0]
|
||||
assert c["configWrite"] is False and c["callHomeWrite"] is False
|
||||
assert c["reasons"] == {"configWrite": "Coming in phase 5 (#46)", "callHomeWrite": "Coming in phase 4"}
|
||||
assert c["reasons"] == {"configWrite": "Coming in phase 5 (#46)",
|
||||
"callHomeWrite": "By serial: use Call-home On / Off (audited). Other call-home "
|
||||
"fields wait for the THOR round."}
|
||||
|
||||
|
||||
def test_change_summary():
|
||||
@@ -272,10 +276,12 @@ def test_a_change_that_was_sent_is_not_called_failed():
|
||||
# #10: a ChangeUnconfirmed body carries `sent`; anything else is a real failure.
|
||||
sent = {"detail": "start monitoring was sent and acknowledged, but reading the state back failed: x "
|
||||
"-- audit record c7", "sent": "acknowledged", "audit_id": "c7"}
|
||||
r = run(["changeErrorText", ["Start", 504, sent, S3, "HTTP 504"]],
|
||||
["changeErrorText", ["Stop", 503, {**sent, "sent": "unknown"}, S3, "HTTP 503"]],
|
||||
["changeErrorText", ["Start", 504, {"detail": "the unit did not answer: no reply"}, S3, "HTTP 504"]],
|
||||
["changeErrorText", ["Stop", 409, {"detail": "not BE9441: BE12599 answered"}, S3, "HTTP 409"]])
|
||||
r = run(["changeErrorText", ["Start monitoring", 504, sent, S3, "HTTP 504"]],
|
||||
["changeErrorText", ["Stop monitoring", 503, {**sent, "sent": "unknown"}, S3, "HTTP 503"]],
|
||||
["changeErrorText", ["Start monitoring", 504, {"detail": "the unit did not answer: no reply"}, S3,
|
||||
"HTTP 504"]],
|
||||
["changeErrorText", ["Stop monitoring", 409, {"detail": "not BE9441: BE12599 answered"}, S3,
|
||||
"HTTP 409"]])
|
||||
assert r[0] == f"Start monitoring not confirmed: {sent['detail']}"
|
||||
assert r[1] == f"Stop monitoring not confirmed: {sent['detail']}"
|
||||
assert r[2] == f"Start monitoring failed: the unit did not answer: no reply — {HINT}"
|
||||
@@ -287,6 +293,37 @@ def test_serial_mode_hides_the_legacy_forms():
|
||||
# #6 / #12: by serial, settings are read-only until phase 5 -- no empty edit
|
||||
# form, no empty legacy tables; the settings box shows from the start.
|
||||
r = run(["serialPanes", [True, False]], ["serialPanes", [True, True]], ["serialPanes", [False, False]])
|
||||
assert r == [{"configForm": False, "settingsBox": True, "settingsPlaceholder": True, "legacyDeviceTables": False},
|
||||
{"configForm": False, "settingsBox": True, "settingsPlaceholder": False, "legacyDeviceTables": False},
|
||||
{"configForm": True, "settingsBox": False, "settingsPlaceholder": False, "legacyDeviceTables": True}]
|
||||
serial = {"configForm": False, "settingsBox": True, "legacyDeviceTables": False,
|
||||
"callHomeForm": False, "callHomeBox": True}
|
||||
legacy = {"configForm": True, "settingsBox": False, "settingsPlaceholder": False, "legacyDeviceTables": True,
|
||||
"callHomeForm": True, "callHomeBox": False}
|
||||
assert r == [{**serial, "settingsPlaceholder": True}, {**serial, "settingsPlaceholder": False}, legacy]
|
||||
|
||||
|
||||
|
||||
# ── Call home by serial (phase 4) ─────────────────────────────────────────────
|
||||
|
||||
def test_call_home_routes_need_a_serial():
|
||||
r = run(["deviceUrl", ["call_home_on", BLANK]], ["deviceUrl", ["call_home_on", S4]],
|
||||
["deviceUrl", ["call_home_off", S3]], ["deviceUrl", ["call_home_state", S4]])
|
||||
assert r[0] is None
|
||||
assert r[1] == {"method": "POST", "path": "/device/call_home/enable?serial=UM20147&host=h&tcp_port=9034"}
|
||||
assert r[2] == {"method": "POST", "path": "/device/call_home/disable?serial=BE9441&host=h&tcp_port=9034"}
|
||||
assert r[3] == {"method": "GET", "path": "/device/call_home/state?serial=UM20147&host=h&tcp_port=9034"}
|
||||
|
||||
|
||||
def test_call_home_change_needs_a_confirmed_series():
|
||||
r = run(["controlsFor", [S3]], ["controlsFor", [_with(S3, {"serial": "BE9441", "series": 3})]],
|
||||
["controlsFor", [_with(S4, {"serial": "UM20147", "series": 4})]],
|
||||
["controlsFor", [_with(BLANK, {"serial": "BE9441", "series": 3})]])
|
||||
assert [c["callHomeChange"] for c in r] == [False, True, True, False]
|
||||
|
||||
|
||||
def test_call_home_rows():
|
||||
r = run(["callHomeRows", [{"enabled": True, "dial_string": "RADIO RING", "series": 4}]],
|
||||
["callHomeRows", [{"enabled": False, "dial_string": None, "series": 3}]],
|
||||
["callHomeRows", [{"enabled": None, "dial_string": "RADIO RING", "series": 3,
|
||||
"detail": {"byte5": "0x07"}}]])
|
||||
assert r[0] == [["Call-home", "On"], ["Dial string", "RADIO RING"], ["Series", 4]]
|
||||
assert r[1] == [["Call-home", "Off"], ["Dial string", "—"], ["Series", 3]]
|
||||
assert r[2][0] == ["Call-home", "Unknown (byte 5 = 0x07)"]
|
||||
Reference in new issue
Block a user