Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
yasuoza committed Nov 11, 2021
1 parent 2e48285 commit c9e6868
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion pkg/switchbot/doc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package switchbot_test
import (
"context"
"log"
"os"
"time"

"github.com/yasuoza/switchbot-ble-go/v2/pkg/switchbot"
Expand All @@ -12,8 +13,23 @@ func Example_press() {
ctx := context.Background()
timeout := 5 * time.Second

// Scan SwitchBots.
var addrs []string
err := switchbot.Scan(ctx, timeout, func(addr string) {
addrs = append(addrs, addr)
})
if err != nil {
log.Fatal(err)
}

// If there is no SwitchBot, err is nil and length of addresses is 0.
if len(addrs) == 0 {
log.Println("SwitchBot not found")
os.Exit(0)
}

// First, connect to SwitchBot.
addr := "A0:00:0A:AA:00:00"
addr := addrs[0]
log.Printf("Connecting to SwitchBot %s\n", addr)
bot, err := switchbot.Connect(ctx, addr, timeout)
if err != nil {
Expand Down

0 comments on commit c9e6868

Please sign in to comment.