blob: 779c144e811463504d6d395a94f36ed119b409f8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
//
// MainInverterView.swift
// InfiniSolar WatchKit Extension
//
// Created by Evgeny Zinoviev on 08.08.2021.
//
import SwiftUI
struct InverterView: View {
@ObservedObject var state = InverterState()
@State var isPresented = false
var body: some View {
VStack(alignment: .leading) {
Text("Inverter")
.font(.title2)
.fontWeight(.thin)
Spacer().frame(height: 10)
// inverter data
if self.state.fetchError == true {
Text("Error while fetching status.")
.multilineTextAlignment(.leading)
Spacer().frame(height: 10)
Button(action:{
self.state.startFetching()
}) {
Text("Retry")
}
// } else if !self.state.status.hasData() {
// ProgressView()
// .progressViewStyle(CircularProgressViewStyle())
} else {
Group {
Text(String(self.state.status.batteryVoltage) + " V")
+ Text(" ≈ " + String(self.state.status.batteryCapacity) + " %").fontWeight(.thin)
Spacer().frame(height: 1)
Text("Active load is ").fontWeight(.thin)
+ Text(String(self.state.status.activePower) + " Wh")
if self.state.status.pvInputPower > 0 {
Divider()
Text("Consuming ").fontWeight(.thin)
+ Text(String(self.state.status.pvInputPower) + " Wh")
+ Text(" from panels").fontWeight(.thin)
}
Spacer().frame(height: 15)
NavigationLink(destination: GenerationView(), isActive: $isPresented) {
Text("Generation stats")
.onTapGesture{
self.isPresented = true
self.state.stopFetching()
}
}
}
}
}
.onAppear() {
self.state.startFetching()
}
}
}
struct InverterView_Previews: PreviewProvider {
static var previews: some View {
InverterView()
}
}
|