fix: #726 chc is None

This commit is contained in:
Florian Bezannier
2024-01-15 22:30:55 +01:00
committed by Florian BEZANNIER
parent cfeb719ba9
commit e9b5a84437
2 changed files with 14 additions and 10 deletions
@@ -48,7 +48,7 @@ class PSACarController(metaclass=Singleton):
def __init__(self):
self.args = parse_args()
self.myp: PSAClient
self.chc: ChargeControls
self.chc: ChargeControls = None
self.config_name = DEFAULT_NAME
self.is_good: bool = True
self.offline = self.args.offline
+13 -9
View File
@@ -106,15 +106,19 @@ def get_position(vin):
def get_charge_control():
logger.info(request)
vin = request.args['vin']
charge_control = APP.chc.get(vin)
if charge_control is None:
return jsonify("error: VIN not in list")
if 'hour' in request.args and 'minute' in request.args:
charge_control.set_stop_hour([int(request.args["hour"]), int(request.args["minute"])])
if 'percentage' in request.args:
charge_control.percentage_threshold = int(request.args['percentage'])
APP.chc.save_config()
return jsonify(charge_control.get_dict())
if APP.chc:
charge_control = APP.chc.get(vin)
if charge_control is None:
return jsonify({"error": "VIN not in list"})
if 'hour' in request.args and 'minute' in request.args:
charge_control.set_stop_hour([int(request.args["hour"]), int(request.args["minute"])])
if 'percentage' in request.args:
charge_control.percentage_threshold = int(request.args['percentage'])
APP.chc.save_config()
return jsonify(charge_control.get_dict())
error = "Charge control not setup check your PSACC configuration and logs"
logger.error(error)
return jsonify({"error": error})
@app.route('/positions')