-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathdebug.py
More file actions
174 lines (151 loc) · 6.33 KB
/
debug.py
File metadata and controls
174 lines (151 loc) · 6.33 KB
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# == debug.py Author: Zuinige Rijder =========================================
"""Simple Python3 script to debug hyundai_kia_connect_api values"""
import configparser
from datetime import datetime
import logging
from hyundai_kia_connect_api import VehicleManager, Vehicle
from monitor_utils import die, get_filepath, get, get_bool, to_int
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"]
USE_GEOCODE = get_bool(monitor_settings, "use_geocode", False)
USE_GEOCODE_EMAIL = get_bool(monitor_settings, "use_geocode_email", False)
GEOCODE_PROVIDER = to_int(
get(monitor_settings, "geocode_provider", "1")
) # 1=OPENSTREETMAP 2=GOOGLE
if GEOCODE_PROVIDER < 1 or GEOCODE_PROVIDER > 2:
die("Invalid GEOCODE_PROVIDER in monitor.cfg, expected 1 or 2")
GOOGLE_API_KEY = get(monitor_settings, "google_api_key", "")
if len(GOOGLE_API_KEY) == 0:
GOOGLE_API_KEY = None # default no API key needed for OPENSTREETMAP
if GEOCODE_PROVIDER == 2 and GOOGLE_API_KEY is None:
die("Missing GOOGLE_API_KEY in monitor.cfg")
LANGUAGE = monitor_settings["language"]
# == 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,
geocode_api_enable=USE_GEOCODE,
geocode_api_use_email=USE_GEOCODE_EMAIL,
geocode_provider=GEOCODE_PROVIDER,
geocode_api_key=GOOGLE_API_KEY,
language=LANGUAGE,
)
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
vm.update_all_vehicles_with_cached_state() # do twice to check geocode cache
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)