|
18 | 18 | POIInfo, |
19 | 19 | ) |
20 | 20 | from .Token import Token |
21 | | -from .Vehicle import Vehicle |
| 21 | +from .Vehicle import Vehicle, VehicleProfile |
22 | 22 |
|
23 | 23 | from .utils import ( |
24 | 24 | bool_or_none, |
|
27 | 27 | normalize_battery_soc, |
28 | 28 | parse_datetime, |
29 | 29 | pressure_or_none, |
| 30 | + str_or_none, |
30 | 31 | window_is_open, |
31 | 32 | ) |
32 | 33 |
|
@@ -232,8 +233,117 @@ def get_vehicles(self, token: Token) -> list[Vehicle]: |
232 | 233 | ccu_ccs2_protocol_support=entry["ccuCCS2ProtocolSupport"], |
233 | 234 | ) |
234 | 235 | result.append(vehicle) |
| 236 | + if self.supports_vehicle_profile: |
| 237 | + self._fetch_vehicle_profiles(token, result) |
235 | 238 | return result |
236 | 239 |
|
| 240 | + def _fetch_vehicle_profiles(self, token: Token, vehicles: list[Vehicle]) -> None: |
| 241 | + for vehicle in vehicles: |
| 242 | + try: |
| 243 | + url = self.SPA_API_URL + f"vehicles/{vehicle.id}/profile" |
| 244 | + headers = self._get_authenticated_headers(token) |
| 245 | + response = self.session.get(url, headers=headers) |
| 246 | + _check_response_for_errors(response.json()) |
| 247 | + profile_data = response.json().get("resMsg", {}).get("vinInfo", []) |
| 248 | + if profile_data: |
| 249 | + vehicle.profile = self._map_vehicle_profile(profile_data[0]) |
| 250 | + except Exception: |
| 251 | + _LOGGER.debug( |
| 252 | + f"{DOMAIN} - Vehicle profile fetch failed for {vehicle.id}" |
| 253 | + ) |
| 254 | + |
| 255 | + def _map_vehicle_profile(self, profile_data: dict) -> VehicleProfile: |
| 256 | + """Map API profile response dict to VehicleProfile dataclass.""" |
| 257 | + basic = profile_data.get("basic", {}) |
| 258 | + device = profile_data.get("device", {}) |
| 259 | + option = profile_data.get("option", {}) |
| 260 | + service_option = profile_data.get("serviceOption", {}) |
| 261 | + battery_type = profile_data.get("batteryType", {}) |
| 262 | + detail_info = profile_data.get("detailInfo", {}) |
| 263 | + dtc_category = profile_data.get("dtcCategory", []) |
| 264 | + |
| 265 | + seat_heater_vent = option.get("seatHeaterVent", {}) |
| 266 | + |
| 267 | + # The API returns some option fields as integers and others as strings. |
| 268 | + # Capability properties compare against string values ("1", "0"), so |
| 269 | + # coerce integer fields to strings via str_or_none (None-safe). |
| 270 | + return VehicleProfile( |
| 271 | + # basic |
| 272 | + brand=basic.get("brand"), |
| 273 | + country=basic.get("country"), |
| 274 | + ota_update_supported=basic.get("ecuOtaUpdateSupport") == 1, |
| 275 | + remote_ota_update_supported=basic.get("ecuRemoteOTAUpdateSupport") == 1, |
| 276 | + # device |
| 277 | + sim_status=device.get("simStatus"), |
| 278 | + sim_start_date=device.get("simStartDate"), |
| 279 | + sim_end_date=device.get("simEndDate"), |
| 280 | + head_unit_type=device.get("headUnitType"), |
| 281 | + head_unit_model_name=device.get("headUnitModelName"), |
| 282 | + head_unit_version=device.get("currentHeadUnitVersion"), |
| 283 | + platform=device.get("platform"), |
| 284 | + navi_applied=device.get("naviApplied") == 1, |
| 285 | + web_manual_url=device.get("webManualUrl"), |
| 286 | + # option — string fields that may arrive as ints |
| 287 | + air_control_type=option.get("airControlType"), |
| 288 | + driver_seat_location=option.get("drvSeatLoc"), |
| 289 | + remote_control=option.get("remoteControl"), |
| 290 | + heating1=option.get("heating1"), |
| 291 | + heating_front_window=option.get("heatingFrontWindow"), |
| 292 | + steering_wheel_heat_option=option.get("strgWhlHeatOption"), |
| 293 | + heating_steering_wheel=option.get("heatingSteeringWheel"), |
| 294 | + heating_side_mirror=option.get("heatingSideMirror"), |
| 295 | + heating_rear_window=option.get("heatingRearWindow"), |
| 296 | + light_only_available=str_or_none(option.get("lightOnlyAvailable")), |
| 297 | + horn_light_available=str_or_none(option.get("hornLightAvailable")), |
| 298 | + hvac_temp_type=option.get("hvacTempType"), |
| 299 | + remote_control_waiting_time=option.get("remoteControlWaitingTime"), |
| 300 | + window_safety_option2=option.get("windowSafetyOption2"), |
| 301 | + sunroof_option=str_or_none(option.get("sunRoofOption")), |
| 302 | + digital_key2=str_or_none(option.get("digitalKey2")), |
| 303 | + remote_heat_control=option.get("remoteHeatControl"), |
| 304 | + air_purifier_option=str_or_none(option.get("airPurifierOption")), |
| 305 | + dvrs_option=option.get("dvrsOption"), |
| 306 | + ignition_control_option=str_or_none(option.get("ignCtrlOption")), |
| 307 | + seat_heater_vent_front_left=seat_heater_vent.get("flSeatHeat"), |
| 308 | + seat_heater_vent_front_right=seat_heater_vent.get("frSeatHeat"), |
| 309 | + seat_heater_vent_rear_left=seat_heater_vent.get("rlSeatHeat"), |
| 310 | + seat_heater_vent_rear_right=seat_heater_vent.get("rrSeatHeat"), |
| 311 | + ev_alarm_option_info=str_or_none(option.get("evAlarmOptionInfo")), |
| 312 | + remote_air_ctrl_control_option=option.get("remoteAirCtrlControlOption"), |
| 313 | + # serviceOption |
| 314 | + battery_warning_service=service_option.get("batteryWarningService") == 1, |
| 315 | + schedule_link_service=service_option.get("scheduleLinkService") == 1, |
| 316 | + center_user_profile_option=service_option.get("centerUserProfileOption"), |
| 317 | + final_destination_noti=service_option.get("finalDestinationNoti") == 1, |
| 318 | + valet_service_option=service_option.get("valetServiceOption") == 1, |
| 319 | + notification_support=service_option.get("notificationSupport") == 1, |
| 320 | + remote_valet_act_option=service_option.get("remoteValetActOption") == 1, |
| 321 | + alert_service_option=service_option.get("alertServiceOption") == 1, |
| 322 | + media_streaming_service=service_option.get("mediaStreamingService"), |
| 323 | + media_streaming_selection_option=service_option.get( |
| 324 | + "mediaStreamingSelectionOption" |
| 325 | + ) |
| 326 | + == 1, |
| 327 | + idle_alert_setting_service=service_option.get("idleAlertSettingService") |
| 328 | + == 1, |
| 329 | + engine_idle_time_notification=service_option.get( |
| 330 | + "engineIdleTimeNotification" |
| 331 | + ) |
| 332 | + == 1, |
| 333 | + send2car_option_info=service_option.get("send2CarOptionInfo"), |
| 334 | + speed_event_support=service_option.get("speedEventSupport") == 1, |
| 335 | + # batteryType |
| 336 | + main_battery_type=battery_type.get("mainbatteryType"), |
| 337 | + aux_battery_type=battery_type.get("auxbatteryType"), |
| 338 | + # detailInfo |
| 339 | + sale_model_code=detail_info.get("saleCarmdlCd"), |
| 340 | + body_type=detail_info.get("bodyType"), |
| 341 | + interior_color=detail_info.get("inColor"), |
| 342 | + exterior_color=detail_info.get("outColor"), |
| 343 | + # dtcCategory |
| 344 | + dtc_categories=dtc_category if dtc_category else None, |
| 345 | + ) |
| 346 | + |
237 | 347 | def _get_time_from_string(self, value, timesection) -> dt.time | None: |
238 | 348 | if value is None: |
239 | 349 | return None |
|
0 commit comments