chromaticity

package
v0.0.0-...-33c2882 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2019 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Ex_Color_Light    = "Extended color light"
	Dimmable_Light    = "Dimmable light"
	On_Off_Plug_Light = "On/Off plug-in unit"
)

Light Types

View Source
const (
	JSONError     = 2
	ResourceError = 3
	ValueError    = 7
	ROGroupError  = 305
)

Error Types

View Source
const LightGroup string = "LightGroup"
View Source
const Lightsource string = "Lightsource"
View Source
const Luminaire string = "Luminaire"

Variables

View Source
var ErrorDescriptions map[int]string = map[int]string{
	JSONError:     "body contains invalid JSON",
	ResourceError: "resource, {{.resource}}, not available",
	ValueError:    "invalid value, {{.value}}, for parameter, {{.parameter}}",
	ROGroupError:  "It is not allowed to update or delete group of this type",
}
View Source
var ErrorStatusCodes map[int]int = map[int]int{
	JSONError:     400,
	ResourceError: 404,
	ValueError:    400,
	ROGroupError:  403,
}

Offical API returns 200 on error?

Functions

func BlendColor

func BlendColor(e *EffectRoutine, light *Light, last_color colorful.Color)

func HclLoop

func HclLoop(done chan bool, light *Light)

A hcl based rainbow fade

func HsvLoop

func HsvLoop(done chan bool, light *Light)

A hsv based rainbow fade

func RainbowLoop

func RainbowLoop(done chan bool, light *Light)

A hsv based rainbow fade

func SendState

func SendState(l *Light, last_color colorful.Color)

func UpdateColorState

func UpdateColorState(dest *ColorState, req *restful.Request)

func WrapLight

func WrapLight(l *Light) interface{}

func WrapLights

func WrapLights(l map[string]*Light) map[string]interface{}

func WriteDELETESuccess

func WriteDELETESuccess(response *restful.Response, ids []string)

func WriteError

func WriteError(response *restful.Response, errorType int, addr string, vars *map[string]string)

func WritePOSTSuccess

func WritePOSTSuccess(response *restful.Response, ids []string)

func WritePUTSuccess

func WritePUTSuccess(response *restful.Response, fields map[string]interface{})

func WritePUTSuccessExplicit

func WritePUTSuccessExplicit(response *restful.Response, fields map[string]interface{})

Unfortunately the Hue API seems to be inconsistant in response format

Types

type ColorState

type ColorState struct {
	LightID        string  `json:"-" gorm:"primary_key"`
	Alert          string  `json:"alert"`
	Bri            uint8   `json:"bri"`
	BriInc         int16   `json:"bri_inc,omitempty"`
	Ct             uint16  `json:"ct"`
	Effect         string  `json:"effect"`
	EffectSpread   float64 `json:"effectspread,omitempty"`
	Hue            uint16  `json:"hue"`
	On             bool    `json:"on"`
	TransitionTime uint16  `json:"transitiontime,omitempty"`
	Sat            uint8   `json:"sat"`
	Xy             Xy      `json:"xy" gorm:"embedded"`
	Colormode      string  `json:"colormode"`
	*EffectRoutine `gorm:"-"`
}

func (*ColorState) GetColor

func (state *ColorState) GetColor() (c colorful.Color)

type Command

type Command struct {
	Address string          `json:"address"`
	Body    json.RawMessage `json:"body"`
	Method  string          `json:"method"`
}

type Config

type Config struct {
	Schedules map[string]Schedule `json: "schedules"`
}

type ConfigInfo

type ConfigInfo struct {
	Name         string               `json:"name"`
	Mac          string               `json:"mac"`
	Dhcp         bool                 `json:"dhcp"`
	Ipaddress    string               `json:"ipaddress"`
	Netmask      string               `json:"netmask"`
	Gateway      string               `json:"gateway"`
	Proxyaddress string               `json:"proxyaddress"`
	Proxyport    int                  `json:"proxyport"`
	UTC          string               `json:"UTC"`
	Whitelist    map[string]Developer `json:"whitelist"`
	Swversion    string               `json:"swversion"`
	//Apiversion     string               `json:"apiversion"` // 1.2.1 +
	Swupdate       UpdateInfo `json:"swupdate"`
	Linkbutton     bool       `json:"linkbutton"`
	Portalservices bool       `json:"portalservices"`
}

func NewConfigInfo

func NewConfigInfo() *ConfigInfo

type Developer

type Developer struct {
	LastUseDate string `json:"last use date"`
	CreateDate  string `json:"create date"`
	Name        string `json:"name"`
}

type EffectRoutine

type EffectRoutine struct {
	Signal chan bool `json:"-"`
	Done   bool      `json:"-"`
}

type ErrorResponse

type ErrorResponse struct {
	Type        int    `json:"type"`
	Address     string `json:"address"`
	Description string `json:"description"`
}

type Group

type Group struct {
	GroupInfo
	State    *ColorState `json:"action"`
	ReadOnly bool        `json:"-"`
	Lights   []*Light    `json:"-"`
}

func NewGroup

func NewGroup(l *LightResource, i GroupInfo, s *ColorState, ro bool) *Group

func (Group) GetInfo

func (g Group) GetInfo() *LightInfo

func (Group) GetNumPixels

func (g Group) GetNumPixels() uint16

func (Group) GetState

func (g Group) GetState() *State

func (Group) GetType

func (g Group) GetType() string

func (Group) SetColor

func (g Group) SetColor(c colorful.Color)

func (Group) SetColors

func (g Group) SetColors(c []colorful.Color)

type GroupInfo

type GroupInfo struct {
	LightIDs  []string `json:"lights"`
	Name      string   `json:"name"`
	GroupType string   `json:"type"`
}

type Light

type Light interface {
	SetColor(c colorful.Color)
	SetColors(c []colorful.Color)
	GetInfo() (i *LightInfo)
	GetState() (s *State)
	GetNumPixels() (p uint16)
	GetType() string
}

type LightInfo

type LightInfo struct {
	// Api def limits these strings to certain length, FIXME if doesn't work
	Type      string `json:"type,omitempty"`
	Name      string `json:"name,omitempty"`
	ModelId   string `json:"modelid,omitempty"`
	SwVersion string `json:"swversion,omitempty"`
	// Api def claims unimplemented atm, FIXME if doesn't work
	PointSymbol map[string]string `json:"pointsymbol"`
}

type LightResource

type LightResource struct {
	Lights      map[string]*Light    `json:"lights"`
	Groups      map[string]*Group    `json:"groups"`
	Schedules   map[string]*Schedule `json:"schedules"`
	*ConfigInfo `json:"config"`
	DB          *gorm.DB `json:"-"`
}

func (*LightResource) ImportSchedules

func (l *LightResource) ImportSchedules(configfile string)

func (LightResource) PersistState

func (l LightResource) PersistState(light *Light, id string)

func (LightResource) RegisterConfigApi

func (l LightResource) RegisterConfigApi(container *restful.Container)

func (LightResource) RegisterGroupsApi

func (l LightResource) RegisterGroupsApi(container *restful.Container)

func (LightResource) RegisterLightsApi

func (l LightResource) RegisterLightsApi(container *restful.Container)

func (LightResource) RegisterSchedulesApi

func (l LightResource) RegisterSchedulesApi(container *restful.Container)

func (LightResource) RestoreState

func (l LightResource) RestoreState()

type LuxLight

type LuxLight struct {
	State *LuxState `json:"state"`
	*LightInfo
}

type LuxState

type LuxState struct {
	*State
	Ct        bool `json:"ct,omitempty"`
	Hue       bool `json:"hue,omitempty"`
	Sat       bool `json:"sat,omitempty"`
	Xy        bool `json:"xy,omitempty"`
	Colormode bool `json:"colormode,omitempty"`
}

Omit color fields for white only lights

type Schedule

type Schedule struct {
	Name        string               `json:"name"`
	Description string               `json:"description"`
	Command     Command              `json:"command"`
	LocalTime   string               `json:"localtime"`
	Time        string               `json:"time"`
	Created     string               `json:"created"`
	Status      string               `json:"status"`
	Autodelete  bool                 `json:"autodelete"`
	Timer       *time.Timer          `json:"-"`
	Schedules   map[string]*Schedule `json:"-"`
	ID          string               `json:"-"`
}

type State

type State struct {
	Reachable bool `json:"reachable"`
	*ColorState
}

func NewState

func NewState() *State

func (*State) SetColor

func (state *State) SetColor(c colorful.Color)

type SuccessResponse

type SuccessResponse struct {
	Field interface{} `json:"success"`
}

type UpdateInfo

type UpdateInfo struct {
	Updatestate int    `json:"updatestate"`
	Url         string `json:"url"`
	Text        string `json:"text"`
	Notify      bool   `json:"notify"`
}

type UserInfo

type UserInfo struct {
	DeviceType string `json:"devicetype"`
	UserName   string `json:"username"`
}

type Xy

type Xy struct {
	X float64
	Y float64
}

func (Xy) MarshalJSON

func (xy Xy) MarshalJSON() ([]byte, error)

func (*Xy) UnmarshalJSON

func (xy *Xy) UnmarshalJSON(data []byte) error

Jump to

Keyboard shortcuts

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