summaryrefslogtreecommitdiff
path: root/main.py
diff options
context:
space:
mode:
authorroot <root@turin.home>2022-01-15 14:46:26 +0000
committerroot <root@turin.home>2022-01-15 14:46:26 +0000
commitf315adea703193deb7419355dc084e903dbfde1e (patch)
tree64f0855bd91bf2c8b7cc4d9c9dc5a80a5c448015 /main.py
parentcf70ae6ded332729f0dc2833d6680d7dac8072db (diff)
Development
Diffstat (limited to 'main.py')
-rw-r--r--main.py85
1 files changed, 54 insertions, 31 deletions
diff --git a/main.py b/main.py
index c642d17..daae78f 100644
--- a/main.py
+++ b/main.py
@@ -1,56 +1,79 @@
-import sqlite3
+# Import other functions and classes
import heating
+import errors
import sql
-import time
+import weather
from flask import Flask, render_template
app = Flask(__name__)
-boiler = heating.rpi_heating()
+# Paramaterised location of database file
+# Use of constant
+DBFILE = "data.db"
-# paramaterised location of database file
-# Use of final data type
-global DBFILE
-DBFILE = 'data.db'
+db = sql.db(DBFILE)
+#weather = weather_met_no()
-db = sql.db(dbfile)
+# Check if running on correct device : defensive coding against running
+# on the wrong device
+try:
+ with open("/sys/firmware/devicetree/base/model", "r") as file:
+ device = file.read()
+except:
+ errors.device_error()
-@app.route('/')
-@app.route('/index.html')
-def index():
+if device.startswith("Raspberry Pi 4"):
+ boiler = heating.rpi_heating(db)
+else:
+ errors.device_error()
+
+
+def main_page():
# paramaterised location of template in 'templates' folder
return render_template(
- "main.html",
- actual_temp = boiler.temp,
- target_temp = boiler.target
- )
+ "main.html",
+ actual_temp=boiler.temperature,
+ target_temp=boiler.target
+ #forecast_temp=weather.temperature()
+ )
+
+
+@app.route("/")
+@app.route("/index.html")
+def index():
+ return main_page()
-@app.route('/up')
+
+@app.route("/up")
def form():
boiler.up()
- return render_template("main.html")
+ return main_page()
+
-@app.route('/down')
+@app.route("/down")
def activity():
- boilder.down()
- return render_template("main.html")
+ boiler.down()
+ return main_page()
+
+
+@app.route("/export")
+def export_choice():
+ return render_template("export_choice.html")
+
-@app.route('/export/<opt>')
+@app.route("/export/<opt>")
def export(opt):
- if opt == 'txt':
+ if opt == "txt":
pass
- elif opt == 'pdf':
+ elif opt == "pdf":
pass
else:
- return render_template('error.html', error="Invalid export type")
+ return render_template(
+ "error.html", error="Invalid export type"
+ )
-if __name__ == '__main__':
- # if the database file does not exist, create it
- try:
- open(dbfile)
- except:
- sql.setup(dbfile)
- app.run()
+if __name__ == "__main__":
+ app.run(host="0.0.0.0")