all repos — iot-project @ ac0651817ca30fa90c5e1fdc8b959f70adf70845

add default values for record
Andronaco Marco marco.andronaco@olivetti.com
Thu, 21 Sep 2023 14:27:56 +0200
commit

ac0651817ca30fa90c5e1fdc8b959f70adf70845

parent

2768cd3b1c1fba57c4b8cb879e28b2e0bb075796

3 files changed, 18 insertions(+), 22 deletions(-)

jump to
M .env.example.env.example

@@ -1,1 +1,1 @@

-OWM_API_KEY=29d3c09e105b332ba224939672820be2 +OWM_API_KEY=
M backend_iot/db.pybackend_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.pybackend_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"]