From 2c4c4bcd955809ae70309c1064c67d4151168e99 Mon Sep 17 00:00:00 2001 From: Konstantin Koslowski Date: Thu, 27 Feb 2020 15:19:31 +0100 Subject: [PATCH] homecontrol: use f-strings --- homecontrol/homecontrol.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/homecontrol/homecontrol.py b/homecontrol/homecontrol.py index 84d44b3..a212c50 100755 --- a/homecontrol/homecontrol.py +++ b/homecontrol/homecontrol.py @@ -124,11 +124,11 @@ class Core: try: q = self.db["actors"].find_one(actorId=actorId) ret["actorId"] = actorId - ret["maxLevel"] = "0x%x" % q["maxLevel"] + ret["maxLevel"] = f"0x{q['maxLevel']}" ret["actorType"] = q["actorType"] q = self.db["actor_levels"].find_one(actorId=actorId, order_by="-ts") ret["ts"] = q["ts"] - ret["level"] = "0x%x" % q["level"] + ret["level"] = f"0x{q['level']}" except Exception as ex: self.logger.error("Exception Type:{type(ex).__name__}, args: {ex.args}") return ret @@ -145,7 +145,7 @@ class Core: query = self.db["actor_levels"].find(actorId=actorId) levels = [] for q in query: - levels.append({"ts": q["ts"], "value": "0x%x" % q["level"]}) + levels.append({"ts": q["ts"], "value": f"0x{q['level']}"}) ret["levels"] = levels except Exception as ex: self.logger.error("Exception Type:{type(ex).__name__}, args: {ex.args}") @@ -252,7 +252,7 @@ def actor_get_level(actorId): limit=int(request.args.get("limit")) else: limit=None - logger.debug("actor/get_levels/%s, limit: %s" % (actorId, limit)) + logger.debug(f"actor/get_levels/{actorId}, limit: {limit}") ret[actorId] = core.actor_get_levels(actorId, limit=limit) return make_response(jsonify(ret), 200) @@ -293,7 +293,7 @@ def sensor_get_values(sensorId): limit=int(request.args.get("limit")) if request.args.get("max_ts"): max_ts=int(request.args.get("max_ts")) - logger.debug("sensor/get_values/%s, [%f, %f], limit: %s" % (sensorId, min_ts, max_ts, limit)) + logger.debug(f"sensor/get_values/{sensorId}, [{min_ts}, {max_ts}], limit: {limit}") ret[sensorId] = core.sensor_get_values(sensorId, min_ts=min_ts, max_ts=max_ts, limit=limit) return make_response(jsonify(ret), 200) @@ -308,7 +308,7 @@ def sensor_add_value(): value = content.get("value") ret = core.sensor_add_value(sensorId, sensorType, value) except Exception as ex: - logger.error('Exception Type:%s, args:\n%s' % (type(ex).__name__, ex.args)) + logger.error("Exception Type:{type(ex).__name__}, args: {ex.args}") abort(400) return make_response(jsonify(ret), 200)