From 9ae89ef7d35e24a2836f6b8394c7448f18c9e5b6 Mon Sep 17 00:00:00 2001 From: Zuinige Rijder Date: Mon, 9 Dec 2024 12:56:05 +0100 Subject: [PATCH] Support Sportage HEV by providing some default values in monitor.py --- monitor.py | 9 ++++++++- monitor_utils.py | 7 +++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/monitor.py b/monitor.py index 3a32ef9..f109cc8 100644 --- a/monitor.py +++ b/monitor.py @@ -53,6 +53,7 @@ get_bool, get_filepath, get_last_line, + get_safe_bool, get_safe_datetime, get_safe_float, km_to_mile, @@ -439,7 +440,13 @@ def handle_one_vehicle( newest_updated_at = newest_updated_at_corrected newest_updated_at = max(newest_updated_at, previous_updated_at) - line = f"{newest_updated_at}, {location_longitude}, {location_latitude}, {vehicle.engine_is_running}, {vehicle.car_battery_percentage}, {float_to_string_no_trailing_zero(odometer)}, {vehicle.ev_battery_percentage}, {vehicle.ev_battery_is_charging}, {vehicle.ev_battery_is_plugged_in}, {geocode}, {ev_driving_range}" # noqa + ev_battery_percentage = vehicle.ev_battery_percentage + if ev_battery_percentage is None: + ev_battery_percentage = 100 + ev_battery_is_charging = get_safe_bool(vehicle.ev_battery_is_charging) + ev_battery_is_plugged_in = get_safe_bool(vehicle.ev_battery_is_plugged_in) + + line = f"{newest_updated_at}, {location_longitude}, {location_latitude}, {vehicle.engine_is_running}, {vehicle.car_battery_percentage}, {float_to_string_no_trailing_zero(odometer)}, {ev_battery_percentage}, {ev_battery_is_charging}, {ev_battery_is_plugged_in}, {geocode}, {ev_driving_range}" # noqa if "None, None" in line: # something gone wrong, retry logging.warning(f"Skipping Unexpected line: {line}") return True # exit subroutine with error diff --git a/monitor_utils.py b/monitor_utils.py index 5f1ebb1..96ef3fa 100644 --- a/monitor_utils.py +++ b/monitor_utils.py @@ -221,6 +221,13 @@ def float_to_string_no_trailing_zero(input_value: float) -> str: return (f"{input_value:.1f}").rstrip("0").rstrip(".") +def get_safe_bool(value: bool) -> bool: + """get safe bool""" + if value is None: + return False + return value + + def is_true(string: str) -> bool: """return if string is true (True or not 0 digit)""" if "None" in string: