Address review findings for the proximity-pairing PR

Correctness:
- Pair-glasses flows no longer strand the app in the manual-disconnected
  state: the pre-scan disconnect is followed by resumeAutoReconnect(), and
  the config page's scan hand-off drops the live link too.
- The mixed-arms serial warning is reachable now: pairs() groups by the
  canonical serial key, and a lone left + lone right with different serials
  get the mismatch warning on both rows (it previously required two
  different serials inside one serial-keyed group, which cannot happen).
- A selected pair that degrades to one arm (prune while the page is open)
  is deselected, and Save never pads a missing arm from stored addresses.
- DiscoveryAggregator.ingest no longer lets a bonded re-emit or split
  advertisement overwrite the note/name/flag learned from a full
  advertisement, and reclassifies split reports using remembered fields so
  a nameless half doesn't drop the arm.
- estimateProximity ignores the advertised TX Power Level (radiated power,
  not measured-power-at-1m); the calibration table is the only reference.
- Saving a ring without a glasses pair updates the stored identity's ring
  name/address instead of leaving the previous ring on record.
- Ring detection requires the stock "EVEN R1" name prefix in both the TS
  classifier and the Java pre-filter; a bare "R1" substring matched
  unrelated devices, and ring rows are always selectable.
- One-shot scans keep every sample (buildAddressSet merges them through
  DiscoveryAggregator), and flash-flow address resolution takes left/right
  from one serial-joined complete pair instead of latest-per-role.

Lifecycle:
- The pairing scan and its refresh timer pause on app suspend and resume
  with the app, and the model's app-event hooks are detached when the page
  is left for good.

Cleanup:
- One MAC normalizer (even-advertisement.normalizeMacAddress, re-exported
  by device-addresses), used for the ring "Yours" comparison too.
- One serial-equality definition (serialKey/serialsMatch); the containment
  fallback in isPreviouslyPaired is gone.
- Shared formatErrorMessage replaces five per-view-model copies; shared
  hex-util replaces the duplicate TS hex codecs; one Java bytesToHex in
  FaceclawFirmwareUtil replaces three hand-rolled encoders.
- glassesRow/ringRow share a presentation-base helper; dead row address
  fields, the constant glassesSectionVisibility, the identical-branch
  status ternary, and zoneRank/ZONE_ORDER are removed.
- .gitignore now actually covers .test-build/ as tests/README claims.

UI:
- Dark-mode styles for the pairing page: readable instructions, dark-gray
  cards with consistent light text; light mode keeps its current look.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016ZqzwmRQ3HQxasBz5rYyZV
This commit is contained in:
James BabcockandClaude Fable 5 committed 2026-08-23 15:28:59 -07:00
1 parent ee022cdc84
commit 17182532f4
24 files changed
+537 -250

No files matched your search

+22 -22
View File
@@ -23,37 +23,37 @@ const {
const near = (a, b, eps) => Math.abs(a - b) <= eps;
test("distance falls as signal weakens", () => {
const close = estimateProximity(-40, null, GLASSES_CALIBRATION);
const mid = estimateProximity(-70, null, GLASSES_CALIBRATION);
const farAway = estimateProximity(-95, null, GLASSES_CALIBRATION);
const close = estimateProximity(-40, GLASSES_CALIBRATION);
const mid = estimateProximity(-70, GLASSES_CALIBRATION);
const farAway = estimateProximity(-95, GLASSES_CALIBRATION);
assert.ok(close.meters < mid.meters);
assert.ok(mid.meters < farAway.meters);
});
test("the reference power reads as one metre", () => {
const estimate = estimateProximity(GLASSES_CALIBRATION.txPowerAtOneMeter, null, GLASSES_CALIBRATION);
const estimate = estimateProximity(GLASSES_CALIBRATION.txPowerAtOneMeter, GLASSES_CALIBRATION);
assert.ok(near(estimate.meters, 1.0, 0.001));
assert.equal(estimate.zone, "near");
});
test("estimates stay inside a plausible band", () => {
assert.ok(near(estimateProximity(20, null, GLASSES_CALIBRATION).meters, MINIMUM_METERS, 0.0001));
assert.ok(near(estimateProximity(-127, null, GLASSES_CALIBRATION).meters, MAXIMUM_METERS, 0.0001));
assert.ok(near(estimateProximity(20, GLASSES_CALIBRATION).meters, MINIMUM_METERS, 0.0001));
assert.ok(near(estimateProximity(-127, GLASSES_CALIBRATION).meters, MAXIMUM_METERS, 0.0001));
});
test("an advertised TX power overrides the calibration", () => {
const assumed = estimateProximity(-60, null, GLASSES_CALIBRATION);
const measured = estimateProximity(-60, -50, GLASSES_CALIBRATION);
// A device that says it transmits at -50 dBm at 1 m, heard at -60, is further
// away than one assumed to transmit at -62 — and it is trusted more.
assert.ok(measured.meters > assumed.meters);
assert.ok(measured.confidence > assumed.confidence);
test("the calibration table is the only reference power", () => {
// An advertised BLE "TX Power Level" is radiated power at the antenna, not a
// measured power at 1 m; estimateProximity deliberately takes no TX power
// argument, so a 0 dBm advertisement cannot inflate the estimate. The API
// itself enforces it — this pins the arity so a txPower parameter cannot
// quietly return.
assert.equal(estimateProximity.length, 2);
});
test("no signal yields no estimate (127 is the unavailable sentinel)", () => {
assert.equal(estimateProximity(null, null, GLASSES_CALIBRATION), null);
assert.equal(estimateProximity(undefined, null, GLASSES_CALIBRATION), null);
assert.equal(estimateProximity(127, null, GLASSES_CALIBRATION), null);
assert.equal(estimateProximity(null, GLASSES_CALIBRATION), null);
assert.equal(estimateProximity(undefined, GLASSES_CALIBRATION), null);
assert.equal(estimateProximity(127, GLASSES_CALIBRATION), null);
});
test("zones and their boundaries", () => {
@@ -67,15 +67,15 @@ test("zones and their boundaries", () => {
});
test("weak signals are marked as approximate", () => {
const strong = estimateProximity(-45, -60, GLASSES_CALIBRATION);
const weak = estimateProximity(-95, null, GLASSES_CALIBRATION);
const strong = estimateProximity(-45, GLASSES_CALIBRATION);
const weak = estimateProximity(-95, GLASSES_CALIBRATION);
assert.ok(!formatDistance(strong).startsWith("~"));
assert.ok(formatDistance(weak).startsWith("~"));
assert.ok(weak.confidence < strong.confidence);
});
test("distance formatting is rounded hard", () => {
const centimetres = estimateProximity(-30, -60, GLASSES_CALIBRATION);
const centimetres = estimateProximity(-30, GLASSES_CALIBRATION);
assert.ok(formatDistance(centimetres).includes("cm"), formatDistance(centimetres));
assert.equal(formatDistance({ meters: 2.34, confidence: 1, zone: "near" }), "2.3 m");
assert.equal(formatDistance({ meters: 42.6, confidence: 1, zone: "distant" }), "43 m");
@@ -83,7 +83,7 @@ test("distance formatting is rounded hard", () => {
});
const device = (id, rssi) => ({ id, rssi });
const estimate = (d) => estimateProximity(d.rssi, null, GLASSES_CALIBRATION);
const estimate = (d) => estimateProximity(d.rssi, GLASSES_CALIBRATION);
const byId = (d) => d.id;
test("glasses sort closest first", () => {
@@ -106,7 +106,7 @@ test("equal signals keep a stable order", () => {
test("ring and glasses are calibrated separately", () => {
// The ring's antenna reads weaker than the glasses at the same distance, so
// the same RSSI must not be reported as the same distance for both.
const ring = estimateProximity(-70, null, RING_CALIBRATION);
const glasses = estimateProximity(-70, null, GLASSES_CALIBRATION);
const ring = estimateProximity(-70, RING_CALIBRATION);
const glasses = estimateProximity(-70, GLASSES_CALIBRATION);
assert.ok(ring.meters < glasses.meters);
});
+9 -2
View File
@@ -19,7 +19,7 @@ const {
ringMacWireBytes,
extractRingSerialSuffix,
classifyAdvertisement,
normalizeAddress,
normalizeMacAddress,
EVEN_COMPANY_IDENTIFIER,
} = require("../.test-build/app/g2/even-advertisement.js");
@@ -80,7 +80,7 @@ test("address codec crosses wire/human order exactly once", () => {
assert.equal(bytesToHex(wire), "E26EB5D27FDA");
assert.equal(humanReadableAddressFromWireBytes(wire), "DA:7F:D2:B5:6E:E2");
assert.equal(wireBytesFromHumanReadableAddress("nope"), null);
assert.equal(normalizeAddress("e0ecb61412e0"), "E0:EC:B6:14:12:E0");
assert.equal(normalizeMacAddress("e0ecb61412e0"), "E0:EC:B6:14:12:E0");
});
test("ring name suffix octets parse from the full name and the bare id", () => {
@@ -155,3 +155,10 @@ test("ignores unrelated advertisers", () => {
assert.equal(classifyAdvertisement(raw({ name: "Pixel Buds", manufacturerData: "E000010203" })), null);
assert.equal(classifyAdvertisement(raw({ name: "", manufacturerData: "" })), null);
});
test("a bare R1 substring is not a ring — only the stock EVEN R1 prefix is", () => {
assert.equal(classifyAdvertisement(raw({ name: "Oppo Enco R1", manufacturerData: "" })), null);
assert.equal(classifyAdvertisement(raw({ name: "R1 Speaker", manufacturerData: "" })), null);
const ad = classifyAdvertisement(raw({ address: "DA:7F:D2:B5:6E:E2", name: "EVEN R1_B56EE2", manufacturerData: "" }));
assert.equal(ad.role, "ring");
});
+46 -4
View File
@@ -156,7 +156,7 @@ test("rings are grouped separately and sorted closest first", () => {
const row = ringRow(aggregator.rings()[1]);
assert.equal(row.modelTitle, "Even R1");
assert.match(row.deviceName, /140137/);
assert.equal(row.ringAddress, "DA:7F:D2:B5:6E:E2");
assert.equal(aggregator.rings()[1].advertisement.address, "DA:7F:D2:B5:6E:E2");
});
test("nearest requires a clear signal lead", () => {
@@ -227,11 +227,53 @@ test("frame C resolves to the generic shot with the swatch still available", ()
test("an incomplete pair cannot be selected and says which arm is missing", () => {
const aggregator = new DiscoveryAggregator();
aggregator.ingest(RIGHT);
const row = glassesRow(aggregator.pairs()[0]);
const pair = aggregator.pairs()[0];
const row = glassesRow(pair);
assert.equal(row.canSelect, false);
assert.match(row.armsSummary, /Only the right arm/);
assert.equal(row.rightAddress, "E0:12:14:8D:6E:3C");
assert.equal(row.leftAddress, "");
assert.equal(pair.right.address, "E0:12:14:8D:6E:3C");
assert.equal(pair.left, null);
});
test("a lone left and lone right with different serials warn about mixed arms", () => {
const aggregator = new DiscoveryAggregator();
aggregator.ingest(LEFT);
aggregator.ingest(OTHER_RIGHT);
for (const pair of aggregator.pairs()) {
const row = glassesRow(pair);
assert.match(row.warning, /arms from two different pairs/);
assert.match(row.warning, /S211GBBC180304/);
assert.match(row.warning, /S211GCBC300403/);
assert.equal(row.canSelect, false);
}
});
test("a bonded re-emit does not overwrite live scan notes or name", () => {
const aggregator = new DiscoveryAggregator();
aggregator.ingest(LEFT);
// Every pairing-page re-entry replays bonded devices: no manufacturer data,
// possibly stale cached name. That must not turn a fully-parsed row into
// "serial unknown" or swap in the stale name.
aggregator.ingest({ ...LEFT, name: "Even G2_32_L_0LDCAF", manufacturerData: "", rssi: null, bonded: true, source: "paired", seenAtMs: 2000 });
const pair = aggregator.pairs()[0];
assert.equal(pair.serial, "S211GBBC180304");
assert.equal(pair.left.name, LEFT.name);
assert.equal(pair.left.note, null);
assert.equal(glassesRow(pair).warning, "");
});
test("a split report without the name keeps the arm by merging earlier traffic", () => {
const aggregator = new DiscoveryAggregator();
aggregator.ingest(LEFT);
// Android sometimes delivers the ADV report (manufacturer data, no name)
// separately from the scan response carrying the name.
const merged = aggregator.ingest({ ...LEFT, name: "", seenAtMs: 2000 });
assert.ok(merged, "the nameless half must not drop the arm");
assert.equal(merged.role, "left");
const pair = aggregator.pairs()[0];
assert.equal(pair.completeness, "left-only");
assert.equal(pair.left.name, LEFT.name);
assert.equal(pair.left.seenAtMs, 2000);
});
test("an embedded-MAC mismatch is surfaced as a warning", () => {