diff --git a/README.md b/README.md index c291db2..e0d124c 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ For this you need to install Python. I have installed Python 3.9.13. [Here is more information about installing Python](https://realpython.com/installing-python/) Steps: -- Download the source code of [hyundai_kia_connect_api v1.40.11 here](https://github.com/Hyundai-Kia-Connect/hyundai_kia_connect_api/releases/tag/v1.40.11) +- Download the source code of [hyundai_kia_connect_api v1.47.1 here](https://github.com/Hyundai-Kia-Connect/hyundai_kia_connect_api/releases/tag/v1.47.1) - Download the [latest hyundai_kia_connect_monitor release here](https://github.com/ZuinigeRijder/hyundai_kia_connect_monitor/releases) - Extract both and move the hyundai_kia_connect_api subfolder of hyundai_kia_connect_api-1.40.11 under hyundai_kia_connect_monitor. - Then configure monitor.cfg diff --git a/debug.py b/debug.py index 687419d..f627399 100644 --- a/debug.py +++ b/debug.py @@ -95,10 +95,11 @@ def print_info(vehicles): print("Last updated at : " + str(vehicle.last_updated_at)) print("Location : " + str(vehicle.location)) print("Air temperature : " + str(vehicle.air_temperature)) - print("Driving distance : " + str(vehicle.ev_driving_distance)) - print("Charge limits : " + str(vehicle.ev_charge_limits)) + print("Driving range : " + str(vehicle.ev_driving_range)) + print("Charge limits AC : " + str(vehicle.ev_charge_limits_ac)) + print("Charge limits DC : " + str(vehicle.ev_charge_limits_dc)) print("Odometer : " + str(vehicle.odometer)) - print("Total driving distance: " + str(vehicle.total_driving_distance)) + print("Total driving range : " + str(vehicle.total_driving_range)) print("Battery SOC : " + str(vehicle.ev_battery_percentage)) print("12V percentage : " + str(vehicle.car_battery_percentage)) print("Locked : " + str(vehicle.is_locked)) diff --git a/monitor.py b/monitor.py index 2cd1fa3..7aa7e13 100644 --- a/monitor.py +++ b/monitor.py @@ -144,7 +144,9 @@ def get_append_data(): if USE_GEOCODE: if len(vehicle.geocode) > 0: # replace comma by semicolon for easier splitting - geocode = ', ' + vehicle.geocode[0].replace(',', ';') + geocode_name = vehicle.geocode[0] + if geocode_name != '': + geocode = ', ' + geocode_name.replace(',', ';') line = ( str(vehicle.last_updated_at) + diff --git a/summary.py b/summary.py index e07f440..2f1055f 100644 --- a/summary.py +++ b/summary.py @@ -48,6 +48,13 @@ def get_vin_arg(): return '' +def safe_divide(numerator, denumerator): + """ safe_divide """ + if denumerator == 0.0: + return 1.0 + return numerator/denumerator + + def to_int(string): """ convert to int """ if "None" in string: @@ -100,6 +107,7 @@ def to_float(string): MONTH = True YEAR = True +HIGHEST_ODO = 0.0 # == read monitor in monitor.cfg =========================== config_parser = configparser.ConfigParser() @@ -296,12 +304,12 @@ def print_summary(prefix, current, values, split, factor): t_elapsed_minutes = max(values[T_ELAPSED_MINUTES], 1) t_soc_cur = values[T_SOC_CUR] - t_soc_avg = round(values[T_SOC_AVG] / t_elapsed_minutes) + t_soc_avg = round(safe_divide(values[T_SOC_AVG], t_elapsed_minutes)) t_soc_min = values[T_SOC_MIN] t_soc_max = values[T_SOC_MAX] t_volt12_cur = values[T_VOLT12_CUR] - t_volt12_avg = round(values[T_VOLT12_AVG] / t_elapsed_minutes) + t_volt12_avg = round(safe_divide(values[T_VOLT12_AVG], t_elapsed_minutes)) t_volt12_min = values[T_VOLT12_MIN] t_volt12_max = values[T_VOLT12_MAX] @@ -318,10 +326,10 @@ def print_summary(prefix, current, values, split, factor): if discharged_kwh < -MIN_CONSUMPTION_DISCHARGE_KWH: # skip inaccurate cost = discharged_kwh * -AVERAGE_COST_PER_KWH cost_str = f"{cost:10.2f}" - km_mi_per_kwh = delta_odo / -discharged_kwh + km_mi_per_kwh = safe_divide(delta_odo, -discharged_kwh) km_mi_per_kwh_str = f"{km_mi_per_kwh:7.1f}" if km_mi_per_kwh > 0.0: - kwh_per_km_mi = 100 / km_mi_per_kwh + kwh_per_km_mi = safe_divide(100, km_mi_per_kwh) kwh_per_km_mi_str = f"{kwh_per_km_mi:10.1f}" else: # do not show positive discharges @@ -483,35 +491,35 @@ def print_summaries(current_day_values, totals, split, last): current_day_values, t_year, split, - 1/trips + safe_divide(1, trips) ) print_summary( f"DAYAVG , {day_str:10}, {DAY_COUNTER:3}d ", current_day_values, t_year, split, - 1/DAY_COUNTER + safe_divide(1, DAY_COUNTER) ) print_summary( f"WEEKAVG , {day_str:10}, {DAY_COUNTER:3}d ", current_day_values, t_year, split, - 1/DAY_COUNTER*7 + safe_divide(7, DAY_COUNTER) ) print_summary( f"MONTHAVG, {day_str:10}, {DAY_COUNTER:3}d ", current_day_values, t_year, split, - 365/DAY_COUNTER/12 + safe_divide(365/12, DAY_COUNTER) ) print_summary( f"YEARLY , {day_str:10}, {DAY_COUNTER:3}d ", current_day_values, t_year, split, - 365/DAY_COUNTER + safe_divide(365, DAY_COUNTER) ) if SHEETUPDATE and last: day_info = current_day.strftime("%a %H:%M") @@ -655,12 +663,20 @@ def keep_track_of_totals(values, split, prev_split): return values -def handle_line(split, prev_split, totals, last): +def handle_line(linecount, split, prev_split, totals, last): """ handle_line """ debug(f"handle_line: {split}, {prev_split}") + global HIGHEST_ODO # pylint:disable=global-statement odo = to_float(split[ODO].strip()) if odo == 0.0: + debug(f"bad odo: {odo}") return totals # bad line + if odo < HIGHEST_ODO: + debug(f"taking over highest ODO: {HIGHEST_ODO} odo={odo}") + odo = HIGHEST_ODO + else: + HIGHEST_ODO = odo + current_day = parser.parse(split[DT]) current_day_values = init( current_day, @@ -679,6 +695,11 @@ def handle_line(split, prev_split, totals, last): ) return totals + if (split[DT] == prev_split[DT]) and ( + (split[LAT] != prev_split[LAT]) or (split[LON] != prev_split[LON]) + ): + print(f"Warning: timestamp wrong line {linecount}\nSPLIT: {split}\nPREV : {prev_split}") # noqa pylint:disable=line-too-long + t_trip = totals[T_TRIP] t_week = totals[T_WEEK] t_month = totals[T_MONTH] @@ -742,8 +763,14 @@ def summary(): eod_line = line[0:11] + "00:00:00" + prev_line[19:] debug(f"prev_line: {prev_line}\n eod_line: {eod_line}") last_split = eod_line.split(',') - totals = handle_line(last_split, prev_split, totals, False) + totals = handle_line( + linecount, + last_split, + prev_split, + totals, + False) totals = handle_line( + linecount, split, prev_split, totals, @@ -764,9 +791,10 @@ def summary(): "00:00:00" + prev_line[19:] last_split = eod_line.split(',') debug(f"prev_line: {prev_line}\n eod_line: {eod_line}") - totals = handle_line(last_split, prev_split, totals, False) + totals = handle_line(linecount, last_split, prev_split, totals, False) # and show summaries handle_line( + linecount, last_split, last_split, totals,