attr

package
v0.0.0-...-0896cb3 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2020 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DTString string
	DTString string = "string"

	// DTBool boolean
	DTBool string = "bool"

	// DTFloat32 float32
	DTFloat32 string = "float32"

	// DTInt32 int32
	DTInt32 string = "int32"
)
View Source
const (
	// UTPercentage percentage
	UTPercentage string = "percentage"

	// UTCelcius celcius
	UTCelcius string = "celcius"

	// UTFarenheit farenheit
	UTFarenheit string = "farenheit"

	// UTMillisecond millisecond
	UTMilliSecond string = "millisecond"
)
View Source
const (
	// ATOpenClose represents an OpenClose attribute
	ATOpenClose string = "OpenClose"

	// ATBrightness represents a Brightness attribute
	ATBrightness string = "Brightness"

	// ATOnOff represents an OnOff attribute
	ATOnOff string = "OnOff"

	// ATHSL represents a HSL attribute
	ATHSL string = "HSL"

	// ATOffset represents an Offset attribute
	ATOffset string = "Offset"

	// ATTemperature represents a temperature attribute
	ATTemperature string = "Temperature"

	// ATButtonState represents a button state e.g. pressed/released
	ATButtonState string = "BtnState"
)
View Source
const (
	// PermsReadOnly the attribute is a read-only value and cannot be set
	PermsReadOnly string = "r"

	// PermsReadWrite the attribute can be read and written to
	PermsReadWrite string = "rw"
)
View Source
const (
	ButtonStatePressed  int32 = 1
	ButtonStateReleased int32 = 2
)
View Source
const (
	// OpenCloseClosed indicates the OpenClose attribute is in a closed state
	OpenCloseClosed int32 = 1

	// OpenCloseOpen indicates the OpenClose attribute is in an open state
	OpenCloseOpen int32 = 2
)
View Source
const (
	// OnOffOff indicates the OnOff attribute is in the off state
	OnOffOff int32 = 1

	// OnOffOn indicates the OnOff attribute is in the on state
	OnOffOn int32 = 2
)

Variables

This section is empty.

Functions

func BoolP

func BoolP(val bool) *bool

BoolP returns a pointer to a bool containing the passed in value

func CloneAttrs

func CloneAttrs(attrs map[string]*Attribute) map[string]*Attribute

Clone copies the map and the contained attributes, returning a new copy that can be modified without chaning the original map or attributes

func FixJSON

func FixJSON(attrs map[string]*Attribute)

FixJSON massages the values back from float64 which is the type given to the values when being unmarshalled, to their correct data type

func Float32P

func Float32P(val float32) *float32

Float32P returns a pointer to a float32 containing the passed in value

func HSLConstruct

func HSLConstruct(hue, saturation, luminence int32) string

HSLConstruct takes in H,S,L values and converts then to a HSL string e.g. hsl(255, 44%, 32%)

func HSLDeconstruct

func HSLDeconstruct(val string) (int32, int32, int32, error)

HSLDeconstruct takes in a HSL string e.g. hsl(255, 44%, 32%) and returns the HSL components e.g. 255,44,32

func HSLStringToRGB

func HSLStringToRGB(hsl string) (byte, byte, byte, error)

HSLStringToRGB converts a HSL string e.g. hsl(100, 32%, 99%) to its corresponding RGB values

func Int32P

func Int32P(val int32) *int32

Int32P returns a pointer to an int32 containing the passed in value

func RGBToHSLString

func RGBToHSLString(r, g, b int) string

RGBToHSLString converts the R,G,B values to a HSL string

func StringP

func StringP(val string) *string

StringP returns a pointer to a string containing the passed in value

Types

type Attribute

type Attribute struct {
	// LocalID is an identifier that should be mutually exclusive between all attributes
	// assigned to a feature, it doesn't need to be globally unique. It can be used to
	// distinguish between the various atrtibutes of a feature
	LocalID string `json:"localId"`

	// Type is the concrete type of attribute such as OpenClose, Brightness, Hue etc
	Type string `json:"type"`

	// DataType is the underlying data type used in the attribute, such as int32, bool etc
	DataType string `json:"dataType"`

	// Unit is the data units used by the attribute e.g. percentage
	Unit string `json:"unit"`

	// Name is a user friendly string which can be shown in the UI
	Name string `json:"name"`

	// Description provides more details about the attribute that can be shown in the UI
	Description string `json:"description"`

	// Value is the value of the attribute
	Value interface{} `json:"value"`

	// Min is the minimum allowed value
	Min interface{} `json:"min"`

	// Max is the max allowed value
	Max interface{} `json:"max"`

	// Step is the step size
	Step interface{} `json:"step"`

	// Perms specifies if the user has read or readwrite permissions, either 'r' or 'rw'
	Perms string `json:"perms"`
}

Attribute represents a value with a specified data type and range.

func NewAttribute

func NewAttribute(localID, t, dataType string, val interface{}) *Attribute

NewAttribute creates and returns a new Attribute instance

func NewBool

func NewBool(localID, concrete string, val *bool) *Attribute

NewBool returns a new attribute initialized as a boolean data type

func NewBrightness

func NewBrightness(localID string, val *float32) *Attribute

NewBrightness returns a new Attribute initialized as a Brightness type

func NewButtonState

func NewButtonState(localID string, val *int32) *Attribute

func NewFloat32

func NewFloat32(localID, concrete string, val *float32) *Attribute

NewFloat32 returns a new attribute initialized as a float32 data type

func NewHSL

func NewHSL(localID string, val *string) *Attribute

NewHSL returns a new attribute instance initialized as a HSL attribute. For HSL attributes they are a string, expecting the format 'hsl(HUE, SAT%, LUM%) where HUE is a number between 0 and 360, and SAT/LUM are 0 to 255

func NewInt32

func NewInt32(localID, concrete string, val *int32) *Attribute

NewInt32 returns a new attribute initialized as an int32 data type

func NewOffset

func NewOffset(localID string, val *float32) *Attribute

NewOffset returns a new Attribute instance initialized as an Offset type

func NewOnOff

func NewOnOff(localID string, val *int32) *Attribute

NewOnOff returns a new Attribute instance initialized as an OnOff type

func NewOpenClose

func NewOpenClose(localID string, val *int32) *Attribute

NweOpenClose returns a new attribute instance, initialized as an OpenClose type

func NewString

func NewString(localID, concrete string, val *string) *Attribute

NewString returns a new attribute initialized as a string data type

func NewTemp

func NewTemp(localID string, val *int32) *Attribute

NewTemp returns a new Attribute instance initialized as a Temp type

func Only

func Only(attrs map[string]*Attribute) *Attribute

Only can be used if you only have one item in a map and want to access it

func (*Attribute) Clone

func (a *Attribute) Clone() *Attribute

Clone returns a cloned copy of the attribute

func (Attribute) String

func (a Attribute) String() string

Jump to

Keyboard shortcuts

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