Documentation
¶
Index ¶
- Constants
- Variables
- func BuildDiscoveryPacket(source uint32) []byte
- func BuildEchoRequestPacket(source uint32, target []byte, echo []byte) []byte
- func BuildGetLabelPacket(source uint32, target []byte) []byte
- func BuildGetVersionPacket(source uint32, target []byte) []byte
- func BuildSetColorPacket(source uint32, target []byte, color LIFXColor, duration time.Duration) []byte
- func BuildSetLabelPacket(source uint32, target []byte, label string) []byte
- func BuildSetPowerPacket(source uint32, target []byte, on bool) []byte
- func InitializeProducts() error
- func PrintProduct(product Product)
- func SanitizeLabel(label string) string
- type Client
- func (c *Client) BroadcastPacket(packet []byte) error
- func (c *Client) ClearDevices()
- func (c *Client) Close() error
- func (c *Client) Discover(timeout time.Duration) error
- func (c *Client) ExportJSON() string
- func (c *Client) GetDeviceByLabel(label string) (*Device, error)
- func (c *Client) GetDeviceLabels() []string
- func (c *Client) GetDevices() []Device
- func (c *Client) LoadDevices(jsonData string) error
- func (c *Client) RefreshDeviceInfo()
- func (c *Client) Send(packet []byte, addr *net.UDPAddr) error
- func (c *Client) SendAndWait(packet []byte, addr *net.UDPAddr, expectedType PacketType, ...) ([]byte, error)
- func (c *Client) SetColor(label string, color LIFXColor, duration time.Duration) error
- func (c *Client) SetLabel(oldLabel, newLabel string) error
- func (c *Client) TurnOff(label string) error
- func (c *Client) TurnOn(label string) error
- type Device
- func (d *Device) ExportDeviceJSON() string
- func (d *Device) GetLabel() (string, error)
- func (d *Device) GetMACAddress() string
- func (d *Device) GetProduct() (Product, error)
- func (d *Device) Ping() bool
- func (d *Device) RefreshInfo() error
- func (d *Device) Send(packet []byte) error
- func (d *Device) SendAndWait(packet []byte, pktType PacketType, duration time.Duration) ([]byte, error)
- func (d *Device) SetColor(color LIFXColor, duration time.Duration) error
- func (d *Device) SetLabel(label string) error
- func (d *Device) TurnOff() error
- func (d *Device) TurnOn() error
- func (d *Device) UDPAddr() *net.UDPAddr
- type Features
- type Header
- func (h *Header) AckRequired() bool
- func (h *Header) Addressable() bool
- func (h *Header) PackHeader() []byte
- func (h *Header) Protocol() uint16
- func (h *Header) ResponseRequired() bool
- func (h *Header) Sequence() uint8
- func (h *Header) SetAckRequired(ackRequired bool)
- func (h *Header) SetAddressable(addressable bool)
- func (h *Header) SetResponseRequired(responseRequired bool)
- func (h *Header) SetSequence(sequence uint8)
- func (h *Header) SetSize(size uint16)
- func (h *Header) SetSource(source uint32)
- func (h *Header) SetTagged(tagged bool)
- func (h *Header) SetTarget(mac []byte)
- func (h *Header) SetType(packetType PacketType)
- func (h *Header) Size() uint16
- func (h *Header) Source() uint32
- func (h *Header) Tagged() bool
- func (h *Header) Target() []byte
- func (h *Header) Type() PacketType
- type LIFXColor
- func (c *LIFXColor) GetBrightness() float64
- func (c *LIFXColor) GetHue() float64
- func (c *LIFXColor) GetKelvin() float64
- func (c *LIFXColor) GetSaturation() float64
- func (c *LIFXColor) SetBrightness(brightness float64)
- func (c *LIFXColor) SetHue(hue float64)
- func (c *LIFXColor) SetKelvin(kelvin float64)
- func (c *LIFXColor) SetSaturation(saturation float64)
- type PacketType
- type Product
- type Vendor
Constants ¶
const ( LifxPort = 56700 // Default UDP port for LIFX LAN protocol HeaderSize = 8 + 16 + 12 // Frame Header + Frame Address + Protocol Header Size Protocol = 1024 // LIFX Protocol Number )
Variables ¶
var (
ProductsByVendorIDAndProductID map[int]map[int]Product
)
Functions ¶
func BuildDiscoveryPacket ¶
BuildDiscoveryPacket creates a discovery packet
func BuildEchoRequestPacket ¶
func BuildGetLabelPacket ¶
BuildGetLabelPacket creates a packet to get the label of a device
func BuildGetVersionPacket ¶
BuildGetVersionPacket creates a packet to get the version of a device
func BuildSetColorPacket ¶
func BuildSetColorPacket(source uint32, target []byte, color LIFXColor, duration time.Duration) []byte
BuildSetColorPacket creates a packet to set the color of a device
func BuildSetLabelPacket ¶
BuildSetLabelPacket creates a packet to set the label of a device
func BuildSetPowerPacket ¶
BuildSetPowerPacket creates a packet to set the power state of a device
func InitializeProducts ¶
func InitializeProducts() error
func PrintProduct ¶
func PrintProduct(product Product)
func SanitizeLabel ¶
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func (*Client) BroadcastPacket ¶
BroadcastPacket sends a packet to the broadcast address
func (*Client) ClearDevices ¶
func (c *Client) ClearDevices()
ClearDevices clears the list of discovered devices
func (*Client) ExportJSON ¶
ExportJSON exports the discovered devices as a JSON string
func (*Client) GetDeviceLabels ¶
GetDeviceLabels returns a list of labels for all discovered devices
func (*Client) GetDevices ¶
Devices returns the list of discovered devices
func (*Client) LoadDevices ¶
LoadDevices loads devices from a JSON string
func (*Client) RefreshDeviceInfo ¶
func (c *Client) RefreshDeviceInfo()
func (*Client) SendAndWait ¶
func (c *Client) SendAndWait(packet []byte, addr *net.UDPAddr, expectedType PacketType, timeout time.Duration) ([]byte, error)
SendAndWait sends a packet and waits for a response
type Device ¶
type Device struct {
MAC []byte `json:"mac"`
IP net.IP `json:"ip"`
Label string `json:"label"`
Product Product `json:"product"`
// contains filtered or unexported fields
}
func (*Device) ExportDeviceJSON ¶
ExportJSON exports the device information as a JSON string using marshall
func (*Device) GetMACAddress ¶
func (*Device) GetProduct ¶
func (*Device) RefreshInfo ¶
RefreshInfo refreshes the device information by getting the label and product details
func (*Device) SendAndWait ¶
type Features ¶
type Features struct {
Hev bool `json:"hev"`
Color bool `json:"color"`
Chain bool `json:"chain"`
Matrix bool `json:"matrix"`
Relays bool `json:"relays"`
Buttons bool `json:"buttons"`
Infrared bool `json:"infrared"`
Multizone bool `json:"multizone"`
TemperatureRange [2]int `json:"temperature_range"` // [min, max] in Kelvin
ExtendedMultizone bool `json:"extended_multizone"`
}
type Header ¶
type Header [HeaderSize]byte
Header represents a 36-byte LIFX protocol header (https://lan.developer.lifx.com/docs/packet-contents#header)
func DefaultHeader ¶
func DefaultHeader(source uint32, target []byte, packetType PacketType, payloadSize uint16) *Header
func ParseHeader ¶
ParseHeader parses the first 36 bytes into a Header struct
func (*Header) AckRequired ¶
AckRequired returns true if the ack required bit (bit 1 of byte 15) is set
func (*Header) Addressable ¶
Addressable returns true if the addressable bit is set
func (*Header) PackHeader ¶
PackHeader converts the header to a byte slice
func (*Header) ResponseRequired ¶
ResponseRequired returns true if the response required bit (bit 0 of byte 15) is set
func (*Header) SetAckRequired ¶
SetAckRequired sets the ack required bit to a boolean value
func (*Header) SetAddressable ¶
SetAddressable sets the addressable bit to a boolean value
func (*Header) SetResponseRequired ¶
SetResponseRequired sets the response required bit to a boolean value
func (*Header) SetSequence ¶
SetSequence sets the sequence number
func (*Header) SetType ¶
func (h *Header) SetType(packetType PacketType)
SetType sets the packet type
type LIFXColor ¶
type LIFXColor struct {
// contains filtered or unexported fields
}
func ColorfulToLifxColor ¶
func NewColorFromHSV ¶
func NewColorFromHex ¶
func NewColorFromRGB ¶
func (*LIFXColor) GetBrightness ¶
func (*LIFXColor) GetSaturation ¶
func (*LIFXColor) SetBrightness ¶
func (*LIFXColor) SetSaturation ¶
type PacketType ¶
type PacketType uint16
const ( GetService PacketType = 2 // Discovery Request GetHostFirmware PacketType = 14 GetWifiInfo PacketType = 16 GetWifiFirmware PacketType = 18 GetPower PacketType = 20 GetLabel PacketType = 23 GetVersion PacketType = 32 GetInfo PacketType = 34 GetLocation PacketType = 48 GetGroup PacketType = 51 EchoRequest PacketType = 58 GetColor PacketType = 101 GetLightPower PacketType = 116 GetInfrared PacketType = 120 GetHevCycle PacketType = 142 GetHevCycleConfiguration PacketType = 145 GetLastHevCycleResult PacketType = 148 GetColorZones PacketType = 502 GetMultiZoneEffect PacketType = 507 GetExtendedColorZones PacketType = 511 GetRPower PacketType = 816 GetDeviceChain PacketType = 701 Get64 PacketType = 707 GetTileEffect PacketType = 718 SensorGetAmbientLight PacketType = 401 )
const ( SetPower PacketType = 21 SetLabel PacketType = 24 SetReboot PacketType = 38 SetLocation PacketType = 49 SetGroup PacketType = 52 SetColor PacketType = 102 SetWaveform PacketType = 103 SetLightPower PacketType = 117 SetWafeformOptional PacketType = 119 SetInfrared PacketType = 122 SetHevCycle PacketType = 143 SetHevCycleConfiguration PacketType = 146 SetColorZones PacketType = 501 SetMultiZoneEffect PacketType = 508 SetExtendedColorZones PacketType = 510 SetRPower PacketType = 817 SetUserPosition PacketType = 703 Set64 PacketType = 715 SetTileEffect PacketType = 719 )
const ( Acknowledgement PacketType = 45 // Returned when `ack_required=1` is specified. StateService PacketType = 3 // Discovery Response StateHostFirmware PacketType = 15 StateWifiInfo PacketType = 17 StateWifiFirmware PacketType = 19 StatePower PacketType = 22 StateLabel PacketType = 25 StateVersion PacketType = 33 StateInfo PacketType = 35 StateLocation PacketType = 50 StateGroup PacketType = 53 EchoResponse PacketType = 59 StateUnhandled PacketType = 223 LightState PacketType = 107 StateLightPower PacketType = 118 StateInfrared PacketType = 121 StateHevCycle PacketType = 144 StateHevCycleConfiguration PacketType = 147 StateLastHevCycleResult PacketType = 149 StateZone PacketType = 503 StateMultiZone PacketType = 506 StateMultiZoneEffect PacketType = 509 StateExtendedColorZones PacketType = 512 StateRPower PacketType = 818 StateDeviceChain PacketType = 702 State64 PacketType = 711 StateTileEffect PacketType = 720 StateAmbientLight PacketType = 402 )
type Product ¶
type Product struct {
ProductID int `json:"pid"`
Name string `json:"name"`
Features Features `json:"features"`
Upgrades []struct {
Major int `json:"major"`
Minor int `json:"minor"`
Features Features `json:"features"`
}
}
func GetProduct ¶
GetProduct returns the product information for a given vendor ID and product ID