summaryrefslogtreecommitdiff
path: root/watchos/InfiniSolar/InfiniSolar WatchKit Extension/InverterView.swift
diff options
context:
space:
mode:
authorEvgeny Zinoviev <me@ch1p.io>2023-01-04 04:04:03 +0300
committerEvgeny Zinoviev <me@ch1p.io>2023-01-04 04:04:03 +0300
commitbb32e56ca28bb43d5d5afef737f25e4725887725 (patch)
tree519388eb284adeb47744a9ebc334bdf9ff5444a6 /watchos/InfiniSolar/InfiniSolar WatchKit Extension/InverterView.swift
parentd549f428cbbd54c49a90f92928e670d373c4a0d9 (diff)
move watchos app sources here (which should be rewritten anyway, and usable only in very specific conditions)
Diffstat (limited to 'watchos/InfiniSolar/InfiniSolar WatchKit Extension/InverterView.swift')
-rw-r--r--watchos/InfiniSolar/InfiniSolar WatchKit Extension/InverterView.swift75
1 files changed, 75 insertions, 0 deletions
diff --git a/watchos/InfiniSolar/InfiniSolar WatchKit Extension/InverterView.swift b/watchos/InfiniSolar/InfiniSolar WatchKit Extension/InverterView.swift
new file mode 100644
index 0000000..779c144
--- /dev/null
+++ b/watchos/InfiniSolar/InfiniSolar WatchKit Extension/InverterView.swift
@@ -0,0 +1,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()
+ }
+}