Hyundai-Kia-Connect / hyundai_kia_connect_api

This is a Kia UVO and Hyundai Bluelink written in python. It is primary consumed by home assistant. If you are looking for a home assistant Kia / Hyundai implementation please look here: https://github.com/Hyundai-Kia-Connect/kia_uvo. Much of this base code came from reading bluelinky and contributions to the kia_uvo home assistant project.
MIT License
120 stars 70 forks source link

Climate control no longer works after testing API #282

Open snowe2010 opened 1 year ago

snowe2010 commented 1 year ago

Description

Messing around with the master branch hoping to become a contributor. Wrote some tests for USA.

After playing around with it for a bit, suddenly bluelink won't start the climate anymore:

DEBUG    hyundai_kia_connect_api.HyundaiBlueLinkAPIUSA:HyundaiBlueLinkAPIUSA.py:511 hyundai_kia_connect_api - Start engine response: {"errorSubCode":"GEN","systemName":"BLODS","errorSubMessage":"Feature Status is OFF","errorMessage":"Your vehicle does not support this feature.","errorCode":502}

And now my actual Bluelink app will not start the car either. Other functions still work, like lock/unlock and flashing lights.

What I Did

def test_something():
    vm = VehicleManager(
        region=3,
        brand=2,
        username=username,
        password=password,
        pin=pin,
        geocode_api_enable=True,
    )
    vm.check_and_refresh_token()
    vehicle_id = next(iter(vm.vehicles))
    vm.check_and_force_update_vehicles(force_refresh_interval=600)

    # this I changed several times before I realized it was broken in the Bluelink app as well... 
    # I don't know what the original command that started it all was. 
    vm.start_climate(vehicle_id, options=ClimateRequestOptions(set_temp=72, duration=10))

    print(vm.vehicles)
Testing started at 8:40 PM ...
Launching pytest with arguments --log-cli-level DEBUG us_login_test.py::test_something --no-header --no-summary -q in /Users/tylerthrailkill/Documents/dev/oss/hyundai_kia_connect_api/tests

============================= test session starts ==============================
collecting ... collected 1 item

us_login_test.py::test_something

============================== 1 passed in 0.96s ===============================

Process finished with exit code 0

-------------------------------- live log call ---------------------------------
DEBUG    hyundai_kia_connect_api.HyundaiBlueLinkAPIUSA:HyundaiBlueLinkAPIUSA.py:90 hyundai_kia_connect_api - initial API headers: {'content-type': 'application/json;charset=UTF-8', 'accept': 'application/json, text/plain, */*', 'accept-encoding': 'gzip, deflate, br', 'accept-language': 'en-US,en;q=0.9', 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36', 'host': 'api.telematics.hyundaiusa.com', 'origin': 'https://api.telematics.hyundaiusa.com', 'referer': 'https://api.telematics.hyundaiusa.com/login', 'from': 'SPA', 'to': 'ISS', 'language': '0', 'offset': '-7', 'sec-fetch-dest': 'empty', 'sec-fetch-mode': 'cors', 'sec-fetch-site': 'same-origin', 'refresh': 'false', 'encryptFlag': 'false', 'brandIndicator': 'H', 'gen': '2', 'client_id': '***', 'clientSecret': '***'}
DEBUG    urllib3.connectionpool:connectionpool.py:1003 Starting new HTTPS connection (1): api.telematics.hyundaiusa.com:443
DEBUG    urllib3.connectionpool:connectionpool.py:456 https://api.telematics.hyundaiusa.com:443 "POST /v2/ac/oauth/token HTTP/1.1" 200 None
DEBUG    hyundai_kia_connect_api.HyundaiBlueLinkAPIUSA:HyundaiBlueLinkAPIUSA.py:102 hyundai_kia_connect_api - Sign In Response {"access_token":"***","refresh_token":"***","expires_in":"1799","username":"***@***.com"}
DEBUG    hyundai_kia_connect_api.HyundaiBlueLinkAPIUSA:HyundaiBlueLinkAPIUSA.py:107 hyundai_kia_connect_api - Access Token Value ***
DEBUG    hyundai_kia_connect_api.HyundaiBlueLinkAPIUSA:HyundaiBlueLinkAPIUSA.py:108 hyundai_kia_connect_api - Refresh Token Value ***
DEBUG    urllib3.connectionpool:connectionpool.py:456 https://api.telematics.hyundaiusa.com:443 "GET /ac/v2/enrollment/details/***@***.com HTTP/1.1" 200 None
DEBUG    hyundai_kia_connect_api.HyundaiBlueLinkAPIUSA:HyundaiBlueLinkAPIUSA.py:390 hyundai_kia_connect_api - Get Vehicles Response {"enrolledVehicleDetails":[{"packageDetails":[{"assetNumber":"A-S00516536","displayCategory":"Connected Care","packageId":"***","term":"36","renewalDate":"***","packageType":"Connected Care","startDate":"***"},{"assetNumber":"A-***","displayCategory":"Remote","packageId":"***","term":"36","renewalDate":"***","packageType":"Remote","startDate":"***"},{"assetNumber":"A-***","displayCategory":"Guidance","packageId":"***","term":"36","renewalDate":"***","packageType":"Guidance","startDate":"***"}],"driverDetails":[{"driverAddressDetails":[{"city":"***","postalCode":"***","type":"PRIMARY","region":"CO"}],"driver":{"accountId":"***","firstName":"***","lastName":"***","phonesOptIn":[],"tncId":"22","loginId":"***@***.com","preferredDealerCode":"***","driverUserProfile":"N","phones":[],"idmId":"***","userId":"***@***.com","email":"***@***.com"}}],"vehicleDetails":{"svrStatus":"NONE","dynamicBurgerMenu":"https://owners.hyundaiusa.com/content/dam/hyundai/us/myhyundai/image/2023/ioniq-5/limited/exterior/base/digital-teal/Dashboard-01.png/jcr:content/renditions/cq5dam.thumbnail.105.68.png","remoteStartWakeupDays":"seven","enrollmentDate":"***","svdDay":"11","trim":"LIMITED","modelCode":"IONIQ 5","ubiCapabilityInd":"Y","vin":"***","enrollmentId":"***","sideMirrorHeatCapable":"YES","ownersuccession":"1","odometer":"801","nickName":"2023 IONIQ 5","defaultBurgerMenu":"https://owners.hyundaiusa.com/content/dam/hyundai/us/myhyundai/image/2023/ioniq-5/limited/exterior/base/default/Dashboard-01.png/jcr:content/renditions/cq5dam.thumbnail.105.68.png","evStatus":"E","modelYear":"2023","steeringWheelHeatCapable":"YES","defaultDashboard":"https://owners.hyundaiusa.com/content/dam/hyundai/us/myhyundai/image/2023/ioniq-5/limited/exterior/base/default/Dashboard-01.png","vehicleGeneration":"2","starttype":"KEY","enrollmentType":"INDIVIDUAL","sapColorCode":"M9U","bluelinkEnabled":true,"odometerUpdateDate":"20230208191733","fatcAvailable":"Y","color":"TEAL","maintSyncCapable":"YES","brandIndicator":"H","deviceStatus":"ENROLLED","setOffPeak":"1","mapProvider":"HERE","generalBurgerMenu":"https://owners.hyundaiusa.com/content/dam/hyundai/us/myhyundai/image/2023/ioniq-5/general/exterior/base/default/Dashboard-01.png/jcr:content/renditions/cq5dam.thumbnail.105.68.png","interiorColor":"VKE","accessoryCode":"WAVN 5.0","nadid":"***","mit":"7500","regid":"***","blueLink":"Y","waypointInd":"NO","billingInd":"MONTHLY","dynamicDashboard":"https://owners.hyundaiusa.com/content/dam/hyundai/us/myhyundai/image/2023/ioniq-5/limited/exterior/base/digital-teal/Dashboard-01.png","imat":"7500","additionalVehicleDetails":{"temperatureRange":"true","tmuSleepMode":"No","enableHCAModule":"Y","maxTemp":81,"icpParking":0,"remoteLockConsentForRemoteStart":"Yes","calendarVehicleSyncEnable":"Yes","vehicleModemType":"4G","icpAACapable":"N","icpDriveThru":0,"dkType":"DK TYPE UNKNOWN","dynamicSOCText":"Use the slider above to set a charge limit. Charging will stop when this battery level is reached. The limit cannot be set lower than 50% This setting will override all other charge settings if set.","enableRoadSideAssitanceAAAModule":"Y","evAlarmOptionInfo":"Yes","mapOtaAccepted":"N","dkCapable":"Y","combinedHeatSettingsEnable":"N","icpChargingStation":0,"hyundaiHome":"N","wifiHotspotCapable":"N","dkEnrolled":"N","icpAvntCapable":"N","minTemp":63,"icpFuelStation":0,"targetSOCLevelMax":100,"remoteLockConsentForRemoteStartCapable":"Yes","icpCPCapable":"N","enableValetActivate":"N","energyConsoleCapable":"No"},"transmissiontype":"AUTO","bluelinkEnrolled":true,"targetSOCLevel":"50","rearWindowHeatCapable":"YES","preferredDealerCode":"CO032","hmaModel":"NE1","series":"IONIQ 5","enrollmentStatus":"ACTIVE","generalDashboard":"https://owners.hyundaiusa.com/content/dam/hyundai/us/myhyundai/image/2023/ioniq-5/general/exterior/base/default/Dashboard-01.png","userprofilestatus":"Y"},"roleDetails":[{"roleCode":"OWN","roleName":"OWNER"},{"roleCode":"SUB","roleName":"SUBSCRIBER"}],"responseHeaderMap":{}}],"addressDetails":[{"city":"***","street":"***","postalCode":"***","type":"PRIMARY","region":"CO"}],"emergencyContacts":[{"firstName":"***","lastName":"***","contactId":"***","phones":[{"number":"***","type":"mobile","order":1}],"relationship":"spouse","email":"***@***.com"}],"user":{"accountId":"**","firstName":"***","lastName":"***","phonesOptIn":[{"number":"***","primaryPhoneIndicator":"YES","fccOptIn":"YES","type":"MOBILE"}],"loginId":"***@***.com","additionalUserDetails":{"userProfileUpdate":"N","timezoneOffset":-7,"billingAccountNumber":"***","appRating":"N","geoLocationConsent":"Y","timezoneAbbr":"MST","otaAcceptance":"N","telematicsPhoneNumber":"***"},"tncFlag":"N","phones":[{"number":"***","type":"cell","order":1}],"idmId":"***","userId":"***@***.com","notificationEmail":"***@***.com","email":"***@***.com"}}
DEBUG    hyundai_kia_connect_api.HyundaiBlueLinkAPIUSA:HyundaiBlueLinkAPIUSA.py:458 hyundai_kia_connect_api - Start engine..
DEBUG    hyundai_kia_connect_api.HyundaiBlueLinkAPIUSA:HyundaiBlueLinkAPIUSA.py:468 hyundai_kia_connect_api - Start engine headers: {'content-type': 'application/json;charset=UTF-8', 'accept': 'application/json, text/plain, */*', 'accept-encoding': 'gzip, deflate, br', 'accept-language': 'en-US,en;q=0.9', 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36', 'host': 'api.telematics.hyundaiusa.com', 'origin': 'https://api.telematics.hyundaiusa.com', 'referer': 'https://api.telematics.hyundaiusa.com/login', 'from': 'SPA', 'to': 'ISS', 'language': '0', 'offset': '-7', 'sec-fetch-dest': 'empty', 'sec-fetch-mode': 'cors', 'sec-fetch-site': 'same-origin', 'refresh': 'false', 'encryptFlag': 'false', 'brandIndicator': 'H', 'gen': '2', 'client_id': '***', 'clientSecret': '***', 'username': '***@***.com', 'accessToken': '***', 'vin': '***', 'registrationId': '***', 'blueLinkServicePin': '***'}
DEBUG    hyundai_kia_connect_api.HyundaiBlueLinkAPIUSA:HyundaiBlueLinkAPIUSA.py:505 hyundai_kia_connect_api - Start engine data: {'Ims': 0, 'airCtrl': 1, 'airTemp': {'unit': 1, 'value': 72}, 'defrost': False, 'heating1': 0, 'igniOnDuration': 10, 'seatHeaterVentInfo': {'drvSeatHeatState': 0, 'astSeatHeatState': 0, 'rlSeatHeatState': 0, 'rrSeatHeatState': 0}, 'username': '***@***.com', 'vin': '***'}
DEBUG    urllib3.connectionpool:connectionpool.py:456 https://api.telematics.hyundaiusa.com:443 "POST /ac/v2/rcs/rsc/start HTTP/1.1" 502 None
DEBUG    hyundai_kia_connect_api.HyundaiBlueLinkAPIUSA:HyundaiBlueLinkAPIUSA.py:508 hyundai_kia_connect_api - Start engine response status code: 502
DEBUG    hyundai_kia_connect_api.HyundaiBlueLinkAPIUSA:HyundaiBlueLinkAPIUSA.py:511 hyundai_kia_connect_api - Start engine response: {"errorSubCode":"GEN","systemName":"BLODS","errorSubMessage":"Feature Status is OFF","errorMessage":"Your vehicle does not support this feature.","errorCode":502}
PASSED                                                                   [100%]{'***': Vehicle(id='***', name='2023 IONIQ 5', model='IONIQ 5', registration_date=['enrollmentDate'], year=None, VIN='***', key=None, enabled=True, _total_driving_range=None, _total_driving_range_value=None, _total_driving_range_unit=None, _odometer=None, _odometer_value=None, _odometer_unit=None, _geocode_address=None, _geocode_name=None, car_battery_percentage=None, engine_is_running=None, last_updated_at=None, timezone=None, dtc_count=None, dtc_descriptions=None, smart_key_battery_warning_is_on=None, washer_fluid_warning_is_on=None, brake_fluid_warning_is_on=None, _air_temperature=None, _air_temperature_value=None, _air_temperature_unit=None, air_control_is_on=None, defrost_is_on=None, steering_wheel_heater_is_on=None, back_window_heater_is_on=None, side_mirror_heater_is_on=None, front_left_seat_status=None, front_right_seat_status=None, rear_left_seat_status=None, rear_right_seat_status=None, is_locked=None, front_left_door_is_open=None, front_right_door_is_open=None, back_left_door_is_open=None, back_right_door_is_open=None, trunk_is_open=None, hood_is_open=None, tire_pressure_all_warning_is_on=None, tire_pressure_rear_left_warning_is_on=None, tire_pressure_front_left_warning_is_on=None, tire_pressure_front_right_warning_is_on=None, tire_pressure_rear_right_warning_is_on=None, _next_service_distance=None, _next_service_distance_value=None, _next_service_distance_unit=None, _last_service_distance=None, _last_service_distance_value=None, _last_service_distance_unit=None, _location_latitude=None, _location_longitude=None, _location_last_set_time=None, ev_charge_port_door_is_open=None, ev_charge_limits_dc=None, ev_charge_limits_ac=None, total_power_consumed=None, power_consumption_30d=None, daily_stats=[], month_trip_info=None, day_trip_info=None, ev_battery_percentage=None, ev_battery_is_charging=None, ev_battery_is_plugged_in=None, _ev_driving_range=None, _ev_driving_range_value=None, _ev_driving_range_unit=None, _ev_estimated_current_charge_duration=None, _ev_estimated_current_charge_duration_value=None, _ev_estimated_current_charge_duration_unit=None, _ev_estimated_fast_charge_duration=None, _ev_estimated_fast_charge_duration_value=None, _ev_estimated_fast_charge_duration_unit=None, _ev_estimated_portable_charge_duration=None, _ev_estimated_portable_charge_duration_value=None, _ev_estimated_portable_charge_duration_unit=None, _ev_estimated_station_charge_duration=None, _ev_estimated_station_charge_duration_value=None, _ev_estimated_station_charge_duration_unit=None, _ev_target_range_charge_AC=None, _ev_target_range_charge_AC_value=None, _ev_target_range_charge_AC_unit=None, _ev_target_range_charge_DC=None, _ev_target_range_charge_DC_value=None, _ev_target_range_charge_DC_unit=None, ev_first_departure_enabled=None, ev_second_departure_enabled=None, ev_first_departure_days=None, ev_second_departure_days=None, ev_first_departure_time=None, ev_second_departure_time=None, ev_off_peak_start_time=None, ev_off_peak_end_time=None, ev_off_peak_charge_only_enabled=None, _fuel_driving_range=None, _fuel_driving_range_value=None, _fuel_driving_range_unit=None, fuel_level=None, fuel_level_is_low=None, engine_type=None, data=None)}
cdnninja commented 1 year ago

Try again tomorrow. Sometimes issues appear and go away without any interaction or change. Would love to see USA dev support! Currently it's updated by people not in the USA so hard for us to test. That is why it lags beyond other regions.

snowe2010 commented 1 year ago

@cdnninja ah ok. Will do! And yes, currently I'm digging through the code seeing what I can understand. Also, is there a better place to discuss dev work rather than in issues or discussions on github?

cdnninja commented 1 year ago

Currently this is the only spot for this repo. I do chat on the blue linky dev discord for reverse engineering as well.

snowe2010 commented 1 year ago

@cdnninja so, looks like a simple reset of the system and a reconfigure of bluelink fixed my ioniq, but I'm still seeing that error on every call to start_climate. Seems like maybe it's due to the fact that the heated seats are being passed, but I'm not able to figure out why. So, one question I have is why are we using the api that is coming from the mobile apps rather than that coming from the web interface? I can clearly see that the bluelink website uses form params rather than the json post that is being used in this python library.

I've been trying to get around the SSL pinning issue for the mobile apps, but am having difficulty. It seems like it probably won't be possible for iOS, but I might be able to get around it on android. I tried loading up the apk in an android virtual device, but I think that Hyundai actually blocks the app from running on emulator. They've tried really hard to prevent this it seems, but I'm not a security researcher so I'm only going to be able to do so much. Seems like maybe we should just switch the mechanism to the web api endpoints for this bit.

cdnninja commented 1 year ago

I believe at the time we found authentication easier and more aligned to other apis by using the mobile app.

Can you confirm if both mobile and website have feature parity?

snowe2010 commented 1 year ago

I'm actually seeing more features in the website. For example, the 'Remote start' feature in the website allows for a custom 'one-off' start.

image