USB-Meter / USB Meter / Views / MeterMappingDebugView.swift
Newer Older
82 lines | 2.773kb
Bogdan Timofte authored a week ago
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 {
Bogdan Timofte authored a week ago
15
        List {
16
            Section {
17
                VStack(alignment: .leading, spacing: 8) {
18
                    Text(store.currentCloudAvailability.helpTitle)
19
                        .font(.headline)
20
                    Text("This screen is limited to meter sync metadata visible on this device through the local store and iCloud KVS.")
21
                        .font(.caption)
22
                        .foregroundColor(.secondary)
23
                    Text(store.currentCloudAvailability.helpMessage)
24
                        .font(.caption)
25
                        .foregroundColor(.secondary)
Bogdan Timofte authored a week ago
26
                }
Bogdan Timofte authored a week ago
27
                .padding(.vertical, 6)
28
            } header: {
29
                Text("Sync Status")
30
            }
31

            
32
            Section {
33
                ForEach(records) { record in
34
                    VStack(alignment: .leading, spacing: 6) {
35
                        Text(record.customName)
36
                            .font(.headline)
37
                        Text(record.macAddress)
38
                            .font(.caption.monospaced())
39
                            .foregroundColor(.secondary)
40
                        HStack {
41
                            Text("TC66 unit:")
42
                                .font(.caption.weight(.semibold))
43
                            Text(record.temperatureUnit)
44
                                .font(.caption.monospaced())
45
                                .foregroundColor(.blue)
46
                        }
47
                    }
48
                    .padding(.vertical, 8)
49
                }
50
            } header: {
51
                Text("KVS Meter Mapping")
Bogdan Timofte authored a week ago
52
            }
53
        }
54
        .listStyle(.insetGrouped)
Bogdan Timofte authored a week ago
55
        .navigationTitle("Meter Sync Debug")
Bogdan Timofte authored a week ago
56
        .onAppear(perform: reload)
57
        .onReceive(changePublisher) { _ in reload() }
58
        .toolbar {
59
            Button("Refresh") {
60
                reload()
61
            }
62
        }
63
    }
64

            
65
    private func reload() {
66
        records = store.allRecords().map { record in
67
            MeterNameRecord(
68
                id: record.id,
69
                macAddress: record.macAddress,
70
                customName: record.customName ?? "<unnamed>",
71
                temperatureUnit: record.temperatureUnit ?? "n/a"
72
            )
73
        }
74
    }
75
}
76

            
77
private struct MeterNameRecord: Identifiable {
78
    let id: String
79
    let macAddress: String
80
    let customName: String
81
    let temperatureUnit: String
82
}