yeelight

package module
v1.0.7-0...-fa84b97 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2021 License: MIT Imports: 15 Imported by: 2

README

Build Status License MIT Go Report Card Code Coverage

Yeelight Golang API

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 instructions

To install, run:

go get github.com/akominch/yeelight

Usage

import (
	"github.com/akominch/yeelight"
	t "github.com/akominch/yeelight/transitions"
)

func main() {
        config := yeelight.BulbConfig{
		Ip: "192.168.1.24",
		Effect: yeelight.Smooth,
	}
	bulb := yeelight.New(config)

	transitions := t.Alarm()
	flow := yeelight.NewFlow(3, yeelight.Off, transitions)
	_, _ = bulb.StartFlow(flow)
}

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

View Source
const (
	Recover Action = 0
	Stay           = 1
	Off            = 2
)
View Source
const (
	Last      Mode = 0
	Normal         = 1
	RGB            = 2
	HSV            = 3
	ColorFlow      = 4
	Moonlight      = 5
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action int8

type Bulb

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

Bulb represents device

func Discover

func Discover() (*Bulb, error)

Discover discovers device in local network via ssdp

func New

func New(config BulbConfig) *Bulb

func (*Bulb) Discover

func (y *Bulb) Discover() (*YeelightParams, error)

func (*Bulb) EnsureOn

func (y *Bulb) EnsureOn() error

func (*Bulb) ExecuteCommand

func (y *Bulb) ExecuteCommand(name string, params ...interface{}) (*CommandResult, error)

func (*Bulb) GetProps

func (y *Bulb) GetProps(props []string) (*PropsResult, error)

func (*Bulb) IsOn

func (y *Bulb) IsOn() (bool, error)

func (*Bulb) Listen

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

Listen connects to device and listens for NOTIFICATION events

func (*Bulb) SetBrightness

func (y *Bulb) SetBrightness(brightness int) (*CommandResult, error)

func (*Bulb) SetBrightnessWithDuration

func (y *Bulb) SetBrightnessWithDuration(brightness int, duration int) (*CommandResult, error)

func (*Bulb) SetHSV

func (y *Bulb) SetHSV(hue int, saturation int) (*CommandResult, error)

func (*Bulb) SetName

func (y *Bulb) SetName(name string) (*CommandResult, error)

func (*Bulb) SetRGB

func (y *Bulb) SetRGB(rgba color.RGBA) (*CommandResult, error)

func (*Bulb) StartFlow

func (y *Bulb) StartFlow(flow *Flow) (*CommandResult, error)

func (*Bulb) StopFlow

func (y *Bulb) StopFlow() (*CommandResult, error)

func (*Bulb) TurnOff

func (y *Bulb) TurnOff() (*CommandResult, error)

func (*Bulb) TurnOn

func (y *Bulb) TurnOn() (*CommandResult, error)

func (*Bulb) TurnOnWithParams

func (y *Bulb) TurnOnWithParams(mode Mode, duration int) (*CommandResult, error)

type BulbConfig

type BulbConfig struct {
	Ip     string
	Effect EffectType
}

Bulb represents device

type Command

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

Command represents COMMAND request to Bulb device

type CommandResult

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

CommandResult represents response from Bulb device

type EffectType

type EffectType string
const (
	Smooth EffectType = "smooth"
	Sudden            = "sudden"
)

type Error

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

Error struct represents error part of response

type Flow

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

func NewFlow

func NewFlow(count int, action Action, transitions []t.Transition) *Flow

func (*Flow) AsStartParams

func (flow *Flow) AsStartParams() []interface{}

type LightType

type LightType int
const (
	Main    LightType = 0
	Ambient           = 1
)

type Mode

type Mode int

type Notification

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

Notification represents notification response

type PropsResult

type PropsResult struct {
	ID     int
	Result map[string]string
	Error  *Error
}

type YeelightParams

type YeelightParams struct {
	Model     string   `json:"model"`
	Support   []string `json:"support"`
	Power     string   `json:"power"`
	Bright    int      `json:"bright"`
	ColorMode int      `json:"color_mode"`
	RGB       int      `json:"rgb"`
	Hue       int      `json:"hue"`
	Sat       int      `json:"sat"`
	Name      string   `json:"name"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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