diff --git a/trip_parser.py b/trip_parser.py index 227622c..4697c88 100644 --- a/trip_parser.py +++ b/trip_parser.py @@ -19,6 +19,7 @@ class TripParser: return TripParser.get_thermal_consumption, self.__is_refuel if self.car.is_hybrid(): return TripParser.get_hybrid_consumption, self.__is_refuel_or_recharging + raise ValueError("Unknown car type") @staticmethod def get_thermal_consumption(start, end): @@ -43,24 +44,24 @@ class TripParser: if fuel_consumption < 0: logger.debugv("refuel detected") return True - elif TripParser.is_recharging(decharge, fuel_consumption, distance): + if TripParser.is_recharging(decharge, distance): logger.debugv("charge detected") return True return False def __is_refuel(self, start, end, distance): - decharge, fuel_consumption = self.get_level_consumption(start, end) + fuel_consumption = self.get_level_consumption(start, end)[1] if fuel_consumption < 0: logger.debugv("refuel detected") return True return False def __is_recharging(self, start, end, distance): - decharge, fuel_consumption = self.get_level_consumption(start, end) - return TripParser.is_recharging(decharge, fuel_consumption, distance) + decharge = self.get_level_consumption(start, end)[0] + return TripParser.is_recharging(decharge, distance) @staticmethod - def is_recharging(decharge, _, distance): + def is_recharging(decharge, distance): # A margin of two is set because battery level can increase with regeneration system or temperature change. # If distance is bigger than 0 but charge bigger than five there is probably missing point and we assume that # regeneration/temperature can't increase by 5 percent the battery level diff --git a/utils.py b/utils.py index 0bac309..9e080e1 100644 --- a/utils.py +++ b/utils.py @@ -7,7 +7,7 @@ import requests from MyLogger import logger -def get_temp(latitude:str, longitude:str, api_key:str) -> float: +def get_temp(latitude: str, longitude: str, api_key: str) -> float: try: if not (latitude is None or longitude is None or api_key is None): weather_rep = requests.get("https://api.openweathermap.org/data/2.5/onecall", @@ -22,6 +22,8 @@ def get_temp(latitude:str, longitude:str, api_key:str) -> float: logger.error("Can't connect to openweathermap :%s", traceback.format_exc()) except KeyError: logger.error("Unable to get temperature from openweathermap :%s", traceback.format_exc()) + return None + def rate_limit(limit, every): def limit_decorator(fn): @@ -39,4 +41,4 @@ def rate_limit(limit, every): return wrapper - return limit_decorator \ No newline at end of file + return limit_decorator