yeelight

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

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

Go to latest
Published: Aug 27, 2018 License: MIT Imports: 13 Imported by: 1

README

Xiaomi Yeelight lights API for Go

Go Report Card

Documentation

Index

Constants

View Source
const (
	// OFF Light off
	OFF = iota
	// ON Light on
	ON = iota
	// OFFLINE Light unreachable
	UNKNOWN = iota
)

Light's power

View Source
const (
	OFFLINE  = 0
	SSDP     = 1
	UPDATING = 2
	ONLINE   = 3
)

Light's connectivity

Variables

This section is empty.

Functions

func Copy

func Copy(dst *Light, src *Light)

Copy copies just light's values Omitting internal entities like channels, sockets, etc

func SSDPMonitor

func SSDPMonitor(lightmap map[string]*Light, lightfound func(light *Light)) error

SSDPMonitor starts listening light's SSDP traffic lightmap is a map of *Light so it can update it with lights found, lightfound is called for each new light found

func Search(time int, localAddr string, lights map[string]*Light, lightfound func(light *Light)) error

Search searches and update lights for some time using SSDP and fills the map with new lights found indexed by its ID. lightfound is called with the newly found light, usually to start listening it

Types

type Command

type Command struct {
	ID     int32         `json:"id"`
	Method string        `json:"method"`
	Params []interface{} `json:"params"`
}

Command JSON commands sent to lights

type Error

type Error struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

Error codes from lights

type Light

type Light struct {
	Address      string          `json:"address"`
	Name         string          `json:"name"`
	ID           string          `json:"id"`
	Model        string          `json:"model"`
	CacheControl string          `json:"cache-control"`
	FW           int             `json:"fw"`
	Power        string          `json:"power"`
	Bright       int             `json:"bright"`
	Sat          int             `json:"sat"`
	CT           int             `json:"ct"`
	RGB          int             `json:"rgb"`
	Hue          int             `json:"hue"`
	ColorMode    int             `json:"color_mode"`
	Support      map[string]bool `json:"support"`
	ReqCount     int32           `json:"reqcount"`
	LastSeen     int64           `json:"lastseen"`
	Status       int32           `json:"status"`

	Conn   *net.TCPConn       `json:"-"`
	Calls  map[int32]*Command `json:"-"`
	ResC   chan *Result       `json:"-"`
	Reader *bufio.Reader      `json:"-"`
	// contains filtered or unexported fields
}

Light is the light :)

func Parse

func Parse(header http.Header) (*Light, error)

Parse returns a Yeelight based on the HTTP headers of its SSDP response represented by header it returns an error if something goes wrong during parsing

func (*Light) Close

func (l *Light) Close() error

Close closes the connection to light

func (*Light) Connect

func (l *Light) Connect() error

Connect connects to a light

func (*Light) GetProp

func (l *Light) GetProp(props ...interface{}) (int32, error)

GetProp gets light properties

func (*Light) Listen

func (l *Light) Listen(notifCh chan<- *ResultNotification) (chan<- bool, error)

Listen connects to light and listens for events which are sent to notifCh

func (*Light) Message

func (l *Light) Message() (string, error)

Message gets light messages

func (*Light) SendCommand

func (l *Light) SendCommand(comm string, params ...interface{}) (int32, error)

SendCommand sends "comm" command to a light with "params" parameters returning the request ID for tracking results

func (*Light) SetBrightness

func (l *Light) SetBrightness(brightness int, duration int) (int32, error)

SetBrightness set light's brightness with effect of duration

func (*Light) SetHSV

func (l *Light) SetHSV(hsv uint16, sat uint8, duration int) (int32, error)

SetHSV set light's color in HSV format with effect of duration

func (*Light) SetName

func (l *Light) SetName(name string, duration int) (int32, error)

SetName set light's name

func (*Light) SetPower

func (l *Light) SetPower(power bool, effect int, duration int) (int32, error)

SetPower set light's power with effect of duration

func (*Light) SetRGB

func (l *Light) SetRGB(rgb uint32, duration int) (int32, error)

SetRGB set light's color in RGB format with effect of duration

func (*Light) SetTemperature

func (l *Light) SetTemperature(temp int, duration int) (int32, error)

SetTemperature set light's color temperature with effect of duration

func (*Light) Toggle

func (l *Light) Toggle() (int32, error)

Toggle toogle light's power on/off

func (*Light) WaitResult

func (l *Light) WaitResult(res int32, timeout int) *Result

WaitResult waits timeout seconds for a result on a request with res ID

type Notification

type Notification struct {
	DevID  string
	Method string                 `json:"method"`
	Params map[string]interface{} `json:"params"`
}

Notification represents notification response

type Result

type Result struct {
	DevID  string
	ID     int           `json:"id"`
	Result []interface{} `json:"result,omitempty"`
	Error  *Error        `json:"error,omitempty"`
}

Result represent results to commands from lights

type ResultNotification

type ResultNotification struct {
	*Result
	*Notification
}

ResultNotification is the generic response

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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