-
Notifications
You must be signed in to change notification settings - Fork 3
/
debug.py
152 lines (133 loc) · 5.42 KB
/
debug.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# == debug.py Author: Zuinige Rijder =========================================
""" Simple Python3 script to debug hyundai_kia_connect_api values """
import configparser
from datetime import datetime
import logging
import logging.config
from hyundai_kia_connect_api import VehicleManager, Vehicle
from monitor_utils import get_filepath
logging.basicConfig(level=logging.DEBUG)
# == read monitor settings in monitor.cfg ==================
parser = configparser.ConfigParser()
parser.read(get_filepath("monitor.cfg"))
monitor_settings = dict(parser.items("monitor", raw=True))
REGION = monitor_settings["region"]
BRAND = monitor_settings["brand"]
USERNAME = monitor_settings["username"]
PASSWORD = monitor_settings["password"]
PIN = monitor_settings["pin"]
# == get_child_value =========================================================
def get_child_value(data: dict, key: str) -> dict:
"""get child value"""
value = data
for k in key.split("."):
try:
value = value[k]
# pylint: disable=broad-except
except Exception:
try:
value = value[int(k)]
# pylint: disable=broad-except
except Exception:
value = {}
return value
# == print_indent ==========================================================
def print_indent(indent: int) -> None:
"""print indent"""
print()
i = 0
while i < indent:
i += 1
print(" ", end="")
# == print_indented ==========================================================
def print_indented(string: str) -> None:
"""print indented"""
indent = 0
for char in string:
if char == "{" or char == "[" or char == "(":
print_indent(indent)
print(char, end="")
indent += 1
print_indent(indent)
elif char == "}" or char == "]" or char == ")":
indent -= 1
print_indent(indent)
print(char, end="")
elif char == ",":
print(char, end="")
print_indent(indent)
else:
print(char, end="")
print()
# == print_info ==========================================================
def print_info(vehicles: dict) -> None:
"""print info"""
for key in vehicles:
vehicle: Vehicle = vehicles[key]
target_soc_list = get_child_value(
vehicle.data,
"vehicleStatus.evStatus.reservChargeInfos.targetSOClist",
)
print("targetSOClist:")
print_indented(str(target_soc_list))
print("Summary: ")
for item in target_soc_list:
target_soc_level = get_child_value(item, "targetSOClevel")
target_soc_range = get_child_value(
item, "dte.rangeByFuel.totalAvailableRange.value"
)
print("Target SOC level : " + str(target_soc_level))
print("Target SOC range : " + str(target_soc_range))
print("Last updated at : " + str(vehicle.last_updated_at))
print("Location Last updated at: " + str(vehicle.location_last_updated_at))
print("Location : " + str(vehicle.location))
print("Air temperature : " + str(vehicle.air_temperature))
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 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))
vm = VehicleManager(
region=int(REGION),
brand=int(BRAND),
username=USERNAME,
password=PASSWORD,
pin=PIN,
)
for KEY in vm.vehicles:
VEHICLE = vm.vehicles[KEY]
print(f"timezone: {VEHICLE.timezone}")
print(f"vehicle: {VEHICLE}")
vm.check_and_refresh_token()
# vm.force_refresh_all_vehicles_states()
vm.update_all_vehicles_with_cached_state() # needed >= 2.0.0
for KEY in vm.vehicles:
VEHICLE = vm.vehicles[KEY]
print(f"timezone: {VEHICLE.timezone}")
print(f"Last updated at: {VEHICLE.last_updated_at}")
print(f"Location Last updated at: {VEHICLE.location_last_updated_at}")
print(f"Location: {VEHICLE.location}")
print(f"vehicle: {VEHICLE}")
now = datetime.now()
yyyymm = now.strftime("%Y%m")
yyyymmdd = now.strftime("%Y%m%d")
vm.update_month_trip_info(VEHICLE.id, yyyymm)
if VEHICLE.month_trip_info is not None:
for day in VEHICLE.month_trip_info.day_list: # ordered on day
if yyyymmdd == day.yyyymmdd: # in example only interested in current day
vm.update_day_trip_info(VEHICLE.id, day.yyyymmdd)
if VEHICLE.day_trip_info is not None:
for trip in reversed(
VEHICLE.day_trip_info.trip_list
): # show oldest first
print(
f"{day.yyyymmdd},{trip.hhmmss},{trip.drive_time},{trip.idle_time},{trip.distance},{trip.avg_speed},{trip.max_speed}" # noqa
)
print(type(vm.vehicles))
print(vm.vehicles)
print("Pretty print vm.vehicles:")
print_indented(str(vm.vehicles))
print_info(vm.vehicles)