From ea01bcb6b7d30219ff6ebf53da76504c0325ea48 Mon Sep 17 00:00:00 2001 From: Florian Bezannier Date: Mon, 8 Jan 2024 07:45:44 +0100 Subject: [PATCH] style: apply autopep8 --- .../psacc/application/car_controller.py | 2 +- .../psacc/application/charging.py | 2 +- psa_car_controller/psacc/repository/db.py | 4 +- psa_car_controller/web/app.py | 4 +- psa_car_controller/web/view/api.py | 1 + psa_car_controller/web/view/views.py | 146 +++++++++--------- tests/test_unit.py | 2 +- 7 files changed, 81 insertions(+), 80 deletions(-) diff --git a/psa_car_controller/psacc/application/car_controller.py b/psa_car_controller/psacc/application/car_controller.py index 7c2906f..34b34f5 100644 --- a/psa_car_controller/psacc/application/car_controller.py +++ b/psa_car_controller/psacc/application/car_controller.py @@ -76,7 +76,7 @@ class PSACarController(metaclass=Singleton): def load_app(self) -> bool: # pylint: disable=too-many-branches my_logger(handler_level=int(self.args.debug)) - + logger.info("App version %s", __version__) if self.args.config: self.config_name = self.args.config diff --git a/psa_car_controller/psacc/application/charging.py b/psa_car_controller/psacc/application/charging.py index e58d649..8cb15e5 100644 --- a/psa_car_controller/psacc/application/charging.py +++ b/psa_car_controller/psacc/application/charging.py @@ -108,4 +108,4 @@ class Charging: / 60, "duration_str": str((c.get("stop_at") - c.get("start_at"))), } - ) \ No newline at end of file + ) diff --git a/psa_car_controller/psacc/repository/db.py b/psa_car_controller/psacc/repository/db.py index 78c9750..8e497ff 100644 --- a/psa_car_controller/psacc/repository/db.py +++ b/psa_car_controller/psacc/repository/db.py @@ -325,9 +325,9 @@ class Database: def get_all_charge() -> List[Charge]: conn = Database.get_db() res = conn.execute("select * from battery ORDER BY start_at").fetchall() - conn.close() + conn.close() return res - + @staticmethod def update_charge(charge: Charge): # we don't need to update mileage, since it should be inserted at beginning of charge, diff --git a/psa_car_controller/web/app.py b/psa_car_controller/web/app.py index 7479390..638c5e9 100644 --- a/psa_car_controller/web/app.py +++ b/psa_car_controller/web/app.py @@ -76,8 +76,8 @@ def config_flask(title, base_path, debug: bool, host, port, reloader=False, # p else: application = DispatcherMiddleware(Flask('dummy_app'), {base_path: app}) requests_pathname_prefix = base_path + "/" - dash_app = DashCustom(external_stylesheets=[dbc.themes.BOOTSTRAP, dbc.icons.BOOTSTRAP], - external_scripts=locale_url, title=title, + dash_app = DashCustom(external_stylesheets=[dbc.themes.BOOTSTRAP, dbc.icons.BOOTSTRAP], + external_scripts=locale_url, title=title, server=app, requests_pathname_prefix=requests_pathname_prefix, suppress_callback_exceptions=True, serve_locally=False) dash_app.enable_dev_tools(debug) diff --git a/psa_car_controller/web/view/api.py b/psa_car_controller/web/view/api.py index ba48cb3..4f0bb25 100644 --- a/psa_car_controller/web/view/api.py +++ b/psa_car_controller/web/view/api.py @@ -29,6 +29,7 @@ def get_vehicle_info(vin): ) return response + @app.route("/style.json") def get_style(): global STYLE_CACHE diff --git a/psa_car_controller/web/view/views.py b/psa_car_controller/web/view/views.py index 6f50e60..46dfa6c 100644 --- a/psa_car_controller/web/view/views.py +++ b/psa_car_controller/web/view/views.py @@ -48,20 +48,20 @@ def get_default_car() -> Car: def add_header(el): version = "v" + __version__ - github_url= "https://github.com/flobz/psa_car_controller/releases/tag/"+version + github_url = "https://github.com/flobz/psa_car_controller/releases/tag/" + version dbc_version = dbc.Button(html.I(version, className="m-1"), size='sm', - color="secondary", + color="secondary", className="me-1 bi bi-github", - external_link =True, href=github_url) + external_link=True, href=github_url) return dbc.Row([dbc.Col(dcc.Link(html.H1('My car info'), href=dash_app.requests_pathname_external_prefix, style={"TextDecoration": "none"})), dbc.Col(html.Div([dbc_version, - dcc.Link(html.Img(src="assets/images/settings.svg", width="30veh"), - href=dash_app.requests_pathname_external_prefix + "config", - className="float-end")], + dcc.Link(html.Img(src="assets/images/settings.svg", width="30veh"), + href=dash_app.requests_pathname_external_prefix + "config", + className="float-end")], className="d-grid gap-2 d-md-flex justify-content-md-end",))], - className='align-items-center'), el + className='align-items-center'), el @dash_app.callback(Output('page-content', 'children'), @@ -104,7 +104,7 @@ def create_callback(): # noqa: MC0001 for changed_line in diff_data: if changed_line['column_name'] == 'price': conn = Database.get_db() - charge = Charge(datetime.utcfromtimestamp(changed_line['start_at']/1000)) + charge = Charge(datetime.utcfromtimestamp(changed_line['start_at'] / 1000)) charge.price = changed_line['current_value'] charge.vin = get_default_car().vin if not Database.set_chargings_price(conn, charge): @@ -139,11 +139,11 @@ def create_callback(): # noqa: MC0001 return "", False @dash_app.callback(Output("loading-output-trips", "children"), Input("export-trips-table", "n_clicks")) - def export_trips_loading_animation(n_clicks): # pylint: disable=unused-argument + def export_trips_loading_animation(n_clicks): # pylint: disable=unused-argument time.sleep(3) @dash_app.callback(Output("loading-output-battery", "children"), Input("export-battery-table", "n_clicks")) - def export_batt_loading_animation(n_clicks): # pylint: disable=unused-argument + def export_batt_loading_animation(n_clicks): # pylint: disable=unused-argument time.sleep(3) # Emulate click on original Export datatables button, since original button is hard to modify dash_app.clientside_callback( @@ -268,75 +268,75 @@ def serve_layout(): dbc.Tab(label="Summary", tab_id="summary", children=summary_tab), dbc.Tab(label="Trips", tab_id="trips", id="tab_trips", children=[dbc.Row( - dbc.Col([ - dcc.Loading( - id="loading-div-trips", - children=[html.Div([html.Div(id="loading-output-trips")])], - type="circle", - className="export-load-anim" - ), - dbc.Button("Export trips data", - id="export-trips-table", - n_clicks=0, - size="sm", - color="light", - className="m-1 w-200" - )], - className="d-grid gap-2 d-md-flex justify-content-md-end" - ) - ), - html.Div(id="tab_trips_fig", children=figures.table_fig), - dbc.Modal( - [ - dbc.ModalHeader("Altitude"), - dbc.ModalBody(html.Div( + dbc.Col([ + dcc.Loading( + id="loading-div-trips", + children=[html.Div([html.Div(id="loading-output-trips")])], + type="circle", + className="export-load-anim" + ), + dbc.Button("Export trips data", + id="export-trips-table", + n_clicks=0, + size="sm", + color="light", + className="m-1 w-200" + )], + className="d-grid gap-2 d-md-flex justify-content-md-end" + ) + ), + html.Div(id="tab_trips_fig", children=figures.table_fig), + dbc.Modal( + [ + dbc.ModalHeader("Altitude"), + dbc.ModalBody(html.Div( id="tab_trips_popup_graph")), - dbc.ModalFooter( - dbc.Button("Close", - id="tab_trips_popup-close", - className="ml-auto") - ), - ], - id="tab_trips_popup", - size="xl", + dbc.ModalFooter( + dbc.Button("Close", + id="tab_trips_popup-close", + className="ml-auto") + ), + ], + id="tab_trips_popup", + size="xl", ) ]), dbc.Tab(label="Charge", tab_id="charge", id="tab_charge", children=[dbc.Row( - dbc.Col([ - dcc.Loading( - id="loading-div-battery", - children=[html.Div([html.Div(id="loading-output-battery")])], - type="circle", - className="export-load-anim" - ), - dbc.Button("Export charging data", - id="export-battery-table", - n_clicks=0, - size="sm", - color="light", - className="m-1 w-200" - )], - className="d-grid gap-2 d-md-flex justify-content-md-end" - ) - ), - figures.battery_table, - dbc.Modal( - [ - dbc.ModalHeader( - "Charging speed"), - dbc.ModalBody(html.Div( + dbc.Col([ + dcc.Loading( + id="loading-div-battery", + children=[html.Div([html.Div(id="loading-output-battery")])], + type="circle", + className="export-load-anim" + ), + dbc.Button("Export charging data", + id="export-battery-table", + n_clicks=0, + size="sm", + color="light", + className="m-1 w-200" + )], + className="d-grid gap-2 d-md-flex justify-content-md-end" + ) + ), + figures.battery_table, + dbc.Modal( + [ + dbc.ModalHeader( + "Charging speed"), + dbc.ModalBody(html.Div( id="tab_battery_popup_graph")), - dbc.ModalFooter( - dbc.Button("Close", - id="tab_battery_popup-close", - className="ml-auto") - ), - ], - id="tab_battery_popup", - size="xl", - ) - ]), + dbc.ModalFooter( + dbc.Button("Close", + id="tab_battery_popup-close", + className="ml-auto") + ), + ], + id="tab_battery_popup", + size="xl", + ) + ]), dbc.Tab(label="Map", tab_id="map", children=[maps]), dbc.Tab(label="Control", tab_id="control", children=html.Iframe( src=request.url_root + "control?header=false", diff --git a/tests/test_unit.py b/tests/test_unit.py index 38699aa..0faa495 100644 --- a/tests/test_unit.py +++ b/tests/test_unit.py @@ -238,7 +238,7 @@ class TestUnit(unittest.TestCase): assert compare_dict(chargings, [{'start_at': date0, 'stop_at': date3, 'duration_str': duration_str, - 'duration_min' :duration_min, + 'duration_min': duration_min, 'VIN': 'VR3UHZKX', 'start_level': 40, 'end_level': 85,