Commit c7a12842 authored by Kristian Tan's avatar Kristian Tan

Added field for on date

parent e08b247b
...@@ -45,7 +45,7 @@ if latest_entry and latest_entry.date == datetime.today(): ...@@ -45,7 +45,7 @@ if latest_entry and latest_entry.date == datetime.today():
# Create dictionary to store pin info # Create dictionary to store pin info
pins = { pins = {
25: {'name': 'Light', 'state': GPIO.LOW, 'on_time': None} 25: {'name': 'Light', 'state': GPIO.LOW, 'on_time': None, 'on_date': None}
} }
# Setup each pin # Setup each pin
...@@ -87,10 +87,7 @@ def toggle_pin(change_pin): ...@@ -87,10 +87,7 @@ def toggle_pin(change_pin):
# Get the elapsed time and strip away milliseconds # Get the elapsed time and strip away milliseconds
elapsed = int((datetime.now() - start_time).total_seconds()) elapsed = int((datetime.now() - start_time).total_seconds())
# Format the time start_date = pins[change_pin]['on_date']
start_date_string = datetime.strftime(start_time, '%Y-%m-%d')
# Create datetime object from formatted time
start_date = datetime.strptime(start_date_string, '%Y-%m-%d')
# If there is already an entry for today, update on time # If there is already an entry for today, update on time
if latest_entry and latest_entry.date == start_date: if latest_entry and latest_entry.date == start_date:
...@@ -102,9 +99,12 @@ def toggle_pin(change_pin): ...@@ -102,9 +99,12 @@ def toggle_pin(change_pin):
db.session.commit() db.session.commit()
pins[change_pin]['on_time'] = None pins[change_pin]['on_time'] = None
pins[change_pin]['on_date'] = None
else: else:
message += " on." message += " on."
pins[change_pin]['on_time'] = datetime.now() pins[change_pin]['on_time'] = datetime.now()
pins[change_pin]['on_date'] = datetime.today()
for pin in pins: for pin in pins:
pins[pin]['state'] = GPIO.input(pin) pins[pin]['state'] = GPIO.input(pin)
......
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