diff --git a/web/view/views.py b/web/view/views.py index 1773738..88875be 100644 --- a/web/view/views.py +++ b/web/view/views.py @@ -10,6 +10,7 @@ from flask import jsonify, request, Response as FlaskResponse import web.utils from libs.car import Cars, Car +from libs.utils import RateLimitException from mylogger import logger from trip import Trips @@ -77,7 +78,7 @@ def create_callback(): # noqa: MC0001 [Input("battery-table", "data_timestamp")], [State("battery-table", "data"), State("battery-table", "data_previous")]) - def capture_diffs_in_battery_table(timestamp, data, data_previous): # pylint: disable=unused-variable + def capture_diffs_in_battery_table(timestamp, data, data_previous): if timestamp is None: raise PreventUpdate diff_data = diff_dashtable(data, data_previous, "start_at") @@ -97,7 +98,7 @@ def create_callback(): # noqa: MC0001 Input("tab_battery_popup-close", "n_clicks")], [State('battery-table', 'data'), State("tab_battery_popup", "is_open")]) - def get_battery_curve(active_cell, close, data, is_open): # pylint: disable=unused-argument, unused-variable + def get_battery_curve(active_cell, close, data, is_open): # pylint: disable=unused-argument if is_open is None: is_open = False if active_cell is not None and active_cell["column_id"] in ["start_level", "end_level"] and not is_open: @@ -109,7 +110,7 @@ def create_callback(): # noqa: MC0001 [Input("trips-table", "active_cell"), Input("tab_trips_popup-close", "n_clicks")], State("tab_trips_popup", "is_open")) - def get_altitude_graph(active_cell, close, is_open): # pylint: disable=unused-argument, unused-variable + def get_altitude_graph(active_cell, close, is_open): # pylint: disable=unused-argument if is_open is None: is_open = False if active_cell is not None and active_cell["column_id"] in ["altitude_diff"] and not is_open: @@ -147,7 +148,7 @@ STYLE_CACHE = None def get_style(): global STYLE_CACHE if not STYLE_CACHE: - with open(app.root_path + "/assets/style.json", "r") as f: + with open(app.root_path + "/assets/style.json", "r", encoding="utf-8") as f: res = json.loads(f.read()) STYLE_CACHE = res url_root = request.url_root @@ -167,7 +168,10 @@ def change_charge_hour(): @app.route('/wakeup/') def wakeup(vin): - return jsonify(CONFIG.myp.wakeup(vin)) + try: + return jsonify(CONFIG.myp.wakeup(vin)) + except RateLimitException: + return jsonify({"error": "Waleup rate limit exceeded"}) @app.route('/preconditioning//')