Skip to content

Commit

Permalink
Support Sportage HEV by providing some default values in monitor.py
Browse files Browse the repository at this point in the history
  • Loading branch information
ZuinigeRijder committed Dec 9, 2024
1 parent 7334764 commit 9ae89ef
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
9 changes: 8 additions & 1 deletion monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
get_bool,
get_filepath,
get_last_line,
get_safe_bool,
get_safe_datetime,
get_safe_float,
km_to_mile,
Expand Down Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions monitor_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 9ae89ef

Please sign in to comment.