lifx

package module
v0.0.0-...-15145d1 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2022 License: MPL-2.0 Imports: 11 Imported by: 1

README

lifx-go

Documentation

Index

Constants

View Source
const (
	KelvinCandlelight    = 1500
	KelvinSunset         = 2000
	KelvinUltraWarm      = 2500
	KelvinIncandescent   = 2700
	KelvinWarm           = 3000
	KelvinCool           = 4000
	KelvinCoolDaylight   = 4500
	KelvinSoftDaylight   = 5000
	KelvinDaylight       = 5600
	KelvinNoonDaylight   = 6000
	KelvinBrightDaylight = 6500
	KelvinCloudDaylight  = 7000
	KelvinBlueDaylight   = 7500
	KelvinBlueOvercast   = 8000
	KelvinBlueIce        = 9000

	HueWhite  = 0
	HueRed    = 0
	HueOrange = 36
	HueYellow = 60
	HueGreen  = 120
	HueCyan   = 180
	HueBlue   = 250
	HuePurple = 280
	HuePink   = 325
)
View Source
const Version = "0.1.0-pre"

Variables

View Source
var (
	Endpoint      = "https://api.lifx.com/v1"
	EndpointState = func(selector string) string {
		return BuildURL(Endpoint, fmt.Sprintf("/lights/%s/state", selector))
	}
	EndpointStateDelta = func(selector string) string {
		return BuildURL(Endpoint, fmt.Sprintf("/lights/%s/state/delta", selector))
	}
	EndpointListLights = func(selector string) string {
		return BuildURL(Endpoint, fmt.Sprintf("/lights/%s", selector))
	}
	EndpointStates = func() string {
		return BuildURL(Endpoint, "/lights/states")
	}
	EndpointColor = func() string {
		return BuildURL(Endpoint, "/color")
	}
	EndpointToggle = func(selector string) string {
		return BuildURL(Endpoint, fmt.Sprintf("/lights/%s/toggle", selector))
	}
	EndpointBreathe = func(selector string) string {
		return BuildURL(Endpoint, fmt.Sprintf("/lights/%s/effects/breathe", selector))
	}
)
View Source
var (
	DefaultBreatheCycles  float64 = 1
	DefaultBreathePeriod  float64 = 1
	DefaultBreathePersist bool    = false
	DefaultBreathePowerOn bool    = true
	DefaultBreathePeak    float64 = 0.5
)
View Source
var (
	DefaultWhites = map[string]int{
		"candlelight":    KelvinCandlelight,
		"sunset":         KelvinSunset,
		"ultrawarm":      KelvinUltraWarm,
		"incandescent":   KelvinIncandescent,
		"warm":           KelvinWarm,
		"cool":           KelvinCool,
		"cooldaylight":   KelvinCoolDaylight,
		"softdaylight":   KelvinSoftDaylight,
		"daylight":       KelvinDaylight,
		"noondaylight":   KelvinNoonDaylight,
		"brightdaylight": KelvinBrightDaylight,
		"clouddaylight":  KelvinCloudDaylight,
		"bluedaylight":   KelvinBlueDaylight,
		"blueovercast":   KelvinBlueOvercast,
		"blueice":        KelvinBlueIce,
	}
)

Functions

func BuildURL

func BuildURL(rawurl, rawpath string) string

func Float32Ptr

func Float32Ptr(v float32) *float32

func Float64Ptr

func Float64Ptr(v float64) *float64

func Int16Ptr

func Int16Ptr(v int16) *int16

func IntPtr

func IntPtr(v int) *int

func StringPtr

func StringPtr(v string) *string

func WithDebug

func WithDebug(debug bool) func(*Client)

func WithUserAgent

func WithUserAgent(userAgent string) func(*Client)

Types

type Breathe

type Breathe struct {
	Color     Color   `json:"color,omitempty"`
	FromColor Color   `json:"from_color,omitempty"`
	Period    float64 `json:"period,omitempty"`
	Cycles    float64 `json:"cycles,omitempty"`
	Persist   bool    `json:"persist,omitempty"`
	PowerOn   bool    `json:"power_on,omitempty"`
	Peak      float64 `json:"peak,omitempty"`
}

func NewBreathe

func NewBreathe() Breathe

func (*Breathe) Valid

func (b *Breathe) Valid() error

type Capabilities

type Capabilities struct {
	HasColor             bool    `json:"has_color"`
	HasVariableColorTemp bool    `json:"has_variable_color_temp"`
	HasIR                bool    `json:"has_ir"`
	HasChain             bool    `json:"has_chain"`
	HasMultizone         bool    `json:"has_multizone"`
	MinKelvin            float64 `json:"min_kelvin"`
	MaxKelvin            float64 `json:"max_kelvin"`
}

type Client

type Client struct {
	Client *http.Client
	// contains filtered or unexported fields
}

func NewClient

func NewClient(accessToken string, options ...func(*Client)) *Client

func NewClientWithUserAgent

func NewClientWithUserAgent(accessToken string, userAgent string) *Client

func (*Client) Breathe

func (c *Client) Breathe(selector string, breathe Breathe) (*LifxResponse, error)

func (*Client) FastPowerOff

func (c *Client) FastPowerOff(selector string)

func (*Client) FastPowerOn

func (c *Client) FastPowerOn(selector string)

func (*Client) FastSetState

func (c *Client) FastSetState(selector string, state State) (*LifxResponse, error)

func (*Client) ListLights

func (c *Client) ListLights(selector string) ([]Light, error)

func (*Client) NewRequest

func (c *Client) NewRequest(method, url string, body io.Reader) (req *http.Request, err error)

func (*Client) PowerOff

func (c *Client) PowerOff(selector string) (*LifxResponse, error)

func (*Client) PowerOn

func (c *Client) PowerOn(selector string) (*LifxResponse, error)

func (*Client) SetState

func (c *Client) SetState(selector string, state State) (*LifxResponse, error)

func (*Client) SetStates

func (c *Client) SetStates(states States) (*LifxResponse, error)

func (*Client) StateDelta

func (c *Client) StateDelta(selector string, delta StateDelta) (*LifxResponse, error)

func (*Client) Toggle

func (c *Client) Toggle(selector string, duration float64) (*LifxResponse, error)

func (*Client) ValidateColor

func (c *Client) ValidateColor(color Color) (Color, error)

type Color

type Color interface {
	ColorString() string
}

type Error

type Error struct {
	Field   string   `json:"field"`
	Message []string `json:"message"`
}

type HSBKColor

type HSBKColor struct {
	H *float32 `json:"hue"`
	S *float32 `json:"saturation"`
	B *float32 `json:"brightness"`
	K *int16   `json:"kelvin"`
}

func NewCyan

func NewCyan() (HSBKColor, error)

func NewGreen

func NewGreen() (HSBKColor, error)

func NewHSBColor

func NewHSBColor(h, s, b float32) (HSBKColor, error)

func NewHSColor

func NewHSColor(h, s float32) (HSBKColor, error)

func NewOrange

func NewOrange() (HSBKColor, error)

func NewPink

func NewPink() (HSBKColor, error)

func NewPurple

func NewPurple() (HSBKColor, error)

func NewRed

func NewRed() (HSBKColor, error)

func NewWhite

func NewWhite(k int16) (HSBKColor, error)

func NewWhiteString

func NewWhiteString(s string) (HSBKColor, error)

func NewYellow

func NewYellow() (HSBKColor, error)

func (HSBKColor) ColorString

func (c HSBKColor) ColorString() string

func (HSBKColor) MarshalText

func (c HSBKColor) MarshalText() ([]byte, error)

func (HSBKColor) String

func (c HSBKColor) String() string

type LifxResponse

type LifxResponse struct {
	Error    string    `json:"error"`
	Errors   []Error   `json:"errors"`
	Warnings []Warning `json:"warnings"`
	Results  []Result  `json:"results"`
}

type Light

type Light struct {
	Id              string     `json:"id"`
	UUID            string     `json:"uuid"`
	Label           string     `json:"label"`
	Connected       bool       `json:"connected"`
	Power           string     `json:"power"`
	Color           HSBKColor  `json:"color"`
	Brightness      float64    `json:"brightness"`
	Effect          string     `json:"effect"`
	Group           Selector   `json:"group"`
	Location        Selector   `json:"location"`
	Product         Product    `json:"product"`
	LastSeen        *time.Time `json:"last_seen,omitempty"`
	SecondsLastSeen float64    `json:"seconds_last_seen"`
}

type NamedColor

type NamedColor string

func (NamedColor) ColorString

func (c NamedColor) ColorString() string

func (NamedColor) String

func (c NamedColor) String() string

type Product

type Product struct {
	Name         string       `json:"name"`
	Identifier   string       `json:"identifier"`
	Company      string       `json:"company"`
	Capabilities Capabilities `json:"capabilities"`
}

type RGBColor

type RGBColor struct {
	R, G, B uint8
}

func NewRGBColor

func NewRGBColor(r, g, b uint8) (RGBColor, error)

func (RGBColor) ColorString

func (c RGBColor) ColorString() string

func (RGBColor) Hex

func (c RGBColor) Hex() string

func (RGBColor) MarshalText

func (c RGBColor) MarshalText() ([]byte, error)

func (RGBColor) String

func (c RGBColor) String() string

type RateLimit

type RateLimit struct {
	Limit     int
	Remaining int
	Reset     time.Time
}

type Response

type Response struct {
	StatusCode int
	Header     http.Header
	Body       io.ReadCloser
	RateLimit  RateLimit
}

func NewResponse

func NewResponse(r *http.Response) (*Response, error)

func (*Response) GetLifxError

func (r *Response) GetLifxError() (err error)

func (*Response) IsError

func (r *Response) IsError() bool

type Result

type Result struct {
	Id     string `json:"id"`
	Label  string `json:"label"`
	Status Status `json:"status"`
}

type Selector

type Selector struct {
	Id   string `json:"id"`
	Name string `json:"name"`
}

type State

type State struct {
	Power      string  `json:"power,omitempty"`
	Color      Color   `json:"color,omitempty"`
	Brightness float64 `json:"brightness,omitempty"`
	Duration   float64 `json:"duration,omitempty"`
	Infrared   float64 `json:"infrared,omitempty"`
	Fast       bool    `json:"fast,omitempty"`
}

type StateDelta

type StateDelta struct {
	Power      *string  `json:"power,omitempty"`
	Duration   *float64 `json:"duration,omitempty"`
	Infrared   *float64 `json:"infrared,omitempty"`
	Hue        *float64 `json:"hue,omitempty"`
	Saturation *float64 `json:"saturation,omitempty"`
	Brightness *float64 `json:"brightness,omitempty"`
	Kelvin     *int     `json:"kelvin,omitempty"`
}

type StateWithSelector

type StateWithSelector struct {
	State
	Selector string `json:"selector"`
}

type States

type States struct {
	States   []StateWithSelector `json:"states,omitempty"`
	Defaults State               `json:"defaults,omitempty"`
}

type Status

type Status string
const (
	OK       Status = "ok"
	TimedOut Status = "timed_out"
	Offline  Status = "offline"
)

type Toggle

type Toggle struct {
	Duration float64 `json:"duration,omitempty"`
}

type Warning

type Warning struct {
	Warning string `json:"warning"`
}

Jump to

Keyboard shortcuts

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