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