ui: humanize door/vibration/magnet status labels
Replace raw snake_case values (magnet: no_magnet) with proper labels: - Door: Closed / Opened / Opening / Closing - Vibration: Idle / Vibration! - Magnet: None / Detected! - Event count singular/plural correction (1 event vs N events)
This commit is contained in:
@@ -190,16 +190,32 @@ function rssiTone(rssi) {
|
|||||||
return 'rose';
|
return 'rose';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const HUMAN = {
|
||||||
|
door_status: {
|
||||||
|
closed: 'Closed', opened: 'Opened',
|
||||||
|
opening_alert: 'Opening', closing_alert: 'Closing',
|
||||||
|
},
|
||||||
|
vibration_status: { no_vibration: 'Idle', vibration_detected: 'Vibration!' },
|
||||||
|
magnet_status: { no_magnet: 'None', magnet_detected: 'Detected!' },
|
||||||
|
};
|
||||||
|
|
||||||
|
function humanize(field, value) {
|
||||||
|
return HUMAN[field]?.[value] ?? value;
|
||||||
|
}
|
||||||
|
|
||||||
function summaryLine(d) {
|
function summaryLine(d) {
|
||||||
if (!d) return '—';
|
if (!d) return '—';
|
||||||
const p = [];
|
const p = [];
|
||||||
if ('temperature_c' in d) p.push(`${d.temperature_c}°C`);
|
if ('temperature_c' in d) p.push(`${d.temperature_c}°C`);
|
||||||
if ('humidity_pct' in d) p.push(`${d.humidity_pct}%`);
|
if ('humidity_pct' in d) p.push(`${d.humidity_pct}%`);
|
||||||
if ('brightness_lux' in d) p.push(`${d.brightness_lux} lux`);
|
if ('brightness_lux' in d) p.push(`${d.brightness_lux} lux`);
|
||||||
if ('door_status' in d) p.push(`door: ${d.door_status}`);
|
if ('door_status' in d) p.push(humanize('door_status', d.door_status));
|
||||||
if ('vibration_status' in d) p.push(`vibration: ${d.vibration_status}`);
|
if ('vibration_status' in d) p.push(humanize('vibration_status', d.vibration_status));
|
||||||
if ('magnet_status' in d) p.push(`magnet: ${d.magnet_status}`);
|
if ('magnet_status' in d) p.push(humanize('magnet_status', d.magnet_status));
|
||||||
if ('event_count' in d && d.mode_id > 2) p.push(`${d.event_count} events`);
|
if ('event_count' in d && d.mode_id > 2) {
|
||||||
|
const label = d.event_count === 1 ? 'event' : 'events';
|
||||||
|
p.push(`${d.event_count} ${label}`);
|
||||||
|
}
|
||||||
if ('fw_major' in d) p.push(`fw ${d.fw_major}.${d.fw_minor}`);
|
if ('fw_major' in d) p.push(`fw ${d.fw_major}.${d.fw_minor}`);
|
||||||
if (p.length === 0) p.push('heartbeat');
|
if (p.length === 0) p.push('heartbeat');
|
||||||
return p.join(' · ');
|
return p.join(' · ');
|
||||||
|
|||||||
Reference in New Issue
Block a user