From a4334d62ead031fa5dbae99686eaf90cb253a4b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cas=20Eli=C3=ABns?= Date: Fri, 1 May 2026 15:34:33 +0200 Subject: [PATCH 1/3] Add None check to trip_parser.py --- .../psacc/application/trip_parser.py | 36 +++++++++++++++---- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/psa_car_controller/psacc/application/trip_parser.py b/psa_car_controller/psacc/application/trip_parser.py index 6b066b3b..06bad5a7 100644 --- a/psa_car_controller/psacc/application/trip_parser.py +++ b/psa_car_controller/psacc/application/trip_parser.py @@ -25,19 +25,35 @@ def __get_energy_method(self) -> [Callable]: @staticmethod def get_thermal_consumption(start, end): - return [0, start[LEVEL_FUEL] - end[LEVEL_FUEL]] + try: + if start[LEVEL_FUEL] is None or end[LEVEL_FUEL] is None: + return [0, 0] + return [0, start[LEVEL_FUEL] - end[LEVEL_FUEL]] + except (KeyError, IndexError, TypeError): + return [0, 0] @staticmethod def get_elec_consumption(start, end): - return [start[LEVEL] - end[LEVEL], 0] + try: + start_level = start[LEVEL] + end_level = end[LEVEL] + if start_level is None or end_level is None: + return [0, 0] + return [start_level - end_level, 0] + except (KeyError, IndexError, TypeError): # TypeError handles None start/end + return [0, 0] @staticmethod def get_hybrid_consumption(start, end): res = [] - for energy in [LEVEL, LEVEL_FUEL]: - if start[energy] is not None and end[energy] is not None: - res.append(start[energy] - end[energy]) - else: + try: + for energy in [LEVEL, LEVEL_FUEL]: + if start[energy] is not None and end[energy] is not None: + res.append(start[energy] - end[energy]) + else: + res.append(0) + except (KeyError, IndexError, TypeError): + while len(res) < 2: res.append(0) return res @@ -50,7 +66,6 @@ def __is_refuel_or_recharging(self, start, end, distance): logger.debugv("charge detected") return True return False - # pylint: disable=unused-argument def __is_refuel(self, start, end, distance): fuel_consumption = self.get_level_consumption(start, end)[1] @@ -60,6 +75,13 @@ def __is_refuel(self, start, end, distance): return False def __is_recharging(self, start, end, distance): + try: + start_level = start[LEVEL] + end_level = end[LEVEL] + if start_level is None or end_level is None: + return False + except (KeyError, IndexError, TypeError): + return False decharge = self.get_level_consumption(start, end)[0] return TripParser.is_recharging(decharge, distance) From 8553b439ddf2b12f7ef9474b78e11d51823d41b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cas=20Eli=C3=ABns?= Date: Fri, 1 May 2026 15:36:03 +0200 Subject: [PATCH 2/3] Add generated test files to gitignore --- .gitignore | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 43438d8c..fea4886e 100644 --- a/.gitignore +++ b/.gitignore @@ -151,4 +151,10 @@ cars.json certs/ *.log.* -.vscode/ \ No newline at end of file +.vscode/ + +tests/data/otp_test2.bin +tests/data/test_car.json +tests/mypeugeot.apk +tests/mypeugeot.apk.bz2 +tests/test_charge_control.json \ No newline at end of file From 64d3c4feb9c618c228c69cdc0a9b2e041baf4f40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cas=20Eli=C3=ABns?= Date: Fri, 1 May 2026 15:46:32 +0200 Subject: [PATCH 3/3] Formatting fix --- psa_car_controller/psacc/application/trip_parser.py | 1 + 1 file changed, 1 insertion(+) diff --git a/psa_car_controller/psacc/application/trip_parser.py b/psa_car_controller/psacc/application/trip_parser.py index 06bad5a7..51f5ec87 100644 --- a/psa_car_controller/psacc/application/trip_parser.py +++ b/psa_car_controller/psacc/application/trip_parser.py @@ -67,6 +67,7 @@ def __is_refuel_or_recharging(self, start, end, distance): return True return False # pylint: disable=unused-argument + def __is_refuel(self, start, end, distance): fuel_consumption = self.get_level_consumption(start, end)[1] if fuel_consumption < 0: