lifx

package module
v0.0.0-...-efeb7b1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 25, 2023 License: MIT Imports: 11 Imported by: 0

README

This is a Go package for interacting with LIFX devices.

products.json

This data file comes from https://github.com/LIFX/products verbatim. It is embedded in this package for deployment simplicity.

Documentation

Overview

Package lifx provides data structures and functions for communicating with LIFX devices.

This is based on the LAN protocol documented at https://lan.developer.lifx.com/docs, so only supports local (same network) communication.

Index

Constants

View Source
const (
	SawWaveform      = Waveform(0)
	SineWaveform     = Waveform(1)
	HalfSineWaveform = Waveform(2)
	TriangleWaveform = Waveform(3)
	PulseWaveform    = Waveform(4)
)

Variables

View Source
var ProductsFile []VendorProducts

ProductsFile represents the data from a products.json file.

The data is decoded from a version of https://github.com/LIFX/products embedded in this package.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient() (*Client, error)

func (*Client) Close

func (c *Client) Close()

func (*Client) Discover

func (c *Client) Discover(ctx context.Context) ([]*Device, error)

Discover probes the network for LIFX devices. The provided context controls how long to wait for responses; its cancellation or deadline expiry will stop execution of Discover but will not return an error.

type Color

type Color struct {
	Hue, Saturation, Brightness uint16
	Kelvin                      uint16
}

Color represents a single HSBK value.

https://lan.developer.lifx.com/docs/field-types#color

type Device

type Device struct {
	Addr   net.UDPAddr
	Serial [6]byte

	// Tracef, if set, will be used to write trace lines.
	Tracef func(ctx context.Context, format string, args ...interface{})
	// contains filtered or unexported fields
}

Device represents a LIFX device on the local network.

A device is bound to the Client that discovered it.

func (*Device) CaptureState

func (d *Device) CaptureState(ctx context.Context) (state State, err error)

CaptureState queries the device and returns its current configuration.

func (*Device) GetColor

func (d *Device) GetColor(ctx context.Context) (Color, error)

func (*Device) GetExtendedColorZones

func (d *Device) GetExtendedColorZones(ctx context.Context) (zones []Color, err error)

func (*Device) GetHostFirmware

func (d *Device) GetHostFirmware(ctx context.Context) (HostFirmware, error)

func (*Device) GetLabel

func (d *Device) GetLabel(ctx context.Context) (string, error)

func (*Device) GetLightPower

func (d *Device) GetLightPower(ctx context.Context) (uint16, error)

func (*Device) GetPower

func (d *Device) GetPower(ctx context.Context) (uint16, error)

func (*Device) GetVersion

func (d *Device) GetVersion(ctx context.Context) (vendor, product uint32, err error)

func (*Device) QuietOn

func (d *Device) QuietOn(ctx context.Context) error

QuietOn turns on the light power if it isn't already turned on. If it wasn't on, the light's brightness will be set to zero first.

func (*Device) RestoreState

func (d *Device) RestoreState(ctx context.Context, state State) error

RestoreState restores a device to its configuration at the time CaptureState was invoked.

func (*Device) SetColor

func (d *Device) SetColor(ctx context.Context, color Color, duration time.Duration) error

func (*Device) SetExtendedColorZones

func (d *Device) SetExtendedColorZones(ctx context.Context, duration time.Duration, zones []Color) error

func (*Device) SetLightPower

func (d *Device) SetLightPower(ctx context.Context, level uint16, duration time.Duration) error

func (*Device) SetWaveform

func (d *Device) SetWaveform(ctx context.Context, cfg WaveformConfig) error

type HostFirmware

type HostFirmware struct {
	Build        time.Time
	Major, Minor uint16
}

type Product

type Product struct {
	PID      uint32              `json:"pid"`
	Name     string              `json:"name"`
	Features ProductCapabilities `json:"features"`
	Upgrades []struct {
		Major    uint16              `json:"major"`
		Minor    uint16              `json:"minor"`
		Features ProductCapabilities `json:"features"`
	} `json:"upgrades"`
}

Product represents information about a product.

func DetermineProduct

func DetermineProduct(file []VendorProducts, vendorID, productID uint32, firmwareVersion HostFirmware) (Product, error)

DetermineProduct determines the product and its derived capabilities. Use this rather than manually inspecting ProductsFile, which should be passed as the first argument.

vendorID and productID arguments can be obtained with GetVersion, and firmwareVersion can be obtained with GetHostFirmware.

type ProductCapabilities

type ProductCapabilities struct {
	HEV    *bool `json:"hev,omitempty"`
	Color  *bool `json:"color,omitempty"`
	Matrix *bool `json:"matrix,omitempty"`

	Multizone         *bool    `json:"multizone,omitempty"`
	TemperatureRange  []uint16 `json:"temperature_range"` // should be two values (min and max); may be nil from DetermineProduct
	ExtendedMultizone *bool    `json:"extended_multizone,omitempty"`
}

ProductCapabilities represents the functional capabilities of a product.

The fields in this structure are nullable because the data file has a default layering semantic. Any Product returned through DetermineProduct is guaranteed to set all fields, except where otherwise specified.

func (ProductCapabilities) String

func (pc ProductCapabilities) String() string

type State

type State struct {
	// contains filtered or unexported fields
}

func (State) NumZones

func (s State) NumZones() int

type VendorProducts

type VendorProducts struct {
	VID  uint32 `json:"vid"`  // 1 == LIFX
	Name string `json:"name"` // e.g. "LIFX"

	Defaults ProductCapabilities `json:"defaults"`
	Products []Product           `json:"products"`
}

VendorProducts represents a vendor and all their products.

type Waveform

type Waveform int

type WaveformConfig

type WaveformConfig struct {
	Waveform  Waveform
	Transient bool

	Color Color

	Period time.Duration
	Cycles float32
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL