clean code

This commit is contained in:
Florian Bezannier
2021-11-11 23:54:44 +01:00
parent 79f79aa6d7
commit 5161044c0d
9 changed files with 17 additions and 30 deletions
+6 -11
View File
@@ -46,7 +46,6 @@ def gen_correlation_id(date):
return correlation_id
# pylint: disable=too-many-instance-attributes,too-many-public-methods
class MyPSACC:
def connect(self, user, password):
self.manager.init_with_user_credentials_realm(user, password, self.realm)
@@ -101,13 +100,10 @@ class MyPSACC:
@rate_limit(6, 1800)
def refresh_token(self):
try:
# pylint: disable=protected-access
self.manager._refresh_token()
self.save_config()
return True
except RequestException as e:
logger.error("Can't refresh token %s", e)
# pylint: disable=protected-access
self.manager._refresh_token()
self.save_config()
return True
def api(self) -> psac.VehiclesApi:
self.api_config.access_token = self.manager.access_token
@@ -443,7 +439,7 @@ class MyPSACC:
@staticmethod
def load_config(name="config.json"):
with open(name, "r") as f:
with open(name, "r", encoding="utf-8") as f:
config_str = f.read()
config = dict(**json.loads(config_str))
if "country_code" not in config:
@@ -493,10 +489,9 @@ class MyPSACC:
yield key, value
# pylint: disable=arguments-differ
class MyPeugeotEncoder(JSONEncoder):
def default(self, mp: MyPSACC):
def default(self, mp: MyPSACC): # pylint: disable=arguments-renamed
data = dict(mp)
mpd = {"proxies": data["_proxies"], "refresh_token": mp.manager.refresh_token,
"client_secret": mp.service_information.client_secret, "abrp": dict(mp.abrp)}
+1 -1
View File
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# pylint: disable=wrong-import-position
import os
import sys
from threading import Thread
@@ -12,6 +11,7 @@ if sys.version_info < (3, 6):
TestRequirements(DIR + "/requirements.txt").test_requirements()
# pylint: disable=wrong-import-position
import web.app
from libs.config import Config
from mylogger import logger
+3 -5
View File
@@ -11,7 +11,6 @@ from web.db import Database
class Points:
# pylint: disable= too-few-public-methods
def __init__(self, latitude, longitude):
self.latitude = latitude
self.longitude = longitude
@@ -21,7 +20,6 @@ class Points:
class Trip:
# pylint: disable= too-many-instance-attributes
def __init__(self):
self.start_at = None
self.end_at = None
@@ -58,7 +56,7 @@ class Trip:
try:
self.consumption_km = 100 * self.consumption / self.distance # kw/100 km
except TypeError:
raise ValueError("Distance not set")
raise ValueError("Distance not set") from TypeError
return self.consumption_km
def set_fuel_consumption(self, consumption) -> float:
@@ -135,8 +133,8 @@ class Trips(list):
logger.debugv("trip discarded")
return False
@staticmethod # noqa: MC0001
def get_trips(vehicles_list: Cars) -> Dict[str, "Trips"]:
@staticmethod
def get_trips(vehicles_list: Cars) -> Dict[str, "Trips"]: # noqa: MC0001
# pylint: disable=too-many-locals,too-many-statements,too-many-nested-blocks,too-many-branches
conn = Database.get_db()
vehicles = conn.execute("SELECT DISTINCT vin FROM position;").fetchall()
+1 -1
View File
@@ -14,7 +14,7 @@ class Abrp:
def __init__(self, token: str = "", abrp_enable_vin=None):
if abrp_enable_vin is None:
abrp_enable_vin = list()
abrp_enable_vin = []
self.token = token
self.abrp_enable_vin = set(abrp_enable_vin)
self.proxies = None
+1 -2
View File
@@ -18,7 +18,6 @@ import importlib
# pylint: disable=invalid-name
app = None
dash_app = None
dispatcher = None
class MyProxyFix(ProxyFix):
@@ -47,7 +46,7 @@ def start_app(*args, **kwargs):
def config_flask(title, base_path, debug: bool, host, port, reloader=False, # pylint: disable=too-many-arguments
unminified=False, view="web.view.views"):
global app, dash_app, dispatcher
global app, dash_app
reload_view = app is not None
app = Flask(__name__)
try:
+3 -4
View File
@@ -129,10 +129,9 @@ class Database:
db_file = Database.DEFAULT_DB_FILE
conn = CustomSqliteConnection(db_file, detect_types=sqlite3.PARSE_DECLTYPES | sqlite3.PARSE_COLNAMES)
conn.row_factory = sqlite3.Row
Database.__thread_lock.acquire()
if not Database.db_initialized:
Database.init_db(conn)
Database.__thread_lock.release()
with Database.__thread_lock:
if not Database.db_initialized:
Database.init_db(conn)
if update_callback:
conn.callbacks.append(Database.callback_fct)
return conn
+1 -2
View File
@@ -51,8 +51,7 @@ SUMMARY_CARDS = {"Average consumption": {"text": [card_value_div(AVG_CONSUM_KW,
# pylint: disable=too-many-locals
def get_figures(car: Car):
global consumption_fig, consumption_df, trips_map, consumption_fig_by_speed, table_fig, info, \
battery_table, consumption_fig_by_temp
global consumption_fig, trips_map, consumption_fig_by_speed, table_fig, battery_table, consumption_fig_by_temp
lats = [42, 41]
lons = [1, 2]
names = ["undefined", "undefined"]
-3
View File
@@ -64,9 +64,6 @@ class FigureFilter:
res = {table.src: table.date_columns for table in self.tables}
return res
def __get_table_src(self):
return [table.src for table in self.tables]
def __get_figures(self):
return {"graph": [graph.figure for graph in self.graphs],
"tables": [table.figure for table in self.tables],
+1 -1
View File
@@ -94,7 +94,7 @@ config_otp_layout = dbc.Row(dbc.Col(className="col-md-12 col-lg-2 m-3", children
def log_layout():
with open(LOG_FILE, "r") as f:
with open(LOG_FILE, "r", encoding="utf-8") as f:
log_text = f.read()
return html.H3(className="m-2", children=["Log:", dbc.Container(
fluid=True,