Commit 87f9bcd5 authored by Kristian Tan's avatar Kristian Tan

Haandle no on time

parent 3e377690
...@@ -74,16 +74,17 @@ def toggle_pin(change_pin): ...@@ -74,16 +74,17 @@ def toggle_pin(change_pin):
message = "Turned " + device_name message = "Turned " + device_name
if GPIO.input(change_pin) == 0: if GPIO.input(change_pin) == 0:
message += " off." message += " off."
uptime = datetime.now() - pins[change_pin]['on_time'] if pins[change_pin]['on_time'] is not None:
uptime = datetime.strptime(uptime, '%b %d %Y %I:%M%p') uptime = datetime.now() - pins[change_pin]['on_time']
date = datetime.strptime(pins[change_pin]['on_time'], '%b %d %Y %I:%M%p') uptime = datetime.strptime(uptime, '%b %d %Y %I:%M%p')
d = DailyUsage(date=date, hours=uptime) date = datetime.strptime(pins[change_pin]['on_time'], '%b %d %Y %I:%M%p')
db.session.add(d) d = DailyUsage(date=date, hours=uptime)
db.session.commit() db.session.add(d)
pins[change_pin]['on_time'] = None db.session.commit()
print("==========") pins[change_pin]['on_time'] = None
print(DailyUsage.query.all()) print("==========")
print("==========") print(DailyUsage.query.all())
print("==========")
else: else:
message += " on." message += " on."
pins[change_pin]['on_time'] = datetime.now() pins[change_pin]['on_time'] = datetime.now()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment