Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
IoTSmartMeter
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
kristian.tan
IoTSmartMeter
Commits
c7a12842
Commit
c7a12842
authored
Nov 13, 2019
by
Kristian Tan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added field for on date
parent
e08b247b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
5 deletions
+5
-5
app.py
app.py
+5
-5
No files found.
app.py
View file @
c7a12842
...
@@ -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
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment