Documentation
¶
Index ¶
- Constants
- func Copy(dst *Light, src *Light)
- func SSDPMonitor(lightmap map[string]*Light, lightfound func(light *Light)) error
- func Search(time int, localAddr string, lights map[string]*Light, ...) error
- type Command
- type Error
- type Light
- func (l *Light) Close() error
- func (l *Light) Connect() error
- func (l *Light) GetProp(props ...interface{}) (int32, error)
- func (l *Light) Listen(notifCh chan<- *ResultNotification) (chan<- bool, error)
- func (l *Light) Message() (string, error)
- func (l *Light) SendCommand(comm string, params ...interface{}) (int32, error)
- func (l *Light) SetBrightness(brightness int, duration int) (int32, error)
- func (l *Light) SetHSV(hsv uint16, sat uint8, duration int) (int32, error)
- func (l *Light) SetName(name string, duration int) (int32, error)
- func (l *Light) SetPower(power bool, effect int, duration int) (int32, error)
- func (l *Light) SetRGB(rgb uint32, duration int) (int32, error)
- func (l *Light) SetTemperature(temp int, duration int) (int32, error)
- func (l *Light) Toggle() (int32, error)
- func (l *Light) WaitResult(res int32, timeout int) *Result
- type Notification
- type Result
- type ResultNotification
Constants ¶
const ( // OFF Light off OFF = iota // ON Light on ON = iota // OFFLINE Light unreachable UNKNOWN = iota )
Light's power
const ( OFFLINE = 0 SSDP = 1 UPDATING = 2 ONLINE = 3 )
Light's connectivity
Variables ¶
This section is empty.
Functions ¶
func SSDPMonitor ¶
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 ¶
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 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 ¶
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) 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) SendCommand ¶
SendCommand sends "comm" command to a light with "params" parameters returning the request ID for tracking results
func (*Light) SetBrightness ¶
SetBrightness set light's brightness with effect of duration
func (*Light) SetTemperature ¶
SetTemperature set light's color temperature with effect of duration
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