Skip to content

Commit 4f8184b

Browse files
brentrubrentru
authored andcommitted
refactor handle_pump a bit
1 parent 3241747 commit 4f8184b

1 file changed

Lines changed: 6 additions & 9 deletions

File tree

PyPortal_GCP_IOT_Planter/code.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -112,22 +112,19 @@ def handle_pump(command):
112112
"""
113113
pump_time = command['pump_time']
114114
pump_status = command['pump']
115-
if pump_status == 0:
116-
print("Turning pump off")
117-
water_pump.value = False
118-
else:
119-
print("Turning pump on for {} seconds...", pump_time)
115+
if pump_status == 1:
116+
print("Turning pump on for {} seconds...".format(pump_time))
120117
start_pump = time.monotonic()
121118
while True:
122119
now = time.monotonic()
123120
if now - start_pump > pump_time:
124-
# Turn the pump off
125-
print("Turning pump off")
126-
water_pump.value = False
121+
# Timer expired, leave the loop
122+
print("Plant watered!")
127123
break
128124
else:
129125
initial = now
130-
print("pump off")
126+
print("Turning pump off")
127+
water_pump.value = False
131128

132129
# Initialize Google Cloud IoT Core interface
133130
google_iot = Cloud_Core(esp, secrets)

0 commit comments

Comments
 (0)