yeelight

package module
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2021 License: MIT Imports: 10 Imported by: 0

README

yeelight

This is a library to communicate with the Yeelights in your network. It allows you to easily change the color, brightness, power, etc.

Installation

To install, run:

go get github.com/newbits/yeelight

Usage

func main() {
  // Discover and retrieve a single Yeelight in the network
  y, err := yeelight.Discover()
  if err != nil {
    log.Fatal(err)
  }

  // Toggle power
  y.Power()

  // Set color
  y.Color("#112233")

  // Set brightness (percentage)
  y.Brightness(85)

  // Retrieve single property
  prop, _ := y.Prop("power")
  fmt.Printf("Power is %s", prop[0].(string))
}

API Specification

The Yeelight API Specification can be found here

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 Device

type Device struct {
	Address string
	Random  *rand.Rand
}

func Discover

func Discover() (*Device, error)

Discover discovers a single device in the local network via SSDP

func DiscoverMany

func DiscoverMany() ([]*Device, error)

DiscoverMany tries to discover many devices at once

func New

func New(address string) *Device

New creates new device instance for address provided

func (Device) Brightness

func (d Device) Brightness(brightness int) error

func (Device) Color

func (d Device) Color(color string) error

func (Device) GetStatus added in v0.3.0

func (d Device) GetStatus() error

func (*Device) Listen

func (d *Device) Listen() (<-chan *Notification, chan<- struct{}, error)

Listen connects to device and listens for NOTIFICATION events

func (Device) New

func (d Device) New() *Device

func (Device) Power

func (d Device) Power() error

Power state toggle for light

func (Device) PowerOff added in v0.3.0

func (d Device) PowerOff() error

func (Device) PowerOn added in v0.3.0

func (d Device) PowerOn() error

func (*Device) Prop

func (d *Device) Prop(values ...interface{}) ([]interface{}, error)

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

func (Device) StopTimer

func (d Device) StopTimer() error

func (Device) Timer

func (d Device) Timer(minutes int) error

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

Jump to

Keyboard shortcuts

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