|
22 | 22 | from .Token import Token |
23 | 23 | from .Vehicle import ( |
24 | 24 | Vehicle, |
| 25 | + VehicleProfile, |
25 | 26 | DailyDrivingStats, |
26 | 27 | MonthTripInfo, |
27 | 28 | DayTripInfo, |
@@ -152,6 +153,119 @@ def __init__(self, region: int, brand: int, language: str) -> None: |
152 | 153 | "https://accounts-eu.genesis.com/realms/eugenesisidm/ga-api/redirect2" |
153 | 154 | ) |
154 | 155 |
|
| 156 | + @staticmethod |
| 157 | + def _str(v): |
| 158 | + """Coerce int-or-string option values to strings for capability comparisons.""" |
| 159 | + if v is None: |
| 160 | + return None |
| 161 | + return str(v) |
| 162 | + |
| 163 | + def _map_vehicle_profile(self, profile_data: dict) -> VehicleProfile: |
| 164 | + basic = profile_data.get("basic", {}) |
| 165 | + device = profile_data.get("device", {}) |
| 166 | + option = profile_data.get("option", {}) |
| 167 | + service_option = profile_data.get("serviceOption", {}) |
| 168 | + battery_type = profile_data.get("batteryType", {}) |
| 169 | + detail_info = profile_data.get("detailInfo", {}) |
| 170 | + dtc_category = profile_data.get("dtcCategory", []) |
| 171 | + |
| 172 | + seat_heater_vent = option.get("seatHeaterVent", {}) |
| 173 | + |
| 174 | + # The EU API returns some option fields as integers and others as strings. |
| 175 | + # Capability properties (steering_wheel_heater_supported, etc.) compare |
| 176 | + # against string values ("1", "0"), so we coerce integer fields to strings. |
| 177 | + return VehicleProfile( |
| 178 | + # basic |
| 179 | + brand=basic.get("brand"), |
| 180 | + country=basic.get("country"), |
| 181 | + ota_update_supported=basic.get("ecuOtaUpdateSupport") == 1, |
| 182 | + remote_ota_update_supported=basic.get("ecuRemoteOTAUpdateSupport") == 1, |
| 183 | + # device |
| 184 | + sim_status=device.get("simStatus"), |
| 185 | + sim_start_date=device.get("simStartDate"), |
| 186 | + sim_end_date=device.get("simEndDate"), |
| 187 | + head_unit_type=device.get("headUnitType"), |
| 188 | + head_unit_model_name=device.get("headUnitModelName"), |
| 189 | + head_unit_version=device.get("currentHeadUnitVersion"), |
| 190 | + platform=device.get("platform"), |
| 191 | + navi_applied=device.get("naviApplied") == 1, |
| 192 | + web_manual_url=device.get("webManualUrl"), |
| 193 | + # option — string fields that may arrive as ints |
| 194 | + air_control_type=option.get("airControlType"), |
| 195 | + driver_seat_location=option.get("drvSeatLoc"), |
| 196 | + remote_control=option.get("remoteControl"), |
| 197 | + heating1=option.get("heating1"), |
| 198 | + heating_front_window=option.get("heatingFrontWindow"), |
| 199 | + steering_wheel_heat_option=option.get("strgWhlHeatOption"), |
| 200 | + heating_steering_wheel=option.get("heatingSteeringWheel"), |
| 201 | + heating_side_mirror=option.get("heatingSideMirror"), |
| 202 | + heating_rear_window=option.get("heatingRearWindow"), |
| 203 | + light_only_available=self._str(option.get("lightOnlyAvailable")), |
| 204 | + horn_light_available=self._str(option.get("hornLightAvailable")), |
| 205 | + hvac_temp_type=option.get("hvacTempType"), |
| 206 | + remote_control_waiting_time=option.get("remoteControlWaitingTime"), |
| 207 | + window_safety_option2=option.get("windowSafetyOption2"), |
| 208 | + sunroof_option=self._str(option.get("sunRoofOption")), |
| 209 | + digital_key2=self._str(option.get("digitalKey2")), |
| 210 | + remote_heat_control=option.get("remoteHeatControl"), |
| 211 | + air_purifier_option=self._str(option.get("airPurifierOption")), |
| 212 | + dvrs_option=option.get("dvrsOption"), |
| 213 | + ignition_control_option=self._str(option.get("ignCtrlOption")), |
| 214 | + seat_heater_vent_front_left=seat_heater_vent.get("flSeatHeat"), |
| 215 | + seat_heater_vent_front_right=seat_heater_vent.get("frSeatHeat"), |
| 216 | + seat_heater_vent_rear_left=seat_heater_vent.get("rlSeatHeat"), |
| 217 | + seat_heater_vent_rear_right=seat_heater_vent.get("rrSeatHeat"), |
| 218 | + ev_alarm_option_info=self._str(option.get("evAlarmOptionInfo")), |
| 219 | + remote_air_ctrl_control_option=option.get("remoteAirCtrlControlOption"), |
| 220 | + # serviceOption |
| 221 | + battery_warning_service=service_option.get("batteryWarningService") == 1, |
| 222 | + schedule_link_service=service_option.get("scheduleLinkService") == 1, |
| 223 | + center_user_profile_option=service_option.get("centerUserProfileOption"), |
| 224 | + final_destination_noti=service_option.get("finalDestinationNoti") == 1, |
| 225 | + valet_service_option=service_option.get("valetServiceOption") == 1, |
| 226 | + notification_support=service_option.get("notificationSupport") == 1, |
| 227 | + remote_valet_act_option=service_option.get("remoteValetActOption") == 1, |
| 228 | + alert_service_option=service_option.get("alertServiceOption") == 1, |
| 229 | + media_streaming_service=service_option.get("mediaStreamingService"), |
| 230 | + media_streaming_selection_option=service_option.get( |
| 231 | + "mediaStreamingSelectionOption" |
| 232 | + ) |
| 233 | + == 1, |
| 234 | + idle_alert_setting_service=service_option.get("idleAlertSettingService") |
| 235 | + == 1, |
| 236 | + engine_idle_time_notification=service_option.get( |
| 237 | + "engineIdleTimeNotification" |
| 238 | + ) |
| 239 | + == 1, |
| 240 | + send2car_option_info=service_option.get("send2CarOptionInfo"), |
| 241 | + speed_event_support=service_option.get("speedEventSupport") == 1, |
| 242 | + # batteryType |
| 243 | + main_battery_type=battery_type.get("mainbatteryType"), |
| 244 | + aux_battery_type=battery_type.get("auxbatteryType"), |
| 245 | + # detailInfo |
| 246 | + sale_model_code=detail_info.get("saleCarmdlCd"), |
| 247 | + body_type=detail_info.get("bodyType"), |
| 248 | + interior_color=detail_info.get("inColor"), |
| 249 | + exterior_color=detail_info.get("outColor"), |
| 250 | + # dtcCategory |
| 251 | + dtc_categories=dtc_category if dtc_category else None, |
| 252 | + ) |
| 253 | + |
| 254 | + def _fetch_vehicle_profiles(self, token: Token, vehicles: list[Vehicle]) -> None: |
| 255 | + for vehicle in vehicles: |
| 256 | + try: |
| 257 | + url = self.SPA_API_URL + f"vehicles/{vehicle.id}/profile" |
| 258 | + headers = self._get_authenticated_headers(token) |
| 259 | + response = requests.get(url, headers=headers, timeout=30) |
| 260 | + _check_response_for_errors(response.json()) |
| 261 | + profile_data = response.json().get("resMsg", {}).get("vinInfo", []) |
| 262 | + if profile_data: |
| 263 | + vehicle.profile = self._map_vehicle_profile(profile_data[0]) |
| 264 | + except Exception: |
| 265 | + _LOGGER.debug( |
| 266 | + f"{DOMAIN} - Vehicle profile fetch failed for {vehicle.id}" |
| 267 | + ) |
| 268 | + |
155 | 269 | def login( |
156 | 270 | self, |
157 | 271 | username: str, |
|
0 commit comments