widewing / ha-toyota-na

Home Assistant integration for Toyota Motor (North America) connected services
75 stars 17 forks source link

Coordinator frequency #37

Closed johndbritton closed 1 month ago

johndbritton commented 2 years ago

It looks like this is hard coded to run update_vehicle_status every two minutes via init.py.

Is it possible to expose a way to trigger a vehicle status update manually?

I'm making a script to robustly start and warm my vehicle. Sometimes the toyota_na commands fail so what I'm doing is checking the status of the vehicle after sending the command and retrying if the status hasn't changed.

Unfortunately, this results in my scripts retrying multiple times even when the commands have been successful because HA doesn't realize that the state has changed until the 2 minute interval has passed.

Also open to other ideas on how to achieve something similar.

tonymorello commented 2 years ago

You could add a delay of 2 minutes between retries

johndbritton commented 2 years ago

I could wait two minutes between checking to see if the command worked, but that would make each start cycle take at least 4 minutes:

What is like to do instead

tonymorello commented 2 years ago

In your example that would be true. I don't know what your specific situation is but let's say this script is supposed to run in the morning if the temperature is below a given threshold and you want the car to start around 6:30 am... It would go like this:

I get that it's not ideal, just a different approach to consider.

johndbritton commented 2 years ago

@tonymorello your approach makes sense. I am trying to avoid the two minute wait after each lock or engine start request.

If I have to try to start the car three times, that means the whole ordeal will take 8 minutes (lock, wait, check, start, wait, check, start, wait, check, start, wait, check, success).

An ability to change the coordinator frequency or to manually request a coordinator update is what I'm trying to figure out.

I'd be willing to send a PR here if someone can give me a bit of direction towards an acceptable solution.

vanstinator commented 2 years ago

We're adding the robust vehicle starting right into the integration and python lib itself.

Part of that work will involve exposing a service to update and a service to refresh the vehicle. We're building out a leaky bucket token pool first to rate limit how often people can call these services so we don't draw attention to ourselves. I'd anticipate this work starting to ship in the next week or two.

johndbritton commented 2 years ago

@vanstinator awesome, I'll keep an eye out for that.

johndbritton commented 2 years ago

@vanstinator it's worth considering to make the start function check lock the car before starting if it's unlocked so that end users don't have to script that part.

dkmcgowan commented 1 month ago

There is a refresh service in v2.4.0