Documentation ¶
Overview ¶
Package common contains common elements for the golifx client and protocols
Index ¶
- Constants
- Variables
- func SetLogger(logger Logger)
- type Client
- type Color
- type Device
- type ErrNotImplemented
- type EventExpiredDevice
- type EventExpiredGroup
- type EventExpiredLocation
- type EventNewDevice
- type EventNewGroup
- type EventNewLocation
- type EventUpdateColor
- type EventUpdateLabel
- type EventUpdatePower
- type Group
- type Light
- type Location
- type Logger
- type Protocol
- type StubLogger
- func (l *StubLogger) Debugf(format string, args ...interface{})
- func (l *StubLogger) Errorf(format string, args ...interface{})
- func (l *StubLogger) Fatalf(format string, args ...interface{})
- func (l *StubLogger) Infof(format string, args ...interface{})
- func (l *StubLogger) Panicf(format string, args ...interface{})
- func (l *StubLogger) Warnf(format string, args ...interface{})
- type Subscription
- type SubscriptionTarget
Constants ¶
const ( // DefaultTimeout is the default duration after which operations time out DefaultTimeout = 2 * time.Second // DefaultRetryInterval is the default interval at which operations are // retried DefaultRetryInterval = 100 * time.Millisecond )
Variables ¶
var ( // ErrNotFound not found ErrNotFound = errors.New(`Not found`) // ErrProtocol protocol error ErrProtocol = errors.New(`Protocol error`) // ErrDuplicate already exists ErrDuplicate = errors.New(`Already exists`) // ErrInvalidArgument invalid argument ErrInvalidArgument = errors.New(`Invalid argument`) // ErrClosed connection closed ErrClosed = errors.New(`Connection closed`) // ErrTimeout timed out ErrTimeout = errors.New(`Timed out`) // ErrDeviceInvalidType invalid device type ErrDeviceInvalidType = errors.New(`Invalid device type`) )
Functions ¶
Types ¶
type Color ¶
type Color struct { Hue uint16 // range 0 to 65535 Saturation uint16 // range 0 to 65535 Brightness uint16 // range 0 to 65535 Kelvin uint16 // range 2500° (warm) to 9000° (cool) }
Color is used to represent the color and color temperature of a light. The color is represented as a 48-bit HSB (Hue, Saturation, Brightness) value. The color temperature is represented in K (Kelvin) and is used to adjust the warmness / coolness of a white light, which is most obvious when saturation is close zero.
type Device ¶
type Device interface { // Returns the ID for the device ID() uint64 // Returns the label for the device GetLabel() (string, error) // Sets the label for the device SetLabel(label string) error // Returns the power state of the device, true for on, false for off GetPower() (bool, error) // Sets the power state of the device, true for on, false for off SetPower(state bool) error // Device is a SubscriptionTarget SubscriptionTarget }
Device represents a generic LIFX device
type ErrNotImplemented ¶
type ErrNotImplemented struct {
Method string
}
ErrNotImplemented not implemented
func (*ErrNotImplemented) Error ¶
func (e *ErrNotImplemented) Error() string
Error satisfies the error interface
type EventExpiredDevice ¶ added in v0.1.0
type EventExpiredDevice struct {
Device Device
}
EventExpiredDevice is emitted by a Client or Group when a Device is no longer known
type EventExpiredGroup ¶ added in v0.2.0
type EventExpiredGroup struct {
Group Group
}
EventExpiredGroup is emitted by a Client or Group when a Group is no longer known
type EventExpiredLocation ¶ added in v0.2.0
type EventExpiredLocation struct {
Location Location
}
EventExpiredLocation is emitted by a Client or Group when a Location is no longer known
type EventNewDevice ¶ added in v0.1.0
type EventNewDevice struct {
Device Device
}
EventNewDevice is emitted by a Client or Group when it discovers a new Device
type EventNewGroup ¶ added in v0.2.0
type EventNewGroup struct {
Group Group
}
EventNewGroup is emitted by a Client when it discovers a new Group
type EventNewLocation ¶ added in v0.2.0
type EventNewLocation struct {
Location Location
}
EventNewLocation is emitted by a Client when it discovers a new Location
type EventUpdateColor ¶ added in v0.1.0
type EventUpdateColor struct {
Color Color
}
EventUpdateColor is emitted by a Light or Group when its Color is updated
type EventUpdateLabel ¶ added in v0.1.0
type EventUpdateLabel struct {
Label string
}
EventUpdateLabel is emitted by a Device or Group when its label is updated
type EventUpdatePower ¶ added in v0.1.0
type EventUpdatePower struct {
Power bool
}
EventUpdatePower is emitted by a Device or Group when its power state is updated
type Group ¶ added in v0.2.0
type Group interface { // ID returns a base64 encoding of the device ID ID() string // Label returns the label for the group GetLabel() string // Devices returns the devices in the group Devices() []Device // Lights returns the lights in the group Lights() []Light // Returns the power state of the group, true if any members are on, false // if all members off. Returns error on communication errors. GetPower() (bool, error) // Returns the average color of lights in the group. Returns error on // communication error. GetColor() (Color, error) // SetColor requests a change of color for all devices in the group that // support color changes, transitioning over the specified duration SetColor(color Color, duration time.Duration) error // SetPower sets the power of devices in the group that support power // changes, state is true for on, false for off. SetPower(state bool) error // SetPowerDuration sets the power of devices in the group that support // power changes, transitioning over the speficied duration, state is true // for on, false for off. SetPowerDuration(state bool, duration time.Duration) error // Device is a SubscriptionTarget SubscriptionTarget }
Group represents a group of LIFX devices
type Light ¶
type Light interface { // SetColor changes the color of the light, transitioning over the specified // duration SetColor(color Color, duration time.Duration) error // GetColor returns the current color of the light GetColor() (Color, error) // SetPowerDuration sets the power of the light, transitioning over the // speficied duration, state is true for on, false for off. SetPowerDuration(state bool, duration time.Duration) error // Light is a superset of the Device interface Device }
Light represents a LIFX light device
type Location ¶ added in v0.2.0
type Location interface { // Location is a group Group }
Location represents a locality-based group of LIFX devices
type Logger ¶
type Logger interface { // Debugf handles debug level messages Debugf(format string, args ...interface{}) // Infof handles info level messages Infof(format string, args ...interface{}) // Warnf handles warn level messages Warnf(format string, args ...interface{}) // Errorf handles error level messages Errorf(format string, args ...interface{}) // Fatalf handles fatal level messages, and must exit the application Fatalf(format string, args ...interface{}) // Panicf handles debug level messages, and must panic the application Panicf(format string, args ...interface{}) }
Logger represents a minimal levelled logger
var ( // Log holds the global logger used by golifx, can be set via SetLogger() in // the golifx package Log Logger )
type Protocol ¶ added in v0.1.0
type Protocol interface { SubscriptionTarget // SetClient sets the client on the protocol for bi-directional // communication SetClient(client Client) // Discover initiates device discovery, this may be a noop in some future // protocol versions. This is called immediately when the client connects // to the protocol Discover() error // Close closes the protocol driver, no further communication with the // protocol is possible Close() error // SetPower sets the power state globally, on all devices SetPower(state bool) error // SetPowerDuration sets the power state globally, on all lights, over the // specified duration SetPowerDuration(state bool, duration time.Duration) error // SetColor changes the color globally, on all lights, over the specified // duration SetColor(color Color, duration time.Duration) error }
Protocol defines the interface between the Client and a protocol implementation
type StubLogger ¶
type StubLogger struct{}
StubLogger satisfies the Logger interface, and simply does nothing with received messages
func (*StubLogger) Debugf ¶
func (l *StubLogger) Debugf(format string, args ...interface{})
Debugf handles debug level messages
func (*StubLogger) Errorf ¶
func (l *StubLogger) Errorf(format string, args ...interface{})
Errorf handles error level messages
func (*StubLogger) Fatalf ¶
func (l *StubLogger) Fatalf(format string, args ...interface{})
Fatalf handles fatal level messages, exits the application
func (*StubLogger) Infof ¶
func (l *StubLogger) Infof(format string, args ...interface{})
Infof handles info level messages
func (*StubLogger) Panicf ¶
func (l *StubLogger) Panicf(format string, args ...interface{})
Panicf handles debug level messages, and panics the application
func (*StubLogger) Warnf ¶
func (l *StubLogger) Warnf(format string, args ...interface{})
Warnf handles warn level messages
type Subscription ¶ added in v0.1.0
type Subscription struct {
// contains filtered or unexported fields
}
Subscription exposes an event channel for consumers, and attaches to a SubscriptionTarget, that will feed it with events
func NewSubscription ¶ added in v0.1.0
func NewSubscription(target SubscriptionTarget) *Subscription
NewSubscription returns a *Subscription attached to the specified target
func (*Subscription) Close ¶ added in v0.1.0
func (s *Subscription) Close() error
Close cleans up resources and notifies the target that the subscription should no longer be used. It is important to close subscriptions when you are done with them to avoid blocking operations.
func (*Subscription) Events ¶ added in v0.1.0
func (s *Subscription) Events() <-chan interface{}
Events returns a chan reader for reading events published to this subscription
func (*Subscription) ID ¶ added in v0.1.0
func (s *Subscription) ID() string
ID returns the unique ID for this subscription
func (*Subscription) Write ¶ added in v0.1.0
func (s *Subscription) Write(event interface{}) error
Write pushes an event onto the events channel
type SubscriptionTarget ¶ added in v0.1.0
type SubscriptionTarget interface { NewSubscription() (*Subscription, error) CloseSubscription(*Subscription) error }
SubscriptionTarget defines the interface between a subscription and it's target object