-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
130 lines (101 loc) · 3.08 KB
/
main.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
from flask import Blueprint, render_template
from flask_login import login_required, current_user
from . import db
from .models import User, EntryInfo
main = Blueprint(name='main', import_name=__name__)
@main.route('/')
def index():
return render_template('home.html')
@main.route('/profile')
@login_required
def profile():
return render_template('profile.html', name=current_user.name)
####################
import datetime
from .lib.cors import crossdomain
from .lib.setup import rooms, settings
from .lib.appliance import Appliance
def updateStates(rooms):
for i, room in enumerate(rooms):
for j, appliance in enumerate(room['Appliances']):
current_appliance = Appliance(appliance)
rooms[i]['Appliances'][j]['State'] = current_appliance.getState()
return rooms
@main.context_processor
def inject_enumerate():
return dict(enumerate=enumerate)
@main.route("/controlroom")
@login_required
def controlroom():
now = datetime.datetime.now()
timeString = now.strftime("%Y-%m-%d %I:%M %p")
templateData = {
'time': timeString,
'rooms': updateStates(rooms),
'refresh_rate': settings['RefreshRate'] * 1000
}
return render_template('controlroom.html', **templateData)
@main.route("/grid/")
@login_required
@crossdomain(origin='*')
def grid():
templateData = {
'rooms': updateStates(rooms)
}
return render_template('grid.html', **templateData)
@main.route("/button/<int:room_index>/<int:appliance_index>/<int:statuss>")
@login_required
@crossdomain(origin='*')
def button(room_index, appliance_index, statuss):
appliance = Appliance(rooms[room_index]['Appliances'][appliance_index])
appliance.executeAction()
appliance.setState(statuss)
templateData = {
'state': appliance.getState(),
'room_index': room_index,
'appliance_index': appliance_index,
'name': appliance.name
}
return render_template('button.html', **templateData)
from .lib import sensors
@main.route("/sensors/")
@login_required
def sensor():
pias = {
'pir': sensors.pirS()
}
return render_template('sensors.html', **pias)
from .lib import qrcodesstem, doorSystem
@main.route("/door/")
@login_required
def door():
datamain = qrcodesstem.doorLockSystem()
user1 = User.query.filter_by(email=datamain).first()
if user1:
doorSystem.doorOpen()
dorja = 1
entryList = EntryInfo(door_entry_time=datetime.datetime.now(), user_name=user1.name)
db.session.add(entryList)
db.session.commit()
else:
dorja = 0
data = {
'dor': dorja,
'dorinfo': "Welcome To Home"
}
return render_template('door.html', **data)
@main.route("/door/close")
@login_required
def doorclose():
doorSystem.doorClose()
return render_template('home.html')
@main.route("/door/open")
@login_required
def dooropen():
doorSystem.doorOpen()
return render_template('home.html')
@main.route("/entry/")
@login_required
def entry():
info = EntryInfo.query.all()
return render_template('entryinfo.html', data=info)