-
Notifications
You must be signed in to change notification settings - Fork 12
/
golifx_test.go
57 lines (49 loc) · 1.44 KB
/
golifx_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package golifx_test
import (
"fmt"
"github.com/pdf/golifx"
"github.com/pdf/golifx/protocol"
)
// Instantiating a new client with protocol V2, with default options
func ExampleNewClient_v2() {
client, err := golifx.NewClient(&protocol.V2{})
if err != nil {
panic(err)
}
light, err := client.GetLightByLabel(`lightLabel`)
if err != nil {
panic(err)
}
fmt.Println(light.ID())
}
// When using protocol V2, it's possible to choose an alternative client port.
// This is not recommended unless you need to use multiple client instances at
// the same time.
func ExampleNewClient_v2port() {
client, err := golifx.NewClient(&protocol.V2{Port: 56701})
if err != nil {
panic(err)
}
light, err := client.GetLightByLabel(`lightLabel`)
if err != nil {
panic(err)
}
fmt.Println(light.ID())
}
// When using protocol V2, it's possible to enable reliable operations. This is
// highly recommended, otherwise sends operate in fire-and-forget mode, meaning
// we don't know if they actually arrived at the target or not. Whilst this is
// faster and generates less network traffic, in my experience LIFX devices
// aren't the most reliable at accepting the packets they're sent, so sometimes
// we need to retry.
func ExampleNewClient_v2reliable() {
client, err := golifx.NewClient(&protocol.V2{Reliable: true})
if err != nil {
panic(err)
}
light, err := client.GetLightByLabel(`lightLabel`)
if err != nil {
panic(err)
}
fmt.Println(light.ID())
}