Carve out some dead code

This commit is contained in:
Jack Kingsman
2026-02-24 18:40:35 -08:00
parent f7f696bf10
commit b1a0456a05
6 changed files with 3 additions and 143 deletions
+1 -74
View File
@@ -1,80 +1,7 @@
import { describe, it, expect } from 'vitest';
import { RADIO_PRESETS, detectPreset, findPreset } from '../utils/radioPresets';
import { RADIO_PRESETS } from '../utils/radioPresets';
describe('Radio Presets', () => {
describe('detectPreset', () => {
it('detects USA/Canada preset', () => {
expect(detectPreset(910.525, 62.5, 7, 5)).toBe('USA/Canada');
});
it('detects Australia preset', () => {
expect(detectPreset(915.8, 250, 10, 5)).toBe('Australia');
});
it('detects Australia (narrow) preset', () => {
expect(detectPreset(916.575, 62.5, 7, 8)).toBe('Australia (narrow)');
});
it('detects EU/UK/Switzerland Long Range preset', () => {
expect(detectPreset(869.525, 250, 11, 5)).toBe('EU/UK/Switzerland Long Range');
});
it('detects EU/UK/Switzerland Medium Range preset', () => {
expect(detectPreset(869.525, 250, 10, 5)).toBe('EU/UK/Switzerland Medium Range');
});
it('detects EU/UK/Switzerland Narrow preset', () => {
expect(detectPreset(869.618, 62.5, 8, 8)).toBe('EU/UK/Switzerland Narrow');
});
it('returns custom for non-matching values', () => {
expect(detectPreset(900, 250, 10, 5)).toBe('custom');
});
it('returns custom when one value differs', () => {
// Same as USA/Canada but with different SF
expect(detectPreset(910.525, 62.5, 8, 5)).toBe('custom');
});
it('returns custom when bandwidth differs', () => {
// Same as USA/Canada but with different BW
expect(detectPreset(910.525, 125, 7, 5)).toBe('custom');
});
it('returns custom when coding rate differs', () => {
// Same as USA/Canada but with different CR
expect(detectPreset(910.525, 62.5, 7, 6)).toBe('custom');
});
});
describe('findPreset', () => {
it('finds preset by exact name', () => {
const preset = findPreset('USA/Canada');
expect(preset).toBeDefined();
expect(preset?.freq).toBe(910.525);
expect(preset?.bw).toBe(62.5);
expect(preset?.sf).toBe(7);
expect(preset?.cr).toBe(5);
});
it('returns undefined for unknown preset', () => {
expect(findPreset('Unknown Preset')).toBeUndefined();
});
it('returns undefined for custom', () => {
expect(findPreset('custom')).toBeUndefined();
});
});
describe('preset round-trip', () => {
it('all presets can be detected after being applied', () => {
for (const preset of RADIO_PRESETS) {
const detected = detectPreset(preset.freq, preset.bw, preset.sf, preset.cr);
expect(detected).toBe(preset.name);
}
});
});
describe('preset values are valid LoRa parameters', () => {
it('all frequencies are in valid ISM bands', () => {
for (const preset of RADIO_PRESETS) {
-14
View File
@@ -25,17 +25,3 @@ export const RADIO_PRESETS: RadioPreset[] = [
{ name: 'Vietnam', freq: 920.25, bw: 250, sf: 11, cr: 5 },
];
/** Detect which preset matches the given radio parameters, or 'custom' if none match. */
export function detectPreset(freq: number, bw: number, sf: number, cr: number): string {
for (const preset of RADIO_PRESETS) {
if (preset.freq === freq && preset.bw === bw && preset.sf === sf && preset.cr === cr) {
return preset.name;
}
}
return 'custom';
}
/** Find a preset by exact name. */
export function findPreset(name: string): RadioPreset | undefined {
return RADIO_PRESETS.find((p) => p.name === name);
}
-15
View File
@@ -210,21 +210,6 @@ export function getLinkId<
};
}
export function findContactByPrefix(prefix: string, contacts: Contact[]): Contact | null {
const normalized = prefix.toLowerCase();
const matches = contacts.filter((c) => c.public_key.toLowerCase().startsWith(normalized));
return matches.length === 1 ? matches[0] : null;
}
export function findContactsByPrefix(prefix: string, contacts: Contact[]): Contact[] {
const normalized = prefix.toLowerCase();
return contacts.filter((c) => c.public_key.toLowerCase().startsWith(normalized));
}
export function findContactByName(name: string, contacts: Contact[]): Contact | null {
return contacts.find((c) => c.name === name) || null;
}
export function getNodeType(contact: Contact | null | undefined): NodeType {
return contact?.type === CONTACT_TYPE_REPEATER ? 'repeater' : 'client';
}