Hyundai-Kia-Connect / kia_uvo

A Home Assistant HACS integration that supports Kia Connect(Uvo) and Hyundai Bluelink. The integration supports the EU, Canada and the USA.
MIT License
390 stars 80 forks source link

Enable Geolocation Entity will break the integration #853

Open robinlee09201 opened 3 months ago

robinlee09201 commented 3 months ago

Please check Services, Known Bug / Issues and Troubleshooting over here first: https://github.com/fuatakgun/kia_uvo/blob/master/README.md Region and Brand of car Canada, Hyundai Version of the integration 2.22.0

Describe the bug A clear and concise description of what the bug is.

After updating to the latest HAOS (6.6.20-haos) and Core (core-2024.3.1) Enable "Enable Geolocation Entity using OpenStreetMap" in the configure will break the integration: failed to config error

Debug logs if an error occurred

Outlined here: https://github.com/fuatakgun/kia_uvo/blob/master/README.md Logger: hyundai_kia_connect_api.KiaUvoApiCA Source: /usr/local/lib/python3.12/site-packages/hyundai_kia_connect_api/KiaUvoApiCA.py:513 First occurred: 6:19:53 AM (4 occurrences) Last logged: 6:21:31 AM

hyundai_kia_connect_api - Get vehicle location failed

To Reproduce Enable "Enable Geolocation Entity using OpenStreetMap" in the configure and reload the integration

Expected behavior

Screenshots If applicable, add screenshots to help explain your problem.

image

Additional context

robinlee09201 commented 3 months ago

Update: it seems like Bluelink Canada stopped providing location info. Consider removing this feature?

sacua commented 3 months ago

I have the same problem as well with my Kia in canada

FuzzyMistborn commented 3 months ago

Same in USA.

cdnninja commented 3 months ago

Did native app remove location lookup?

PasTroCa commented 3 months ago

Did native app remove location lookup?

Not in Canada.

robinlee09201 commented 3 months ago

Did native app remove location lookup?

Not in Canada.

But the native app's vehicle locator function stops working as well.

cdnninja commented 3 months ago

So this could just be an outage. If so it changes approach to fixing it.

robinlee09201 commented 3 months ago

So this could just be an outage. If so it changes approach to fixing it.

It could be. At least, the error needs to be handled correctly without breaking the entire integration.

cdnninja commented 3 months ago

For sure. Thinking to start with that and see where this shakes out. If location doesn't return we can pull the whole feature.

sacua commented 3 months ago

There is most likely maintenance on the Kia/hyundai server side currently. Screenshot_20240321_195807_Kia Connect

nprez83 commented 3 months ago

I can confirm this problem is also happening with my Kia Telluride in the USA. The location is working normally in the native app.

Importantly, the latitude and longitude info is still there in the data package within the integration, isn't this what OpenStreetMap then uses to decode the street address? Could this problem be an issue with the OpenStreetMap api rather than Kia's? Just a thought. @cdnninja

nprez83 commented 3 months ago

Was doing some troubleshooting using the Places custom integration, which also uses the OpenStreetMap API to decode location. Initially, when I created a sensor using the Kia device_tracker, the sensor failed. I then noticed the device_tracker is reporting GPS accuracy as zero, so I disabled the "use GPS accuracy option" and the sensor worked well.

I still have to look into how the kia_uvo integration calls the OpenStreetMap API to obtain the geocoded location, but I think the error may have to do with the GPS accuracy as currently reported by the device_tracker.

cdnninja commented 3 months ago

Accuracy isn't provided by kia so we don't pass it on. This is the code in question: https://github.com/Hyundai-Kia-Connect/hyundai_kia_connect_api/blob/4c4d811455925cab99eb3c489e761ac6f66f84fc/hyundai_kia_connect_api/ApiImpl.py#L82-L102

For those that say GPS location is working I am confused on where the issue occurs. Would need logs to see this. I will add an if statement so if no gps location it won't query the API. Someone else will need to test for me as I don't have a kia or hyundai anymore.

cdnninja commented 3 months ago

Update from master and let me know if this is improved.

robinlee09201 commented 3 months ago

Update from master and let me know if this is improved.

Unfortunately no. The error still occurs. I believe the location is successfully received, and the tracker device interprets the location correctly. The OSM response also seems OK when I manually run the HTTP request. I don't see any error code related to the integration though. Do you know how to add debug info in the API code in my local setup? I couldn't find the API code in my HAOS.

cdnninja commented 3 months ago

What is the current exception with debug logging enabled?

robinlee09201 commented 3 months ago

What is the current exception with debug logging enabled?

There is no exception found in the log, seems that Hyundai has fixed the location issue (location is returned normally now. When the issue first occurred, Bluelink location was broken). But somehow, enabling geolocation still breaks the integration without any warning/error in the log.

cdnninja commented 3 months ago

Some data from debug is needed. Need to see the data coming back. Even attributes would help. Could be just malformed data now.

robinlee09201 commented 3 months ago

Some data from debug is needed. Need to see the data coming back. Even attributes would help. Could be just malformed data now.

Yea, that's why I'm asking if I can add some debug messages to the API code in my system. I don't think the bug is in the integration, but I don't know where the API's source code is installed in Home Assistant.

cdnninja commented 3 months ago

Lots of debug statement exist today in the code. I haven't seen any debug logs for this issue yet. If needed can add more but until seeing existing hard to know if more is needed.

To add more with home assistant typically easiest to just do it in the repo however if you run the python locally easy to add more and should pinpoint the issue as well.

mechmyday commented 3 months ago

Adding some logs from my instance.

Logger: hyundai_kia_connect_api.HyundaiBlueLinkAPIUSA Source: /usr/local/lib/python3.12/site-packages/hyundai_kia_connect_api/HyundaiBlueLinkAPIUSA.py:225 First occurred: 4:06:12 PM (2 occurrences) Last logged: 10:09:43 PM

hyundai_kia_connect_api - Unable to get vehicle location: {'errorSubCode': 'IDM_500', 'systemName': 'IDM', 'functionName': 'findMyCar', 'errorSubMessage': '\n### Error querying database. Cause: java.sql.SQLRecoverableException: Closed Connection\n### The error may exist in file [/webapps/gtidm/ROOT/WEB-INF/classes/gtidm/sqlmap/HaeTokenStoreDao.xml]\n### The error may involve gtidm.co.cou.dao.HaeTokenStoreDao.checkTokenLogout\n### The error occurred while executing a query\n### Cause: java.sql.SQLRecoverableException: Closed Connection\n; SQL []; Closed Connection; nested exception is java.sql.SQLRecoverableException: Closed Connection', 'errorMessage': '\n### Error querying database. Cause: java.sql.SQLRecoverableException: Closed Connection\n### The error may exist in file [/webapps/gtidm/ROOT/WEB-INF/classes/gtidm/sqlmap/HaeTokenStoreDao.xml]\n### The error may involve gtidm.co.cou.dao.HaeTokenStoreDao.checkTokenLogout\n### The error occurred while executing a query\n### Cause: java.sql.SQLRecoverableException: Closed Connection\n; SQL []; Closed Connection; nested exception is java.sql.SQLRecoverableException: Closed Connection', 'errorCode': 500, 'serviceName': 'CheckToken'} hyundai_kia_connect_api - Unable to get vehicle location: {'errorSubCode': 'GEN', 'systemName': 'HATA', 'functionName': 'findMyCar', 'errorSubMessage': 'HATA findMyCar service failed while performing the operation FindMyCar', 'errorMessage': "We're sorry, but we could not complete your request. Please try again later.", 'errorCode': 502, 'serviceName': 'FindMyCar'}```

Logger: hyundai_kia_connect_api.HyundaiBlueLinkAPIUSA Source: /usr/local/lib/python3.12/site-packages/hyundai_kia_connect_api/HyundaiBlueLinkAPIUSA.py:221 First occurred: 1:00:22 PM (447 occurrences) Last logged: 11:31:03 PM

hyundai_kia_connect_api - get vehicle location rate limit exceeded.

cdnninja commented 3 months ago

Looks like in your case we aren't getting location at all. So fails before it geo codes the coordinates. Does the error change when not api limited? I would encourage you to increase your polling interval to not max that out. You are a different region than others though so more responses would be good.

cdnninja commented 3 months ago

Anyone able to provide logs to help me close this one out?

mechmyday commented 3 months ago

I was able to update the polling settings and I haven't seen any issues since.

nprez83 commented 3 months ago

I'm still having the same issue with the integration breaking when the geocoded address is enabled. Unfortunately, despite enabling debug logging, there is nothing pertinent coming up on the logs, I think partly because the issue is arising somewhere in the ApiImpl file.

cdnninja commented 3 months ago

Without someone providing debug logs to me I can't help any further. Just since you don't see an issue doesn't mean I won't.

nprez83 commented 3 months ago

Here are the log entries I see. No errors are noted, but the integration fails to load if the geocoded place option is selected. Importantly, notice the latitude and longitude are correctly included in the payload, and are decoded without issues by the Places integration, which also uses OpenStreetMap.

I think the error is either happening somewhere in the ApiImpl.py code, so we may need to add debug messages there, or is happening when the integration tries to create the new sensor for the geocoded location. Either way, no pertinent errors are being shown in the logs.

2024-03-31 12:02:11.537 DEBUG (SyncWorker_29) [hyundai_kia_connect_api.KiaUvoAPIUSA] hyundai_kia_connect_api - Sign In Response {"status":{"statusCode":0,"errorType":0,"errorCode":0,"errorMessage":"Success with response body"}}
2024-03-31 12:02:11.538 DEBUG (SyncWorker_29) [hyundai_kia_connect_api.KiaUvoAPIUSA] got session id 59e49e3d-db06-42d1-bf61-a07bdf40dea7
2024-03-31 12:02:12.444 DEBUG (SyncWorker_29) [hyundai_kia_connect_api.KiaUvoAPIUSA] hyundai_kia_connect_api - Get Vehicles Response {"status":{"statusCode":0,"errorType":0,"errorCode":0,"errorMessage":"Success with response body"},"payload":{"vehicleSummary":[{"vin":"XXXXXXX","vehicleIdentifier":"XXXXXXX","modelName":"TELLURIDE","modelYear":"2020","nickName":"XXXXXXX","generation":2,"extColorCode":"KDG","trim":"EX","imagePath":{"imageName":"2020-telluride-ex-kdg.png","imagePath":"/content/dam/kia/us/owners/image/vehicle-app/2020/telluride/ex/","imageType":"1","imageSize":{"length":"100","width":"100","uom":0}},"enrollmentStatus":1,"fatcAvailable":0,"telematicsUnit":1,"fuelType":1,"colorName":"GRAVITY GREY","activationType":2,"mileage":"XXXXXXX","dealerCode":"XXXXXXX","mobileStore":[{"osType":0,"downloadURL":"https://itunes.apple.com/us/app/kia-access-with-uvo-link/id1280548773?mt=8","image":{"imageName":"iosImage.png","imagePath":"/content/dam/kia/us/owners/image/common/app/","imageType":"2","imageSize":{"length":"100","width":"100","uom":0}}},{"osType":1,"downloadURL":"https://play.google.com/store/apps/details?id=com.myuvo.link","image":{"imageName":"androidImage.png","imagePath":"/content/dam/kia/us/owners/image/common/app/","imageType":"2","imageSize":{"length":"100","width":"100","uom":0}}}],"supportedApp":{"appType":"5","appImage":{"imageName":"uvo-app.png","imagePath":"/content/dam/kia/us/owners/image/common/app/access/","imageType":"2","imageSize":{"length":"100","width":"100","uom":0}}},"supportAdditionalDriver":1,"customerType":0,"projectCode":"ON","headUnitDesc":"AVN5.0W","provStatus":"4","enrollmentSuppressionType":0,"rsaStatus":0,"dsEnrollment":0,"ubiEnrollment":0,"notificationCount":0,"genType":"2","headUnitType":"N","displayType":"AVN5.0W","headUnitName":"avn5w","vehicleKey":"XXXXXXX"}],"chatbotSupport":true}}
2024-03-31 12:02:12.448 DEBUG (SyncWorker_2) [hyundai_kia_connect_api.KiaUvoAPIUSA] hyundai_kia_connect_api - sending https://api.owners.kia.com/apigw/v1/cmm/gvi request with {'vehicleConfigReq': {'airTempRange': '0', 'maintenance': '1', 'seatHeatCoolOption': '0', 'vehicle': '1', 'vehicleFeature': '0'}, 'vehicleInfoReq': {'drivingActivty': '0', 'dtc': '1', 'enrollment': '1', 'functionalCards': '0', 'location': '1', 'vehicleStatus': '1', 'weather': '0'}, 'vinKey': ['XXXXXXX']}
2024-03-31 12:02:13.305 DEBUG (SyncWorker_2) [hyundai_kia_connect_api.KiaUvoAPIUSA] hyundai_kia_connect_api got response {"status":{"statusCode":0,"errorType":0,"errorCode":0,"errorMessage":"Success with response body"},"payload":{"vehicleInfoList":[{"vinKey":"XXXXXXX","vehicleConfig":{"vehicleDetail":{"vehicle":{"vin":"XXXXXXX","trim":{"modelYear":"2020","salesModelCode":"J4442","optionGroupCode":"010","modelName":"TELLURIDE","factoryCode":"S9","projectCode":"ON","trimName":"EX","driveType":"2","transmissionType":"1","ivrCategory":"5","btSeriesCode":"J"},"telematics":1,"mileage":"XXXXXXX","mileageSyncDate":"20240331013331","exteriorColor":"GRAVITY GREY","exteriorColorCode":"KDG","fuelType":1,"invDealerCode":"XXXXXXX","testVehicle":"0","supportedApps":[{"appType":"0"},{"appType":"5","appImage":{"imageName":"uvo-app.png","imagePath":"/content/dam/kia/us/owners/image/common/app/access/","imageType":"2","imageSize":{"length":"100","width":"100","uom":0}}}],"activationType":2,"headUnitType":"N","displayType":"AVN5.0W","headUnitName":"avn5w"},"images":[{"imageName":"2020-telluride-ex-kdg.png","imagePath":"/content/dam/kia/us/owners/image/vehicle-app/2020/telluride/ex/","imageType":"1","imageSize":{"length":"100","width":"100","uom":0}}],"device":{"launchType":"0","swVersion":"ON.USA.S5W_M.V008.001.220504","telematics":{"generation":"3","platform":"1","tmsCenter":"1","billing":true,"genType":"2"},"versionNum":"GASOLINE","headUnitType":"0","hdRadio":"X40HAF","ampType":"NA","headUnitName":"avn5w","bluetoothRef":"20","headUnitDesc":"AVN5.0W"}},"maintenance":{"nextServiceMile":XXXXXXX,"maintenanceSchedule":[7500,15000,22500,30000,37500,45000,52500,60000,67500,75000,82500,90000,97500,105000,112500]},"billingPeriod":{"freeTrial":{"value":12,"unit":0},"freeTrialExtension":{"value":12,"unit":1},"servicePeriod":{"value":60,"unit":1}}},"lastVehicleInfo":{"vehicleNickName":"XXXXXXX","preferredDealer":"XXXXXXX","customerType":0,"enrollment":{"provStatus":"4","enrollmentStatus":"1","enrollmentType":"0","registrationDate":"20191223","expirationDate":"20201004","expirationMileage":"100000","freeServiceDate":{"startDate":"20191004","endDate":"20201004"}},"activeDTC":{"dtcActiveCount":"0"},"vehicleStatusRpt":{"statusType":"2","reportDate":{"utc":"20240331160213","offset":-7},"vehicleStatus":{"climate":{"airCtrl":false,"defrost":false,"airTemp":{"value":"72","unit":1},"heatingAccessory":{"steeringWheel":0,"sideMirror":0,"rearWindow":0},"heatVentSeat":{"driverSeat":{"heatVentType":0,"heatVentLevel":1},"passengerSeat":{"heatVentType":0,"heatVentLevel":1},"rearLeftSeat":{"heatVentType":0,"heatVentLevel":1},"rearRightSeat":{"heatVentType":0,"heatVentLevel":1}}},"engine":false,"doorLock":true,"doorStatus":{"frontLeft":0,"frontRight":0,"backLeft":0,"backRight":0,"trunk":0,"hood":0},"lowFuelLight":false,"ign3":false,"transCond":true,"distanceToEmpty":{"value":242,"unit":3},"tirePressure":{"all":0},"dateTime":{"utc":"20240331160213","offset":-7},"syncDate":{"utc":"20240331153331","offset":-7},"batteryStatus":{"stateOfCharge":65,"deliveryMode":1},"sleepMode":true,"lampWireStatus":{"headLamp":{},"stopLamp":{},"turnSignalLamp":{}},"windowStatus":{},"engineRuntime":{},"remoteControlAvailable":1,"valetParkingMode":0,"rsaStatus":0}},"location":{"coord":{"lat":XXXXXXX,"lon":XXXXXXX,"alt":XXXXXXX,"type":0,"altdo":0},"head":193,"speed":{"value":0,"unit":1},"accuracy":{"hdop":7,"pdop":14},"syncDate":{"utc":"20240331153331","offset":-7}},"financed":true,"financeRegistered":false,"linkStatus":0,"rsaStatus":0,"primaryOwnerID":"XXXXXXX"}}]}}
2024-03-31 12:02:13.307 DEBUG (SyncWorker_2) [hyundai_kia_connect_api.KiaUvoAPIUSA] hyundai_kia_connect_api - last_updated_at - before 20240331153331
2024-03-31 12:02:13.308 DEBUG (SyncWorker_2) [hyundai_kia_connect_api.KiaUvoAPIUSA] hyundai_kia_connect_api - last_updated_at - after 2024-03-31 15:33:31+00:00
2024-03-31 12:02:13.309 DEBUG (SyncWorker_2) [hyundai_kia_connect_api.KiaUvoAPIUSA] hyundai_kia_connect_api - SOC Levels couldn't be found. May not be an EV.
2024-03-31 12:02:13.313 DEBUG (SyncWorker_2) [hyundai_kia_connect_api.KiaUvoAPIUSA] hyundai_kia_connect_api - last_updated_at - before 20240331153331
2024-03-31 12:02:13.313 DEBUG (SyncWorker_2) [hyundai_kia_connect_api.KiaUvoAPIUSA] hyundai_kia_connect_api - last_updated_at - after 2024-03-31 15:33:31+00:00

### The integration queries the API 5 additional times in the next 20 secs, with identical responses as above

2024-03-31 12:02:34.264 DEBUG (MainThread) [custom_components.kia_uvo.coordinator] Finished fetching kia_uvo data in 5.948 seconds (success: False)
cdnninja commented 3 months ago

I think to solve this someone with the issue will need to step in to dig in. I don't run this integration personally anymore so am limited in my ability to troubleshoot. While lat long are listed in payload this doesn't confirm it is being parsed.

Best way to troubleshoot is to download the hyundai_kia_api via github desktop run the api code directly and confirm what is being loaded into the vehicle object. If geocode is working in that situation we know this is the integration. If it isn't it is easy to add debugs locally to narrow down why.

nprez83 commented 3 months ago

I'll try to do it. For that is worth, the lat and lon are indeed being parsed correctly into the device_tracker the kia_uvo creates, which is why I can then use the "Places" integration to geocode it.