Documentation
¶
Overview ¶
Package dynamic generates ops.HueTsk dynamically based on user input.
Index ¶
- Constants
- Variables
- type Choice
- type ChoiceList
- type Decoder
- type Encoder
- type Factory
- type FactoryEncoderDecoder
- type HueTask
- type HueTaskList
- type NamedParam
- type NamedParamList
- type Param
- type ParamSerializer
- func (p ParamSerializer) Encode() string
- func (p ParamSerializer) GetBrightness(key string) (result uint8, err error)
- func (p ParamSerializer) GetColor(key string) (result gohue.Color, err error)
- func (p ParamSerializer) GetInt(key string) (result int, err error)
- func (p ParamSerializer) SetBrightness(key string, value uint8) ParamSerializer
- func (p ParamSerializer) SetColor(key string, color gohue.Color) ParamSerializer
- func (p ParamSerializer) SetInt(key string, value int) ParamSerializer
- type PlainColorFactory
- func (p PlainColorFactory) Decode(s string) (action ops.HueAction, err error)
- func (p PlainColorFactory) Encode(action ops.HueAction) string
- func (p PlainColorFactory) New(values []interface{}) ops.HueAction
- func (p PlainColorFactory) NewExplicit(brightness uint8) (action ops.HueAction, paramsAsStrings []string)
- func (p PlainColorFactory) Params() NamedParamList
- type PlainFactory
- func (p PlainFactory) Decode(s string) (action ops.HueAction, err error)
- func (p PlainFactory) Encode(action ops.HueAction) string
- func (p PlainFactory) New(values []interface{}) ops.HueAction
- func (p PlainFactory) NewExplicit(color gohue.Color, colorString string, brightness uint8) (action ops.HueAction, paramsAsStrings []string)
- func (p PlainFactory) Params() NamedParamList
Constants ¶
const ( // Default name of color parameter ColorParamName = "Color" // Default name of brightness parameter BrightnessParamName = "Bri" )
Variables ¶
var ( // Reported if no value exists for a key in ParamSerializer ErrNoValue = errors.New("dynamic: No value.") )
Functions ¶
This section is empty.
Types ¶
type Choice ¶
type Choice struct { // What the user sees in the choice dialog Name string // The parameter value attached to this choice Value interface{} }
Choice represents a single choice in a choice dialog.
type Factory ¶
type Factory interface { // Params returns the parameters for which user must supply values. Params() NamedParamList // New creates the ops.HueAction using the values that the user supplied. // values will have the same length as what Params returns. New(values []interface{}) ops.HueAction }
Factory generates an ops.HueAction from a list of user inputs. Specific implementations also provide a NewExplicit mehod that takes explicitly typed parameters and returns a new ops.HueAction and the parameters as strings.
type FactoryEncoderDecoder ¶
func Constant ¶
func Constant(a ops.HueAction) FactoryEncoderDecoder
Constant returns a Factory that provides no user inputs and always generates the supplied ops.HueAction.
type HueTask ¶
type HueTask struct { // Unique Id. Id int // e.g "Fixed color and brightness" Description string // Helps to generate the ops.HueTask Factory }
HueTask represents a task that needs user input to generate a real ops.HueTask. These instances must be treated as immutable.
func FromOpsHueTask ¶
FromOpsHueTask is a convenience routine that converts an ops.HueTask into a HueTask.
func (*HueTask) FromExplicit ¶
FromExplicit creates an ops.HueTask from this instance. Callers must call NewExplcit on this instance's Factory field and pass the return values to this method.
func (*HueTask) FromUrlValues ¶
FromUrlValues generates an ops.HueTask based on url values from an html form. prefix is the prefix of url values for example if prefix is "p" then user supplied inputs would be under "p0" "p1" "p2" etc; values are the url values. FromUrlValues includes the description of this instance along with a description of each user supplied parameter in the returned ops.HueTask
type HueTaskList ¶
type HueTaskList []*HueTask
HueTaskList represents an immutable list of hue tasks.
func FromOpsHueTaskList ¶
func FromOpsHueTaskList(l ops.HueTaskList) HueTaskList
FromOpsHueTaskList is a convenience routine that converts an ops.HueTaskList into a HueTaskList.
func (HueTaskList) SortByDescriptionIgnoreCase ¶
func (l HueTaskList) SortByDescriptionIgnoreCase() HueTaskList
SortByDescriptionIgnoreCase returns a new HueTaskList with the same HueTasks as this instance only sorted by description in ascending order ignoring case.
func (HueTaskList) ToMap ¶
func (l HueTaskList) ToMap() map[int]*HueTask
ToMap returns this HueTaskList as a map keyed by Id
type NamedParam ¶
type NamedParam struct { // The name which appears on user input forms and in description of // generated ops.HueTask. Name string Param }
NamedParam represents a Param that is named.
type NamedParamList ¶
type NamedParamList []NamedParam
NamedParamList represents an immutable list of NamedParam
type Param ¶
type Param interface { // Selection returns the options to appear in the choice dialog. The // first option is always similar to "Select one." If the value of this // parameter is to be inputted in free form, returns nil. Selection() []string // MaxCharCount returns the maximum character count of this parameter. // It is used as a hint to determine how big to make the input text field // for the user. MaxCharCount() int // Convert converts the string the user entered or the ordinal value of // the selected option to the actual value of this parameter. The first // returned value is the actual value of the parameter; the second // returned value is a string representation that is used in the // description of the generated ops.HueTask Convert(s string) (interface{}, string) }
Interface Param represents a single parameter for generating a ops.HueTask.
func Brightness ¶
func Brightness() Param
Brightness is a convenience rourtine that returns an integer parameter representing brightness which is (0-255) with default of 255 and size of 3 chars.
func ColorPicker ¶
ColorPicker returns a Param that lets the user choose a color from a predefined list. defaultColor is the default color if user does not choose; defaultName is the name to show for the default color.
func Int ¶
Int returns an Param that is presented as a text field and has an integer value. minValue and maxValue the minimum and maximum value inclusive of the integer; defaultValue is the default value if user doesn't enter a number or enters one that is out of range; maxChars is the size of the text field.
func Picker ¶
func Picker( choices ChoiceList, defaultValue interface{}, defaultName string) Param
Picker returns a Param that is presented as a choice dialog. choices are the choices user will see exluding the "Select one" choice; defaultValue is the value of returned Param if user does not select a choice; defaultName is the description of the default value to use in generated ops.HueTask descriptions.
type ParamSerializer ¶
ParamSerializer encodes parameters for hue tasks as a string.
func NewParamSerializer ¶
func NewParamSerializer(s string) (ParamSerializer, error)
NewParamSerializer decodes a string back into parameters. Caller can safely modify the returned value.
func (ParamSerializer) Encode ¶
func (p ParamSerializer) Encode() string
Encode encodes stored parameters as a single string.
func (ParamSerializer) GetBrightness ¶
func (p ParamSerializer) GetBrightness(key string) (result uint8, err error)
GetBrightness returns the stored brightness. If no value stored under key then returns ErrNoValue. May return a different error if the value stored is corrupted or cannot be converted to a brightness.
func (ParamSerializer) GetColor ¶
func (p ParamSerializer) GetColor(key string) (result gohue.Color, err error)
GetColor returns the stored Color value. If no value stored under key then returns ErrNoValue. May return a different error if the value stored is corrupted or cannot be converted to a Color.
func (ParamSerializer) GetInt ¶
func (p ParamSerializer) GetInt(key string) (result int, err error)
GetInt returns the stored int value. If no value stored under key then returns ErrNoValue. May return a different error if the value stored is corrupted or cannot be converted to an int.
func (ParamSerializer) SetBrightness ¶
func (p ParamSerializer) SetBrightness(key string, value uint8) ParamSerializer
SetBrightness stores a brightness value and returns this instance for chaining.
func (ParamSerializer) SetColor ¶
func (p ParamSerializer) SetColor(key string, color gohue.Color) ParamSerializer
SetColor stores an color value and returns this instance for chaining.
func (ParamSerializer) SetInt ¶
func (p ParamSerializer) SetInt(key string, value int) ParamSerializer
SetInt stores an int value and returns this instance for chaining.
type PlainColorFactory ¶
PlainColorFactory implements Factory and lets user provide brightness only then generates an ops.HueAction that makes lights the user supplied brightness with given color. Default is full brightness.
func (PlainColorFactory) Decode ¶
func (p PlainColorFactory) Decode(s string) (action ops.HueAction, err error)
Decode decodes a string that Encode produced back into a HueAction.
func (PlainColorFactory) Encode ¶
func (p PlainColorFactory) Encode(action ops.HueAction) string
Encode encodes a HueAction that this instance created as a string
func (PlainColorFactory) New ¶
func (p PlainColorFactory) New(values []interface{}) ops.HueAction
func (PlainColorFactory) NewExplicit ¶
func (p PlainColorFactory) NewExplicit( brightness uint8) (action ops.HueAction, paramsAsStrings []string)
brightness is the brightness of the light.
func (PlainColorFactory) Params ¶
func (p PlainColorFactory) Params() NamedParamList
type PlainFactory ¶
type PlainFactory struct {
// contains filtered or unexported fields
}
PlainFactory implements Factory and lets user provide brightness and color and then generates an ops.HueAction that makes lights the user supplied color and brightness. The zero value uses the color picker that the ColorPicker() function returns with a default color of white along with full brightness.
func NewPlainFactory ¶
func NewPlainFactory(colorPicker Param) PlainFactory
NewPlainFactory creates a PlainFactory that uses the specified color picker. Client uses the Picker function to provide a color picker.
func (PlainFactory) Decode ¶
func (p PlainFactory) Decode(s string) (action ops.HueAction, err error)
Decode decodes a string that Encode produced back into a HueAction.
func (PlainFactory) Encode ¶
func (p PlainFactory) Encode(action ops.HueAction) string
Encode encodes a HueAction that this instance created as a string
func (PlainFactory) New ¶
func (p PlainFactory) New(values []interface{}) ops.HueAction
func (PlainFactory) NewExplicit ¶
func (p PlainFactory) NewExplicit( color gohue.Color, colorString string, brightness uint8) (action ops.HueAction, paramsAsStrings []string)
color is the light color; colorString is the string representation of the light color; brightness is the brightness of the light.
func (PlainFactory) Params ¶
func (p PlainFactory) Params() NamedParamList