Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Improve wake up retry logic #379

Merged
merged 3 commits into from
Dec 9, 2022
Merged

Conversation

carleeno
Copy link
Contributor

@carleeno carleeno commented Dec 9, 2022

The wake_up decorator was removed as it was only used for the api() method. The wake_if_asleep logic has been refactored between the Controller.wake_up and Controller.api methods and made to be more readable and handle edge cases better:

  • If api is called for a endpoint that does not accept a vehicle_id, and wake_if_asleep=True, it will raise an exception
    • with the decorator, it would have failed as it's not possible to wake a vehicle without it'd ID, but also it's not needed to wake a vehicle for these types of commands
  • If the api is called with wake_if_asleep=True and the car has gone to sleep so recently that the Controller doesn't know it yet, the initial api request will fail, but now it will handle that gracefully, wake the vehicle, and try the command again
    • it appeared the decorator was supposed to do this, but due to some misplaced conditions, it did not.

It's also more efficient by only retrying the wake command if it failed, otherwise it waits for it to come online by polling the VEHICLE_SUMMARY endpoint at regular intervals with it's own timeout.

(split out from #373)

Tested with HA dev container and model 3

  • ensured sending a command with wake_if_asleep=True (climate on) while car was asleep would wake the car, only sending 1 wake request, and then detect that the car waked (it took ~8 seconds)
  • ensured sending a command with wake_if_asleep=False (climate off) while car was asleep would not wake the car, and logs would not show an error that the car was unavailable
  • ensured that sending a command with wake_if_asleep=True while car was awake would not try to wake the car

@carleeno
Copy link
Contributor Author

carleeno commented Dec 9, 2022

(in draft while I finish some real world testing)

@carleeno carleeno marked this pull request as ready for review December 9, 2022 03:17
@alandtse alandtse merged commit 31de243 into zabuldon:dev Dec 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants