add default values for record
Andronaco Marco marco.andronaco@olivetti.com
Thu, 21 Sep 2023 14:27:56 +0200
3 files changed,
18 insertions(+),
22 deletions(-)
M
.env.example
→
.env.example
@@ -1,1 +1,1 @@
-OWM_API_KEY=29d3c09e105b332ba224939672820be2 +OWM_API_KEY=
M
backend_iot/db.py
→
backend_iot/db.py
@@ -14,21 +14,21 @@ database = db
class Record(BaseModel): timestamp = DateTimeField(default=datetime.now) - latitude = FloatField() - longitude = FloatField() - aqi = IntegerField() - t_in = FloatField() - t_out = FloatField() - t_setpoint = FloatField() - fan_speed = IntegerField() - power = BooleanField() - auto = BooleanField() - co_in = FloatField() - co_out = FloatField() - no2_in = FloatField() - pm10_out = FloatField() - airflow = IntegerField() - aq_in = IntegerField() + latitude = FloatField(default=0) + longitude = FloatField(default=0) + aqi = IntegerField(default=0) + t_in = FloatField(default=0) + t_out = FloatField(default=0) + t_setpoint = FloatField(default=0) + fan_speed = IntegerField(default=0) + power = BooleanField(default=False) + auto = BooleanField(default=False) + co_in = FloatField(default=0) + co_out = FloatField(default=0) + no2_in = FloatField(default=0) + pm10_out = FloatField(default=0) + airflow = IntegerField(default=0) + aq_in = IntegerField(default=0) class AQI(BaseModel): timestamp = DateTimeField(default=datetime.now)@@ -75,7 +75,7 @@ #User.select().order_by(User.id.desc()).get()
try: return Record.select().order_by(Record.timestamp.desc()).get() except DoesNotExist: - return None + return addRecord() def addRecord(**info): - Record.create(**info)+ return Record.create(**info)
M
backend_iot/views.py
→
backend_iot/views.py
@@ -21,10 +21,6 @@ @app.route("/")
def index_route(): if request.method == 'GET': return render_template("index.html") - - form = request.form - update_record(form) - addRecord(**form) editable_fields = ["t_target", "power", "fan_speed", "auto", "airflow"]