summaryrefslogtreecommitdiff
path: root/watchos/InfiniSolar/InfiniSolar WatchKit Extension/PumpView.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/PumpView.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/PumpView.swift')
-rw-r--r--watchos/InfiniSolar/InfiniSolar WatchKit Extension/PumpView.swift60
1 files changed, 60 insertions, 0 deletions
diff --git a/watchos/InfiniSolar/InfiniSolar WatchKit Extension/PumpView.swift b/watchos/InfiniSolar/InfiniSolar WatchKit Extension/PumpView.swift
new file mode 100644
index 0000000..270996d
--- /dev/null
+++ b/watchos/InfiniSolar/InfiniSolar WatchKit Extension/PumpView.swift
@@ -0,0 +1,60 @@
+//
+// MainPumpView.swift
+// InfiniSolar WatchKit Extension
+//
+// Created by Evgeny Zinoviev on 09.08.2021.
+//
+
+import SwiftUI
+
+struct PumpView: View {
+ @ObservedObject var state = PumpState()
+
+ var body: some View {
+ VStack(alignment: .leading) {
+ Text("Water pump")
+ .font(.title2)
+ .fontWeight(.thin)
+ Spacer().frame(height: 10)
+
+ if self.state.loading == true {
+ Text("Loading...")
+ .fontWeight(.thin)
+ }
+
+ else if self.state.error == true {
+ Text("Connection error.")
+ }
+
+ else {
+ if self.state.isEnabled == true {
+ Text("The pump is ").fontWeight(.thin)
+ + Text("turned on")
+ Spacer().frame(height: 10)
+ Button(self.state.setting ? "..." : "Turn off") {
+ self.state.setState(on: false)
+ }
+ } else {
+ Text("The pump is ").fontWeight(.thin)
+ + Text("turned off")
+ Spacer().frame(height: 10)
+ Button(self.state.setting ? "..." : "Turn on") {
+ self.state.setState(on: true)
+ }
+ }
+ }
+ }
+ .onAppear() {
+ self.state.fetch()
+ }
+ .onDisappear() {
+ self.state.abort()
+ }
+ }
+}
+
+struct PumpView_Previews: PreviewProvider {
+ static var previews: some View {
+ PumpView()
+ }
+}