diff --git a/thermostat.py b/thermostat.py index d93e5f2..80981bd 100644 --- a/thermostat.py +++ b/thermostat.py @@ -11,6 +11,18 @@ import sys import datetime import time +# This code has been written for +# python3-flask 2.2.2-3 all micro web framework based on Werkzeug and Jinja2 - Python 3.x +# python3-flask-migrate 4.0.4-1 all SQLAlchemy migrations for Flask using Alembic and Python 3 +# python3-flask-sqlalchemy 3.0.3-1 all adds SQLAlchemy support to your Python 3 Flask application +# alembic 1.8.1-2 all lightweight database migration tool for SQLAlchemy +# python3-alembic 1.8.1-2 all lightweight database migration tool for SQLAlchemy - Python module +# python3-sqlalchemy 1.4.46+ds1-1 all SQL toolkit and Object Relational Mapper for Python 3 +# python3-sqlalchemy-ext:i386 1.4.46+ds1-1+b1 i386 SQL toolkit and Object Relational Mapper for Python3 - C extension + +# Flask-SQLAlchemy documentation: https://flask-sqlalchemy.palletsprojects.com/en/3.0.x/quickstart/ +# We use SQLAlchemy ORM style 2.x: https://docs.sqlalchemy.org/en/20/tutorial/data_select.html + logging.basicConfig(level=logging.WARNING) authorizations = { @@ -119,7 +131,7 @@ def get_metric(metric, current_time, interval): def get_forced_mode(): with app.app_context(): - row = db.session.query(Set_mode.value, Set_mode.timestamp).first() + row = db.session.execute(db.select(Set_mode.value, Set_mode.timestamp)).first() #cur.execute("SELECT value, timestamp FROM set_mode WHERE name='mode'") #row = cur.fetchone() data = dict(zip(['value', 'timestamp'], row)) @@ -221,8 +233,7 @@ while True: current_date = datetime.datetime.now() today_awake_time = current_date.replace(hour=int(awake_hour.split(':')[0]), minute=int(awake_hour.split(':')[1]), second=0, microsecond=0) today_sleep_time = current_date.replace(hour=int(sleep_hour.split(':')[0]), minute=int(sleep_hour.split(':')[1]), second=0, microsecond=0) - #forced_mode = get_forced_mode() - forced_mode = None + forced_mode = get_forced_mode() if forced_mode is not None and forced_mode in targets: if target_name != forced_mode: target_name = forced_mode