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

example for how to use subscribe_for_vehicle_updates #93

Open
jkh911208 opened this issue Aug 10, 2024 · 4 comments
Open

example for how to use subscribe_for_vehicle_updates #93

jkh911208 opened this issue Aug 10, 2024 · 4 comments

Comments

@jkh911208
Copy link
Contributor

i want to use websocket to get state of the vehicle, but i just can't make it work
can you provide me a short example how to get vehicle state something like every 30 seconds? with web socket using subscribe_for_vehicle_updates?

@natekspencer
Copy link
Collaborator

Your statements are somewhat contradictory. Polling and subscribing are two different approaches for receiving the data. You can use them in combination with each other, but the subscribe_for_vehicle_updates should not be used every 30 seconds.

If you want to poll every 30 seconds, do something like:

while True:
  response = await api.get_vehicle_state(vehicle_id)
  await asyncio.sleep(30)

If you want to receive data by subscribing, you can do something like:

def handle_update(updated_data: dict) -> None:
  # do something with the updated data
  logging.debug("%s", updated_data)

await api.subscribe_for_vehicle_updates(vehicle_id, callback=handle_update)

@jkh911208
Copy link
Contributor Author

Your statements are somewhat contradictory. Polling and subscribing are two different approaches for receiving the data. You can use them in combination with each other, but the subscribe_for_vehicle_updates should not be used every 30 seconds.

If you want to poll every 30 seconds, do something like:

while True:
  response = await api.get_vehicle_state(vehicle_id)
  await asyncio.sleep(30)

If you want to receive data by subscribing, you can do something like:

def handle_update(updated_data: dict) -> None:
  # do something with the updated data
  logging.debug("%s", updated_data)

await api.subscribe_for_vehicle_updates(vehicle_id, callback=handle_update)

ah...got it thanks! I will give it a try, is it possible to get live charging data from subscribe?

@tmack8001
Copy link
Collaborator

Live charging data over the subscription?

Meaning what specifically?

Charge rate and such from the onboard vehicle based charger, yeah. Though not for say your wall box unfortunately we haven't been able to find evidence of that information over a subscription.

@jkh911208
Copy link
Contributor Author

@tmack8001 is it possible to make call back function a async function?

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

No branches or pull requests

3 participants