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
132 stars 75 forks source link

fix(EU): Remove token device_id refresh for some actions #679

Open asychow opened 1 week ago

asychow commented 1 week ago

Potential fix for https://github.com/Hyundai-Kia-Connect/hyundai_kia_connect_api/issues/564

According to my capture, the app doesn't not send notifications/register after the action reqeusts. Nor does it update vehicleId in header of the next notifications/<vehicleId>/records request.

check_action_status()returns OrderStatus.SUCCESS after the fix (was throwing an error hyundai_kia_connect_api.exceptions.APIError: No action found with ID <action-id>)

cdnninja commented 1 week ago

Those were added as a work around. Our device id was being invalidated for some reason. Maybe it needs to be moved in the code though.

Would need some decent testing before merging.

asychow commented 6 days ago

I have performed two preliminary tests.

  1. Capture 20 hours of BL traffic, with requests sent, wifi reconnection and app force-close & reopen multiple times during the period. Neither deviceId nor vehicleId is changed
  2. Simulate BL requests using the API with breaks in between, e.g. lock => wait for success => sleep 10 seconds => wait for success => unlock => wait for success => sleep 3 minutes => close charge door => wait for success. All the commands ran successfully.

Please correct me if I am wrong or the tests are flawed, but the test results suggest that refreshing deviceId is no longer needed (maybe some changes on the server?). I'm happy to test this in the HA integration for an extended period, but ideally we need someone who experienced the deviceId issue in https://github.com/Hyundai-Kia-Connect/kia_uvo/issues/672 to test too.

fuatakgun commented 6 days ago

thanks for comprehensive test, vehicle id is not supposed to change, but for device id, can you please run it further more than 20 hours? let's see if it still requires to be updated after initial token expiration.

cdnninja commented 3 days ago

This speaks to why this was added: https://github.com/Hyundai-Kia-Connect/kia_uvo/issues/672

It is believed to be caused by us not registering push notifications correctly. So when we run a command that triggers a push it errors server side and invalidates our device_id. If you are finding that isn't the case when using these methods and using mobile app same day we can try remove this and roll it out. Worse case we revert it.