| 1 |
// MeterMappingDebugView.swift |
|
| 2 |
// USB Meter |
|
| 3 |
// |
|
| 4 |
// Created by Codex on 2026. |
|
| 5 |
// |
|
| 6 | ||
| 7 |
import SwiftUI |
|
| 8 | ||
| 9 |
struct MeterMappingDebugView: View {
|
|
| 10 |
@State private var records: [MeterNameRecord] = [] |
|
| 11 |
private let store = MeterNameStore.shared |
|
| 12 |
private let changePublisher = NotificationCenter.default.publisher(for: .meterNameStoreDidChange) |
|
| 13 | ||
| 14 |
var body: some View {
|
|
| 15 |
List(records) { record in
|
|
| 16 |
VStack(alignment: .leading, spacing: 6) {
|
|
| 17 |
Text(record.customName) |
|
| 18 |
.font(.headline) |
|
| 19 |
Text(record.macAddress) |
|
| 20 |
.font(.caption.monospaced()) |
|
| 21 |
.foregroundColor(.secondary) |
|
| 22 |
HStack {
|
|
| 23 |
Text("TC66 unit:")
|
|
| 24 |
.font(.caption.weight(.semibold)) |
|
| 25 |
Text(record.temperatureUnit) |
|
| 26 |
.font(.caption.monospaced()) |
|
| 27 |
.foregroundColor(.blue) |
|
| 28 |
} |
|
| 29 |
} |
|
| 30 |
.padding(.vertical, 8) |
|
| 31 |
} |
|
| 32 |
.listStyle(.insetGrouped) |
|
| 33 |
.navigationTitle("Meter Name Mapping")
|
|
| 34 |
.onAppear(perform: reload) |
|
| 35 |
.onReceive(changePublisher) { _ in reload() }
|
|
| 36 |
.toolbar {
|
|
| 37 |
Button("Refresh") {
|
|
| 38 |
reload() |
|
| 39 |
} |
|
| 40 |
} |
|
| 41 |
} |
|
| 42 | ||
| 43 |
private func reload() {
|
|
| 44 |
records = store.allRecords().map { record in
|
|
| 45 |
MeterNameRecord( |
|
| 46 |
id: record.id, |
|
| 47 |
macAddress: record.macAddress, |
|
| 48 |
customName: record.customName ?? "<unnamed>", |
|
| 49 |
temperatureUnit: record.temperatureUnit ?? "n/a" |
|
| 50 |
) |
|
| 51 |
} |
|
| 52 |
} |
|
| 53 |
} |
|
| 54 | ||
| 55 |
private struct MeterNameRecord: Identifiable {
|
|
| 56 |
let id: String |
|
| 57 |
let macAddress: String |
|
| 58 |
let customName: String |
|
| 59 |
let temperatureUnit: String |
|
| 60 |
} |