-
Notifications
You must be signed in to change notification settings - Fork 1
/
hardware_helpers.py
executable file
·51 lines (37 loc) · 1.19 KB
/
hardware_helpers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!flask/bin/python
import json, sqlite3, time, datetime
def get_latest_temperatures():
query = """SELECT ID, TEMPERATURE, TIMESTAMP FROM TEMPERATURE ORDER BY TIMESTAMP DESC LIMIT 100;""";
conn = sqlite3.connect('temperature.db')
cur = conn.cursor()
cur.execute(query)
ts_list = []
temp_list = []
for row in cur:
id, temp, timestamp = row
# print type(timestamp)
# timestamp = time.mktime(timestamp.timetuple())
epochmills = time.mktime(datetime.datetime.strptime(timestamp, "%Y-%m-%d %H:%M:%S").timetuple())
temp_list += [temp, ]
ts_list += [epochmills, ]
cur.close()
conn.close()
response = {'ts_list' : ts_list, 'temp_list' : temp_list}
return response
def get_oven_temperature():
"""Get oven temperature (celsius) through hardware magic
@return: float
"""
past_temp = get_latest_temperatures()
latest_temp = past_temp['temp_list'][0]
return latest_temp
def get_oven_state():
"""Get state of oven
@return: One of ["on", "off", "error"]
"""
return "error"
def main():
print get_oven_temperature()
print get_latest_temperatures()
if __name__ == '__main__':
main()