-
Notifications
You must be signed in to change notification settings - Fork 12
/
golifx.go
57 lines (51 loc) · 1.85 KB
/
golifx.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
// Copyright 2015 Peter Fern
// Use of this source code is governed by the MIT
// license that can be found in the LICENSE file
// Package golifx provides a simple Go interface to the LIFX LAN protocol.
//
// Based on the protocol documentation available at:
// http://lan.developer.lifx.com/
//
// Also included in cmd/lifx is a small CLI utility that allows interacting with
// your LIFX devices on the LAN.
//
// In various parts of this package you may find references to a Device or a
// Light. The LIFX protocol makes room for future non-light devices by making a
// light a superset of a device, so a Light is a Device, but a Device is not
// necessarily a Light. At this stage, LIFX only produces lights though, so
// they are the only type of device you will interact with.
package golifx
import (
"time"
"github.com/pdf/golifx/common"
)
const (
// VERSION of this library
VERSION = "1.0.4"
)
// NewClient returns a pointer to a new Client and any error that occurred
// initializing the client, using the protocol p. It also kicks off a discovery
// run.
func NewClient(p common.Protocol) (*Client, error) {
c := &Client{
protocol: p,
timeout: common.DefaultTimeout,
retryInterval: common.DefaultRetryInterval,
internalRetryInterval: 10 * time.Millisecond,
quitChan: make(chan struct{}, 2),
}
c.protocol.SetTimeout(&c.timeout)
c.protocol.SetRetryInterval(&c.retryInterval)
if err := c.subscribe(); err != nil {
return nil, err
}
err := c.discover()
return c, err
}
// SetLogger allows assigning a custom levelled logger that conforms to the
// common.Logger interface. To capture logs generated during client creation,
// this should be called before creating a Client. Defaults to
// common.StubLogger, which does no logging at all.
func SetLogger(logger common.Logger) {
common.SetLogger(logger)
}