diff --git a/psa-car-controller/psa/constants.py b/psa-car-controller/psa/constants.py index e7bbf37..e10fbd4 100644 --- a/psa-car-controller/psa/constants.py +++ b/psa-car-controller/psa/constants.py @@ -35,4 +35,4 @@ BRAND = {"com.psa.mym.myopel": {"realm": "clientsB2COpel", "brand_code": "OP", " "com.psa.mym.mycitroen": {"realm": "clientsB2CCitroen", "brand_code": "AC", "app_name": "MyCitroen"}, "com.psa.mym.myds": {"realm": "clientsB2CDS", "brand_code": "DS", "app_name": "MyDS"}, "com.psa.mym.myvauxhall": {"realm": "clientsB2CVauxhall", "brand_code": "VX", "app_name": "MyVauxhall"} - } \ No newline at end of file + } diff --git a/psa-car-controller/psa/otp/load.py b/psa-car-controller/psa/otp/load.py index 29eb8cc..3f766f3 100644 --- a/psa-car-controller/psa/otp/load.py +++ b/psa-car-controller/psa/otp/load.py @@ -16,6 +16,7 @@ DEFAULT_VERSION = "529" def filter_load(string: str): return string.replace("&", "&") + class IWData: # pylint: disable=invalid-name,too-many-branches,too-many-statements def __init__(self, IW): diff --git a/psa-car-controller/psa/otp/otp.py b/psa-car-controller/psa/otp/otp.py index 196b88a..a815948 100644 --- a/psa-car-controller/psa/otp/otp.py +++ b/psa-car-controller/psa/otp/otp.py @@ -256,7 +256,7 @@ class Otp: password = self.data.iwK1 + ":" + str(self.defi) + ":" + self.data.iwsecval res = bytes(hashlib.sha256(password.encode("utf-8")).digest()) nb = ((int.from_bytes(res[:4], byteorder="big") & 0xfffffff) * 1024) + ( - int.from_bytes(res[4:8], byteorder="big") & 1023) + int.from_bytes(res[4:8], byteorder="big") & 1023) otp = number_to_base36(nb) return otp @@ -305,7 +305,7 @@ def save_otp(obj, filename="otp.bin"): class RenameUnpickler(pickle.Unpickler): def find_class(self, module, name): - renamed_module = "psa."+module.lower() + renamed_module = "psa." + module.lower() return super().find_class(renamed_module, name) diff --git a/psa-car-controller/psa/setup/apk_parser.py b/psa-car-controller/psa/setup/apk_parser.py index 9b5f594..9f05654 100644 --- a/psa-car-controller/psa/setup/apk_parser.py +++ b/psa-car-controller/psa/setup/apk_parser.py @@ -32,7 +32,7 @@ class ApkParser: self.client_secret = resources.get_string(package_name, "PSA_API_CLIENT_SECRET_PROD")[1] self.host_brandid_prod = resources.get_string(package_name, "HOST_BRANDID_PROD")[1] self.culture = self.__get_cultures_code(a.get_file("res/raw/cultures.json"), self.country_code) - ## Get Customer id + # Get Customer id self.site_code = BRAND[package_name]["brand_code"] + "_" + self.country_code + "_ESP" pfx_cert = a.get_file("assets/MWPMYMA1.pfx") save_key_to_pem(pfx_cert, b"y5Y2my5B") @@ -51,4 +51,4 @@ def save_key_to_pem(pfx_data, pfx_password): with open("certs/private.pem", "wb") as f: f.write(private_key.private_bytes(encoding=serialization.Encoding.PEM, format=serialization.PrivateFormat.TraditionalOpenSSL, - encryption_algorithm=serialization.NoEncryption())) \ No newline at end of file + encryption_algorithm=serialization.NoEncryption())) diff --git a/psa-car-controller/psa/setup/app_decoder.py b/psa-car-controller/psa/setup/app_decoder.py index 8408bd4..533a33f 100755 --- a/psa-car-controller/psa/setup/app_decoder.py +++ b/psa-car-controller/psa/setup/app_decoder.py @@ -51,7 +51,7 @@ def firstLaunchConfig(package_name, client_email, client_password, country_code, f"sitecode: {apk_parser.site_code}" try: msg += res.text - except: # pylint: disable=bare-except + except BaseException: pass logger.error(msg) raise Exception(msg) from ex @@ -81,7 +81,7 @@ def firstLaunchConfig(package_name, client_email, client_password, country_code, msg = traceback.format_exc() try: msg += res2.text - except: # pylint: disable=bare-except + except BaseException: pass logger.error(msg) raise Exception(msg) from ex diff --git a/psa-car-controller/psa/setup/github.py b/psa-car-controller/psa/setup/github.py index 0215853..62933a8 100644 --- a/psa-car-controller/psa/setup/github.py +++ b/psa-car-controller/psa/setup/github.py @@ -35,9 +35,9 @@ def urlretrieve_from_github(user, repo, directory, filename, branch="main"): r = requests.get("https://github.com/{}/{}/raw/{}/{}{}".format(user, repo, branch, directory, filename), headers={ "Accept": "application/vnd.github.VERSION.raw" - }, - stream=True - ) + }, + stream=True + ) r.raise_for_status() for chunk in r.iter_content(1024): diff --git a/psa-car-controller/psacc/application/abrp.py b/psa-car-controller/psacc/application/abrp.py index e08ed9d..c823dbb 100644 --- a/psa-car-controller/psacc/application/abrp.py +++ b/psa-car-controller/psacc/application/abrp.py @@ -9,6 +9,7 @@ from psacc.model.car import Car logger = logging.getLogger(__name__) + class Abrp: api_key = "1e28ad14-df16-49f0-97da-364c9154b44a" url = "https://api.iternio.com/1/tlm/send" diff --git a/psa-car-controller/psacc/application/charge_control.py b/psa-car-controller/psacc/application/charge_control.py index 7df16de..3135213 100644 --- a/psa-car-controller/psacc/application/charge_control.py +++ b/psa-car-controller/psacc/application/charge_control.py @@ -92,7 +92,7 @@ class ChargeControl: if next_in_second < self.psacc.info_refresh_rate: periodicity = next_in_second thread = threading.Timer(periodicity, self.process) - thread.setDaemon(True) # pylint: disable=deprecated-method + thread.setDaemon(True) thread.start() else: if self._next_stop_hour is not None and self._next_stop_hour < now: @@ -100,7 +100,7 @@ class ChargeControl: self.retry_count = 0 except (AttributeError, ValueError): logger.exception("Probably can't retrieve all information from API:") - except: # pylint: disable=bare-except + except BaseException: logger.exception("Charge control:") def get_dict(self): diff --git a/psa-car-controller/psacc/application/charging.py b/psa-car-controller/psacc/application/charging.py index f3c7a16..af4454a 100644 --- a/psa-car-controller/psacc/application/charging.py +++ b/psa-car-controller/psacc/application/charging.py @@ -53,10 +53,8 @@ class Charging: Database.update_charge(charge) Database.clean_battery(conn) - - @staticmethod - def is_charge_ended(charge:'Charge'): + def is_charge_ended(charge: 'Charge'): return not charge or charge.stop_at @staticmethod diff --git a/psa-car-controller/psacc/application/ecomix.py b/psa-car-controller/psacc/application/ecomix.py index a442e69..a6083ce 100644 --- a/psa-car-controller/psacc/application/ecomix.py +++ b/psa-car-controller/psacc/application/ecomix.py @@ -15,6 +15,7 @@ CO2_SIGNAL_URL = "https://api.co2signal.com" logger = logging.getLogger(__name__) + class Ecomix: _cache = {} co2_signal_key = None diff --git a/psa-car-controller/psacc/application/psa_client.py b/psa-car-controller/psacc/application/psa_client.py index c65d08b..46efa1f 100644 --- a/psa-car-controller/psacc/application/psa_client.py +++ b/psa-car-controller/psacc/application/psa_client.py @@ -122,13 +122,13 @@ class PSAClient: self.get_vehicle_info(car.vin) for callback in self.info_callback: callback() - except: # pylint: disable=bare-except + except BaseException: logger.exception("refresh_vehicle_info: ") sleep(self.info_refresh_rate) def start_refresh_thread(self): if self.refresh_thread is None: - self.refresh_thread = threading.Thread(target=self.__refresh_vehicle_info,daemon=True) + self.refresh_thread = threading.Thread(target=self.__refresh_vehicle_info, daemon=True) self.refresh_thread.start() def get_vehicles(self): diff --git a/psa-car-controller/psacc/application/trip_parser.py b/psa-car-controller/psacc/application/trip_parser.py index 5a48972..466df0d 100644 --- a/psa-car-controller/psacc/application/trip_parser.py +++ b/psa-car-controller/psacc/application/trip_parser.py @@ -8,6 +8,7 @@ LEVEL_FUEL = 8 logger = logging.getLogger(__name__) + class TripParser: def __init__(self, car: Car): self.car = car diff --git a/psa-car-controller/psacc/model/trip.py b/psa-car-controller/psacc/model/trip.py index 5198d4b..8e5f1c6 100644 --- a/psa-car-controller/psacc/model/trip.py +++ b/psa-car-controller/psacc/model/trip.py @@ -8,6 +8,7 @@ from .car import Car logger = logging.getLogger(__name__) + class Points: def __init__(self, latitude, longitude): self.latitude = latitude diff --git a/psa-car-controller/psacc/repository/config_repository.py b/psa-car-controller/psacc/repository/config_repository.py index 01da5f3..21deb96 100644 --- a/psa-car-controller/psacc/repository/config_repository.py +++ b/psa-car-controller/psacc/repository/config_repository.py @@ -15,20 +15,20 @@ logger = logging.getLogger(__name__) DEFAULT_CONFIG = """[General] currency = € # minimum trip length in km so it's added to stats and map in website -minimum trip length = +minimum trip length = [Electricity config] # price by kw/h -day price = +day price = night price = # ex: 22h30 night hour start = # ex: 6h00 night hour end = -dc charge price = -high speed dc charge price = +dc charge price = +high speed dc charge price = # minimum power in kW that should be delivered during a charge so it can be considered as a high speed charger -high speed dc charge threshold = +high speed dc charge threshold = """ @@ -150,7 +150,7 @@ class ConfigRepository(BaseModel): def _read_file(name): if name is None: name = CONFIG_FILENAME - with open(name, "r") as f: + with open(name, "r", encoding="utf-8") as f: return f.read() @staticmethod @@ -186,7 +186,7 @@ class ConfigRepository(BaseModel): @staticmethod def _write(name, config): - with open(name, "w") as f: + with open(name, "w", encoding="utf-8") as f: config.write(f) @staticmethod diff --git a/psa-car-controller/psacc/repository/db.py b/psa-car-controller/psacc/repository/db.py index 2346395..6969e21 100644 --- a/psa-car-controller/psacc/repository/db.py +++ b/psa-car-controller/psacc/repository/db.py @@ -187,7 +187,7 @@ class Database: @staticmethod def get_battery_curve(conn, start_at, stop_at, vin): battery_curves = [] - res = conn.execute("""SELECT date, level, rate, autonomy + res = conn.execute("""SELECT date, level, rate, autonomy FROM battery_curve WHERE start_at=? and date<=? and VIN=?;""", (start_at, stop_at, vin)).fetchall() diff --git a/psa-car-controller/web/tools/figurefilter.py b/psa-car-controller/web/tools/figurefilter.py index a186d43..83cb585 100644 --- a/psa-car-controller/web/tools/figurefilter.py +++ b/psa-car-controller/web/tools/figurefilter.py @@ -9,7 +9,6 @@ from dash.dependencies import Output, Input logger = logging.getLogger(__name__) - class Graph: def __init__(self, graph_id, x, y: [], figure): self.graph_id = graph_id @@ -97,7 +96,7 @@ class FigureFilter: res = "{" i = ord("a") for table in self.tables: - res+= f'"{table.table_id}": {chr(i)},' + res += f'"{table.table_id}": {chr(i)},' i += 1 res = res[:-1] + "}" return res diff --git a/psa-car-controller/web/view/config_views.py b/psa-car-controller/web/view/config_views.py index 51ecac2..57c01e3 100644 --- a/psa-car-controller/web/view/config_views.py +++ b/psa-car-controller/web/view/config_views.py @@ -109,7 +109,7 @@ def log_layout(): "white-space": "pre-line"}, children=log_text, className="m-3 bg-light h5"), - html.Div(id="empty-div")]) + html.Div(id="empty-div")]) def config_layout(activeTabs="log"): diff --git a/psa-car-controller/web/view/views.py b/psa-car-controller/web/view/views.py index 5381380..b593d8a 100644 --- a/psa-car-controller/web/view/views.py +++ b/psa-car-controller/web/view/views.py @@ -357,8 +357,8 @@ def serve_layout(): ], id="tab_trips_popup", size="xl", - ) - ]), + ) + ]), dbc.Tab(label="Charge", tab_id="charge", id="tab_charge", children=[figures.battery_table, dbc.Modal(