diff --git a/thermostat.py b/thermostat.py index 6c398d7..0911131 100644 --- a/thermostat.py +++ b/thermostat.py @@ -13,6 +13,7 @@ import time import requests # This code has been written for +# python3 3.11.2-1+b1 # 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 @@ -120,7 +121,7 @@ def get_metric(metric, current_time, interval): try: r = requests.get(url) data = json.loads(r.text) - timestamp = getDateTimeFromISO8601String(data['timestamp']).replace(tzinfo=timezone.utc).timestamp() + timestamp = datetime.fromisoformat(data['timestamp']).replace(tzinfo=timezone.utc).timestamp() if current_time - timestamp < interval * 2: return data['value'] else: @@ -138,7 +139,7 @@ def get_forced_mode(): #cur.execute("SELECT value, timestamp FROM set_mode WHERE name='mode'") #row = cur.fetchone() data = dict(zip(['value', 'timestamp'], row)) - timestamp = getDateTimeFromISO8601String(data['timestamp']).replace(tzinfo=timezone.utc).timestamp() + timestamp = datetime.fromisoformat(data['timestamp']).replace(tzinfo=timezone.utc).timestamp() # We ignore old targets but never ignore absence modes if data['value'] in targets and time.time() - timestamp > forced_mode_duration: logging.debug("Ignoring old set mode.") @@ -330,14 +331,7 @@ logging.info("====== Ended successfully ======") #from http.server import BaseHTTPRequestHandler #import threading #import socketserver -# -## As of Python 3.7 there is a method datetime.fromisoformat() which is exactly the reverse for isoformat(). -## So this will no longer be necessary. -#from dateutil import parser -#def getDateTimeFromISO8601String(s): -# d = parser.parse(s) -# return d -# + #from threading import Lock # #xprint_lock = Lock()