From a19fedf7638f3e16f91f1c92b80b8a287f15a459 Mon Sep 17 00:00:00 2001 From: Elara Musayelyan Date: Tue, 26 Oct 2021 21:42:41 -0700 Subject: [PATCH] Add whitelist to pair() and make case insensitive --- infinitime.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/infinitime.go b/infinitime.go index 798c77f..8ba5605 100644 --- a/infinitime.go +++ b/infinitime.go @@ -4,6 +4,7 @@ import ( "bytes" "encoding/binary" "errors" + "strings" "time" bt "github.com/muka/go-bluetooth/api" @@ -70,7 +71,7 @@ func Connect(opts *Options) (*Device, error) { // If such device does not exist if errors.Is(err, ErrNoDevices) { // Attempt to pair device - dev, err = pair() + dev, err = pair(opts) } if err != nil { return nil, err @@ -174,7 +175,7 @@ func connectByName(opts *Options) (*Device, error) { func contains(ss []string, s string) bool { for _, str := range ss { - if str == s { + if strings.EqualFold(str, s) { return true } } @@ -182,7 +183,7 @@ func contains(ss []string, s string) bool { } // Pair attempts to discover and pair an InfiniTime device -func pair() (*Device, error) { +func pair(opts *Options) (*Device, error) { // Create new device out := &Device{} // Start bluetooth discovery @@ -204,6 +205,9 @@ func pair() (*Device, error) { } // If device name is InfiniTime if dev.Properties.Name == BTName { + if opts.WhitelistEnabled && !contains(opts.Whitelist, dev.Properties.Address) { + continue + } // Set output device out.device = dev break