yeelight

package module
v0.0.0-...-1c0cb75 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2020 License: MIT Imports: 9 Imported by: 1

README

Build Status License MIT Go Report Card Code Coverage

yeelight

Golang API for Yeelight

Overview

Yeelight is simple command line tool and Golang implementation API of Yeelight protocol with notification listening support

Installation

Make sure you have a working Go environment. See Golang install instructionshttp://golang.org/doc/install.html)

To install, run:

go get github.com/avarabyeu/yeelight

Usage

func main() {
	y, err := yeelight.Discover()
	checkError(err)

	on, err := y.GetProp("power")
	checkError(err)
	fmt.Printf("Power is %s", on[0].(string))

	notifications, done, err := y.Listen()
	checkError(err)
	go func() {
		<-time.After(time.Second)
		done <- struct{}{}
	}()
	for n := range notifications {
		fmt.Println(n)
	}

	context.Background().Done()

}

API Specification

Yeelight API Specification [can be found here] (https://www.yeelight.com/download/Yeelight_Inter-Operation_Spec.pdf)

License

yeelight is distributed under the MIT license

Yeelight® is a registered trademark of Yeelight.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Command

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

Command represents COMMAND request to Yeelight device

type CommandResult

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

CommandResult represents response from Yeelight device

type Error

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

Error struct represents error part of response

type Notification

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

Notification represents notification response

type Yeelight

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

Yeelight represents device

func Discover

func Discover() (*Yeelight, error)

Discover discovers device in local network via ssdp

func New

func New(addr string) *Yeelight

New creates new device instance for address provided

func (*Yeelight) GetProp

func (y *Yeelight) GetProp(values ...interface{}) ([]interface{}, error)

GetProp method is used to retrieve current property of smart LED.

func (*Yeelight) Listen

func (y *Yeelight) Listen() (<-chan *Notification, chan<- struct{}, error)

Listen connects to device and listens for NOTIFICATION events

func (*Yeelight) SetBright

func (y *Yeelight) SetBright(bright int) error

func (*Yeelight) SetPower

func (y *Yeelight) SetPower(on bool) error

SetPower is used to switch on or off the smart LED (software managed on/off).

func (*Yeelight) ThrowAlarm

func (y *Yeelight) ThrowAlarm() error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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