Files
VanAligneiOS/CamperMonitorWatch/Views/WatchDeviceDetailView.swift
2026-09-04 21:30:51 +02:00

70 lines
2.6 KiB
Swift
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import SwiftUI
/// Alle Werte eines Geräts. Am iPhone stehen hier zusätzlich Verlauf und
/// Diagnose auf der Uhr wäre beides unlesbar und ist deshalb weggelassen.
struct WatchDeviceDetailView: View {
let deviceID: UUID
@Environment(PhoneLink.self) private var link
private var device: WatchDevice? {
link.payload?.devices.first { $0.id == deviceID }
}
var body: some View {
List {
if let device {
/*if let fridge = device.fridge {
WatchFridgeControls(deviceID: device.id, fridge: fridge)
}*/
Section {
ForEach(device.snapshot?.metrics.filter { $0.value != nil } ?? []) { metric in
LabeledContent(metric.label) {
Text(metric.formattedWithUnit)
.monospacedDigit()
}
.font(.footnote)
}
} header: {
Text("Messwerte")
}
Section {
if let fault = device.snapshot?.fault {
Label(fault, systemImage: "exclamationmark.triangle.fill")
.font(.caption2)
.foregroundStyle(.red)
}
if let state = device.snapshot?.state {
Text(state).font(.caption2)
}
ForEach(device.snapshot?.offReasons ?? [], id: \.self) { reason in
Text(reason)
.font(.caption2)
.foregroundStyle(.secondary)
}
Label(device.link.label, systemImage: "antenna.radiowaves.left.and.right")
.font(.caption2)
.foregroundStyle(.secondary)
}
} else {
Text("Gerät ist nicht mehr im Fahrzeugprofil.")
.font(.footnote)
.foregroundStyle(.secondary)
}
}
.navigationTitle(device?.name ?? "Gerät")
// Die Kühlbox wird nur verbunden, solange jemand sie ansieht. Das gilt
// auch von hier aus das iPhone verbindet auf Zuruf.
.onAppear {
//guard device?.fridge != nil else { return }
//link.send(.fridgeSession(device: deviceID, wanted: true))
}
.onDisappear {
// guard device?.fridge != nil else { return }
//link.send(.fridgeSession(device: deviceID, wanted: false))
}
}
}