Documentation ¶
Index ¶
- Constants
- Variables
- func Properties() []string
- func ValidateAdjustPercentage(value int) error
- func ValidateBright(value int) error
- func ValidateColorTemperature(value int) error
- func ValidateDuration(duration time.Duration) error
- func ValidateHue(value int) error
- func ValidateRGB(value int) error
- func ValidateSat(value int) error
- type AdjustAction
- type AdjustProp
- type CallResponse
- type Client
- func (c Client) AddCron(ctx context.Context, on bool, timeout time.Duration) error
- func (c Client) AdjustBackgroundBright(ctx context.Context, percentage int, duration time.Duration) error
- func (c Client) AdjustBackgroundColor(ctx context.Context, percentage int, duration time.Duration) error
- func (c Client) AdjustBackgroundColorTemperature(ctx context.Context, percentage int, duration time.Duration) error
- func (c Client) AdjustBright(ctx context.Context, percentage int, duration time.Duration) error
- func (c Client) AdjustColor(ctx context.Context, percentage int, duration time.Duration) error
- func (c Client) AdjustColorTemperature(ctx context.Context, percentage int, duration time.Duration) error
- func (c Client) BackgroundPower(ctx context.Context, on bool, mode PowerMode, effect Effect, ...) error
- func (c Client) BackgroundToggle(ctx context.Context) error
- func (c Client) Call(ctx context.Context, method string, params ...interface{}) (CallResponse, error)
- func (c Client) DeleteCron(ctx context.Context, on bool) error
- func (c Client) DevToggle(ctx context.Context) error
- func (c Client) GetCron(ctx context.Context, on bool) (time.Duration, error)
- func (c Client) GetProperties(ctx context.Context, properties []string) (map[string]string, error)
- func (c Client) Listen(ctx context.Context) (<-chan string, error)
- func (c Client) Power(ctx context.Context, on bool, mode PowerMode, effect Effect, ...) error
- func (c Client) SetAdjust(ctx context.Context, action AdjustAction, prop AdjustProp) error
- func (c Client) SetBackgroundAdjust(ctx context.Context, action AdjustAction, prop AdjustProp) error
- func (c Client) SetBackgroundBright(ctx context.Context, brightness int, effect Effect, duration time.Duration) error
- func (c Client) SetBackgroundColorTemperature(ctx context.Context, value int, effect Effect, duration time.Duration) error
- func (c Client) SetBackgroundDefault(ctx context.Context) error
- func (c Client) SetBackgroundHSV(ctx context.Context, hue int, sat int, effect Effect, duration time.Duration) error
- func (c Client) SetBackgroundRGB(ctx context.Context, value int, effect Effect, duration time.Duration) error
- func (c Client) SetBright(ctx context.Context, brightness int, effect Effect, duration time.Duration) error
- func (c Client) SetColorTemperature(ctx context.Context, value int, effect Effect, duration time.Duration) error
- func (c Client) SetDefault(ctx context.Context) error
- func (c Client) SetHSV(ctx context.Context, hue int, sat int, effect Effect, duration time.Duration) error
- func (c Client) SetMusic(ctx context.Context, on bool, musicHost string, port int) error
- func (c Client) SetName(ctx context.Context, name string) error
- func (c Client) SetRGB(ctx context.Context, value int, effect Effect, duration time.Duration) error
- func (c Client) StartBackgroundColorFlow(ctx context.Context, count int, action FlowAction, ...) error
- func (c Client) StartColorFlow(ctx context.Context, count int, action FlowAction, ...) error
- func (c Client) StopBackgroundColorFlow(ctx context.Context) error
- func (c Client) StopColorFlow(ctx context.Context) error
- func (c Client) Toggle(ctx context.Context) error
- type DiscoveryResultItem
- type Effect
- type FlowAction
- type FlowExpression
- type FlowMode
- type PowerMode
- type UnknownError
Constants ¶
const ( MethodGetProp = "get_prop" MethodSetColorTemperature = "set_ct_abx" MethodSetRGB = "set_rgb" MethodSetHSV = "set_hsv" MethodSetBright = "set_bright" MethodSetPower = "set_power" MethodToggle = "toggle" MethodSetDefault = "set_default" MethodStartCF = "start_cf" MethodStopCF = "stop_cf" MethodSetScene = "set_scene" // TODO: implement me MethodCronAdd = "cron_add" MethodCronGet = "cron_get" MethodCronDelete = "cron_del" MethodSetAdjust = "set_adjust" MethodSetMusic = "set_music" MethodSetName = "set_name" MethodSetBgRGB = "bg_set_rgb" MethodSetBgHSV = "bg_set_hsv" MethodSetBgColorTemperature = "bg_set_ct_abx" MethodBgStartCF = "bg_start_cf" MethodBgStopCF = "bg_stop_cf" MethodBgSetScene = "bg_set_scene" // TODO: implement me MethodBgSetDefault = "bg_set_default" MethodBgSetPower = "bg_set_power" MethodSetBgBright = "bg_set_bright" MethodSetBgAdjust = "bg_set_adjust" MethodBgToggle = "bg_toggle" MethodDevToggle = "dev_toggle" MethodAdjustBright = "adjust_bright" MethodAdjustCt = "adjust_ct" MethodAdjustColor = "adjust_color" MethodBgAdjustBright = "bg_adjust_bright" MethodBgAdjustCt = "bg_adjust_ct" MethodBgAdjustColor = "bg_adjust_color" )
list of all supported methods
const ( PropertyPower = "power" PropertyBright = "bright" PropertyCT = "ct" PropertyRGB = "rgb" PropertyHue = "hue" PropertySat = "sat" PropertyColorMode = "color_mode" PropertyFlowing = "flowing" PropertyDelayOff = "delayoff" PropertyFlowParams = "flow_params" PropertyMusicOn = "music_on" PropertyName = "name" PropertyBgPower = "bg_power" PropertyBgFlowing = "bg_flowing" PropertyBgFlowParams = "bg_flow_params" PropertyBgCt = "bg_ct" PropertyBgLMode = "bg_lmode" // TODO: is this property correct? PropertyBgBright = "bg_bright" PropertyBgRgb = "bg_rgb" PropertyBgHue = "bg_hue" PropertyBgSat = "bg_sat" PropertyNlBr = "nl_br" PropertyActiveMode = "active_mode" BrightWithZero = "bright_with_zero" )
Properties
const ( MinDuration = 30 * time.Millisecond MinAdjustPercentage = -100 MaxAdjustPercentage = 100 MinRGB = 0 MaxRGB = 16777215 // (hex: 0xFFFFFF) MinHue = 0 MaxHue = 359 MinSat = 0 MaxSat = 100 MinBright = 0 MaxBright = 100 MinColorTemperature = 1700 MaxColorTemperature = 6500 )
Variables ¶
var ( // ErrWrongNumberOfResultItems says that response has wrong number of result items ErrWrongNumberOfResultItems = errors.New("wrong number of result items") // ErrCronIsUnset says that cron is unset ErrCronIsUnset = errors.New("cron is unset") // ErrDurationTooSmall says that duration too small ErrDurationTooSmall = errors.New("duration too small") // ErrWrongAdjustPercentage says that wrong percentage ErrWrongAdjustPercentage = errors.New("wrong percentage") // ErrWrongRGBValue says that wrong RGB value ErrWrongRGBValue = errors.New("wrong RGB value") // ErrWrongHueValue says that wrong Hue value ErrWrongHueValue = errors.New("wrong Hue value") // ErrWrongSatValue says that wrong Sat value ErrWrongSatValue = errors.New("wrong Sat value") // ErrWrongBrightValue says that wrong Bright value ErrWrongBrightValue = errors.New("wrong Bright value") // ErrWrongColorTemperature says that wrong color temperature ErrWrongColorTemperature = errors.New("wrong color temperature") // ErrRequiredMinimumOneExpression says that required minimum one expression ErrRequiredMinimumOneExpression = errors.New("required minimum one expression") // ErrMissingPortInAddress says that missing port in address ErrMissingPortInAddress = errors.New("missing port in address") // ErrConnect says that connect error ErrConnect = errors.New("connect error") // ErrMethodNotSupported says that method not supported ErrMethodNotSupported = errors.New("method not supported") // ErrResponseJSONSyntax says that response json has syntax error ErrResponseJSONSyntax = errors.New("response json has syntax error") )
Functions ¶
func ValidateAdjustPercentage ¶
ValidateAdjustPercentage validate percentage for adjust_* methods validation rules in MinAdjustPercentage and MaxAdjustPercentage
func ValidateBright ¶
func ValidateDuration ¶
ValidateDuration validate duration validation rules in MinDuration
func ValidateHue ¶
ValidateHue validate hue validation rules in MinHue and MaxHue
func ValidateRGB ¶
ValidateRGB validate rgb validation rules in MinRGB and MaxRGB
func ValidateSat ¶
ValidateSat validate sat validation rules in MinSat and MaxSat
Types ¶
type AdjustAction ¶
type AdjustAction string
AdjustAction is enum of Adjust Actions
const ( AdjustActionIncrease AdjustAction = "increase" AdjustActionDecrease AdjustAction = "decrease" AdjustActionCircle AdjustAction = "circle" )
Adjust Actions options
type AdjustProp ¶
type AdjustProp string
AdjustProp is enum of Adjust Properties
const ( AdjustPropBright AdjustProp = "bright" AdjustPropColorTemperature AdjustProp = "ct" AdjustPropColor AdjustProp = "color" )
Adjust Properties options
type CallResponse ¶
type CallResponse struct { ID int `json:"id"` Result json.RawMessage `json:"result"` Error json.RawMessage `json:"error"` }
CallResponse contains raw response from device.
func (CallResponse) Bind ¶
func (rr CallResponse) Bind(target interface{}) error
Bind response result to provided variable
func (CallResponse) ToError ¶
func (rr CallResponse) ToError() error
ToError checks if the answer contains an error.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client isRaw instance of Yeelight SDK Please use New() for creating
func (Client) AddCron ¶
AddCron method isRaw used to start a timer job on the smart LED parameter `on` currently can only be false. (means power off) parameter `timeout` isRaw the length of the timer
func (Client) AdjustBackgroundBright ¶
func (c Client) AdjustBackgroundBright(ctx context.Context, percentage int, duration time.Duration) error
AdjustBackgroundBright method is used to adjust the brightness by specified percentage within specified duration.
func (Client) AdjustBackgroundColor ¶
func (c Client) AdjustBackgroundColor(ctx context.Context, percentage int, duration time.Duration) error
AdjustBackgroundColor method is used to adjust the color within specified duration.
func (Client) AdjustBackgroundColorTemperature ¶
func (c Client) AdjustBackgroundColorTemperature(ctx context.Context, percentage int, duration time.Duration) error
AdjustBackgroundColorTemperature method is used to adjust the color temperature by specified percentage within specified duration.
func (Client) AdjustBright ¶
AdjustBright method is used to adjust the brightness by specified percentage within specified duration.
func (Client) AdjustColor ¶
AdjustColor method is used to adjust the color within specified duration.
func (Client) AdjustColorTemperature ¶
func (c Client) AdjustColorTemperature(ctx context.Context, percentage int, duration time.Duration) error
AdjustColorTemperature method is used to adjust the color temperature by specified percentage within specified duration.
func (Client) BackgroundPower ¶
func (c Client) BackgroundPower(ctx context.Context, on bool, mode PowerMode, effect Effect, duration time.Duration) error
BackgroundPower method isRaw used to switch on or off the smart LED (software managed on/off).
func (Client) BackgroundToggle ¶
BackgroundToggle method isRaw used to toggle the smart LED.
func (Client) Call ¶
func (c Client) Call(ctx context.Context, method string, params ...interface{}) (CallResponse, error)
Call method of device with provided parameters
func (Client) DeleteCron ¶
DeleteCron method isRaw used to stop the specified cron job parameter `on` currently can only be false. (means power off)
func (Client) DevToggle ¶
DevToggle method is used to toggle the main light and background light at the same time.
func (Client) GetCron ¶
GetCron method isRaw used to retrieve the setting of the current cron job of the specified type parameter `on` currently can only be false. (means power off)
func (Client) GetProperties ¶
GetProperties method isRaw used to retrieve current property of smart LED Arg `properties` isRaw a list of requested properties. List of all possible properties available in function Properties()
func (Client) Power ¶
func (c Client) Power(ctx context.Context, on bool, mode PowerMode, effect Effect, duration time.Duration) error
Power method isRaw used to switch on or off the smart LED (software managed on/off).
func (Client) SetAdjust ¶
func (c Client) SetAdjust(ctx context.Context, action AdjustAction, prop AdjustProp) error
SetAdjust method is used to change brightness, CT or color of a smart LED without knowing the current value, it's main used by controllers.
func (Client) SetBackgroundAdjust ¶
func (c Client) SetBackgroundAdjust(ctx context.Context, action AdjustAction, prop AdjustProp) error
SetBackgroundAdjust method is used to change brightness, CT or color of a smart LED without knowing the current value, it's main used by controllers.
func (Client) SetBackgroundBright ¶
func (c Client) SetBackgroundBright(ctx context.Context, brightness int, effect Effect, duration time.Duration) error
SetBackgroundBright method isRaw used to change the brightness of a smart LED. "brightness" isRaw the target brightness. The type isRaw integer and ranges from 1 to 100. The brightness isRaw a percentage instead of a absolute value. 100 means maximum brightness while 1 means the minimum brightness.
func (Client) SetBackgroundColorTemperature ¶
func (c Client) SetBackgroundColorTemperature(ctx context.Context, value int, effect Effect, duration time.Duration) error
SetBackgroundColorTemperature method isRaw used to change the color temperature of a smart LED. "value" isRaw the target color temperature. The type isRaw integer and range isRaw 1700 ~ 6500 (k).
func (Client) SetBackgroundDefault ¶
SetBackgroundDefault method isRaw used to save current state of smart LED in persistent memory. So if user powers off and then powers on the smart LED again (hard power reset), the smart LED will show last saved state.
func (Client) SetBackgroundHSV ¶
func (c Client) SetBackgroundHSV(ctx context.Context, hue int, sat int, effect Effect, duration time.Duration) error
SetBackgroundHSV method isRaw used to change the color of a smart LED "hue" isRaw the target hue value, whose type isRaw integer. It should be expressed in decimal integer ranges from 0 to 359. "sat" isRaw the target saturation value whose type isRaw integer. It's range isRaw 0 to 100.
func (Client) SetBackgroundRGB ¶
func (c Client) SetBackgroundRGB(ctx context.Context, value int, effect Effect, duration time.Duration) error
SetBackgroundRGB method isRaw used to change the color of a smart LED "value" isRaw the target color, whose type isRaw integer. It should be expressed in decimal integer ranges from 0 to 16777215 (hex: 0xFFFFFF)
func (Client) SetBright ¶
func (c Client) SetBright(ctx context.Context, brightness int, effect Effect, duration time.Duration) error
SetBright method isRaw used to change the brightness of a smart LED. "brightness" isRaw the target brightness. The type isRaw integer and ranges from 1 to 100. The brightness isRaw a percentage instead of a absolute value. 100 means maximum brightness while 1 means the minimum brightness.
func (Client) SetColorTemperature ¶
func (c Client) SetColorTemperature(ctx context.Context, value int, effect Effect, duration time.Duration) error
SetColorTemperature method isRaw used to change the color temperature of a smart LED. "value" isRaw the target color temperature. The type isRaw integer and range isRaw 1700 ~ 6500 (k).
func (Client) SetDefault ¶
SetDefault method isRaw used to save current state of smart LED in persistent memory. So if user powers off and then powers on the smart LED again (hard power reset), the smart LED will show last saved state.
func (Client) SetHSV ¶
func (c Client) SetHSV(ctx context.Context, hue int, sat int, effect Effect, duration time.Duration) error
SetHSV method isRaw used to change the color of a smart LED "hue" isRaw the target hue value, whose type isRaw integer. It should be expressed in decimal integer ranges from 0 to 359. "sat" isRaw the target saturation value whose type isRaw integer. It's range isRaw 0 to 100.
func (Client) SetMusic ¶
SetMusic method is used to start or stop music mode on a device. Under music mode, no property will be reported and no message quota is checked. "musicHost" the IP address of the music server. "port" the TCP port music application is listening on.
func (Client) SetName ¶
SetName method isRaw used to name the device. The name will be stored on the device and reported in discovering response.
func (Client) StartBackgroundColorFlow ¶
func (c Client) StartBackgroundColorFlow(ctx context.Context, count int, action FlowAction, expressions []FlowExpression) error
StartBackgroundColorFlow method is used to start a color flow. Color flow is a series of smart LED visible state changing. It can be brightness changing, color changing or color temperature changing. `count` is the total number of visible state changing before color flow stopped. 0 means infinite loop on the state changing.
func (Client) StartColorFlow ¶
func (c Client) StartColorFlow(ctx context.Context, count int, action FlowAction, expressions []FlowExpression) error
StartColorFlow method is used to start a color flow. Color flow is a series of smart LED visible state changing. It can be brightness changing, color changing or color temperature changing. `count` is the total number of visible state changing before color flow stopped. 0 means infinite loop on the state changing.
func (Client) StopBackgroundColorFlow ¶
StopBackgroundColorFlow method is used to stop a running color flow.
func (Client) StopColorFlow ¶
StopColorFlow method is used to stop a running color flow.
type DiscoveryResultItem ¶
type DiscoveryResultItem struct { ID string Name string Location string Model string FirmwareVersion string Support []string Power bool }
DiscoveryResultItem contain information about result of discovery
type FlowAction ¶
type FlowAction int
FlowAction is enum of Flow Action
const ( // FlowActionRecover means smart LED recover to the state before the color flow started. FlowActionRecover FlowAction = 0 // FlowActionStay means smart LED stay at the state when the flow is stopped. FlowActionStay FlowAction = 1 // FlowActionTurnOff means turn off the smart LED after the flow is stopped. FlowActionTurnOff FlowAction = 2 )
Color flow action
type FlowExpression ¶
type FlowExpression struct { // Duration Gradual change time or sleep time. Minimum value 50 milliseconds. Duration time.Duration // Mode can be FlowModeColor, FlowColorTemperature, FlowSleep Mode FlowMode // Value is RGB value when mode is FlowModeColor, CT value when mode is FlowColorTemperature, Ignored when mode is FlowSleep. Value int // Brightness value, -1 or 1 ~ 100. Ignored when mode is FlowSleep. // When this value is -1, brightness in this tuple is ignored (only color or CT change takes effect). Brightness int }
FlowExpression is the expression of the state changing series.
type UnknownError ¶
type UnknownError string
UnknownError contain raw unknown error
func (UnknownError) Error ¶
func (e UnknownError) Error() string