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

Refactor BLE connecting to allow scanning for vehicle presence #353

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Lenart12
Copy link

@Lenart12 Lenart12 commented Jan 18, 2025

Description

This PR splits the ble.tryToConnect method in to two parts, by factoring out its first step in which we scan for a suitable tesla BLE advertisement (beacon). This is achieved by putting the code in a new ble.scanVehicleBeacon method along with other smaller refactorings. This allows us to expose the new method with ble.ScanVehicleBeacon.

The end user can then use a different (shorter) timeout to check for the presence of the vehicle before deciding if it wants to try to connect, since if a beacon got detected it would make sense to use a longer timeout to connect, or even do multiple retries, and if it wasn't detected allow for faster error handling.

Example

// Old way
conn, err := ble.NewConnection(ctx, vin)

// New way

// Either try to connect immediatly
conn, err := ble.NewConnection(ctx, vin)
// Or
scanCtx, scanCancel = context.withTimeout(ctx, 1*time.Second)
defer scanCancel()
beacon, err := ble.ScanVehicleBeacon(scanCtx, vin)
if err != nil {
  handleErr(err)
}
conn, err := ble.NewConnectionToBleTarget(ctx, vin, beacon)

Type of change

Please select all options that apply to this change:

  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Bug fix (non-breaking change which fixes an issue)
  • Documentation update

Checklist:

Confirm you have completed the following steps:

  • My code follows the style of this project.
  • I have performed a self-review of my code.
  • I have made corresponding updates to the documentation.
  • I have added/updated unit tests to cover my changes.

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.

1 participant