engine

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2021 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrEngineInvalidSpecial = errors.New("Engine: invalid special action")
View Source
var ErrEngineMissingBridge = errors.New("Engine: missing index")
View Source
var ErrEngineMissingIndex = errors.New("Engine: missing index")
View Source
var ErrEngineNoConnect = errors.New("Engine: No Connect function")
View Source
var ErrIndexNilBridge = errors.New("NewIndex: bridge is nil")
View Source
var ErrInvalidAction = errors.New("action.Do: Invalid action")

Functions

This section is empty.

Types

type Action

type Action struct {
	Group *HueGroup `json:"group,omitempty"`
	Light *HueLight `json:"light,omitempty"`

	Scene *HueScene `json:"scene,omitempty"`
	OnOff BoolOnOff `json:"onoff,omitempty"`

	Special *HueSpecial `json:"special,omitempty"`
}

Action represents single action

func (Action) Do

func (action Action) Do(bridge *huego.Bridge) error

func (Action) String

func (res Action) String() string

String stringifies the ex

type BoolOnOff

type BoolOnOff string

BoolOnOff represents turning a scene on or off

const (
	BoolAny BoolOnOff = ""
	BoolOn  BoolOnOff = "on"
	BoolOff BoolOnOff = "off"
)

type Engine

type Engine struct {

	// Connect is a user-defined function to connect to a bridge
	Connect func() (bridge *huego.Bridge, err error)
	// contains filtered or unexported fields
}

Engine coordinates an engine and index regeneration

func NewEngine

func NewEngine(bridge *huego.Bridge) *Engine

func (*Engine) Do

func (engine *Engine) Do(action Action) error

Do performs the provided action

func (engine *Engine) Link() error

Link links the engine

func (*Engine) Query

func (engine *Engine) Query(input string) ([]Action, []MatchScore, []Score, error)

Query queries the engine

func (*Engine) RefreshIndex

func (engine *Engine) RefreshIndex() (err error)

func (*Engine) SetBridge

func (engine *Engine) SetBridge(bridge *huego.Bridge)

type HueGroup

type HueGroup struct {
	ID   int         `json:"id"`
	Data huego.Group `json:"data"`
}

HueGroup represents a hue group

func NewHueGroup

func NewHueGroup(group huego.Group) *HueGroup

NewHueGroup creates a new hue group.

Any internal call to this function should take care to place any unused instance back into groupPool.

func (*HueGroup) Refresh

func (group *HueGroup) Refresh(bridge *huego.Bridge) error

Refresh reloads data about this group from a bridge

func (*HueGroup) UnmarshalJSON

func (group *HueGroup) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler.

For safety reasons this only unmarshals the ID from the data source. Any call should be followed by a call to Refresh.

type HueLight

type HueLight struct {
	ID   int         `json:"id"`
	Data huego.Light `json:"data"`
}

HueLight represents a hue light

func NewHueLight

func NewHueLight(light huego.Light) *HueLight

NewHueLight creates a new hue light.

Any internal call to this function should take care to place any unused instance back into lightPool.

func (*HueLight) Refresh

func (light *HueLight) Refresh(bridge *huego.Bridge) error

Refresh reloads data about this light from a bridge

func (*HueLight) UnmarshalJSON

func (light *HueLight) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler

For safety reasons this only unmarshals the ID from the data source. Any call should be followed by a call to Refresh.

type HueScene

type HueScene struct {
	ID   string      `json:"id"`
	Data huego.Scene `json:"data"`
}

HueScene represents a hue scene

func NewHueScene

func NewHueScene(scene huego.Scene) *HueScene

NewHueScene creates a new hue scene.

Any internal call to this function should take care to place any unused instance back into scenePool.

func (*HueScene) Refresh

func (scene *HueScene) Refresh(bridge *huego.Bridge) error

Refresh reloads data about this scene from a bridge

func (*HueScene) UnmarshalJSON

func (scene *HueScene) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler.

For safety reasons this only unmarshals the ID from the data source. Any call should be followed by a call to Refresh.

type HueSpecial

type HueSpecial struct {
	ID   string `json:"id"`
	Data struct {
		Message string `json:"message"`
	} `json:"data"`
}

HueSpecial represents a special action that can be returned by the webserver

type Index

type Index struct {
	Groups []huego.Group
	Lights []huego.Light
	Scenes []huego.Scene
}

Index provides cached data contained in a hue bridge

func NewIndex

func NewIndex(bridge *huego.Bridge) (*Index, error)

NewIndex creates an index of a given bridge

func (Index) Query

func (index Index) Query(queries []Query) (actions []Action, matchScores []MatchScore, scores []Score)

Query queries an index for a set of queries It returns a list of matching actions

func (Index) QueryString

func (index Index) QueryString(input string) ([]Action, []MatchScore, []Score)

QueryString sends a string query to this index

type MatchScore

type MatchScore [][]float64

MatchScore represents the score of a single action

func (MatchScore) AsFloat64

func (m MatchScore) AsFloat64() (total float64)

AsFloat64 returns the score of this action as a single float64

type Query

type Query struct {
	// Name is the name of an action to pattern match against
	Name string
	// Action is the name of an action (scene or on/off) to pattern match against
	Action string
}

Query describes a query for the huelio system.

func ParseQuery

func ParseQuery(value string) (passes []Query)

ParseQuery generates a set of queries from an input string

func (Query) MatchGroup

func (query Query) MatchGroup(room *HueGroup) float64

MatchGroup scores the object stored in this room against a group.

func (Query) MatchLight

func (query Query) MatchLight(light *HueLight) float64

MatchLight scores the object stored in this room against a light.

func (Query) MatchOnOff

func (query Query) MatchOnOff(onoff BoolOnOff) float64

MatchOnOff scores the action stored in this scene against an on/off action.

func (Query) MatchScene

func (query Query) MatchScene(scene *HueScene) float64

MatchLights scores the object stored in this room against a scene action.

func (Query) String

func (q Query) String() string

type Results

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

Ranking represents a set of results

func (*Results) Add

func (r *Results) Add(action Action, matchScore MatchScore)

Add adds a new result to this result set

func (*Results) Len

func (r *Results) Len() int

func (*Results) Less

func (r *Results) Less(i, j int) bool

func (*Results) Reset

func (r *Results) Reset(cap int)

Reset resets this ranking slice for the provided cap

func (*Results) Results

func (r *Results) Results() ([]Action, []MatchScore, []Score)

Actions returns the sorted version of results

func (*Results) Swap

func (r *Results) Swap(i, j int)

type Score

type Score [4]float64

Score represents the score of a single result

func (Score) Less

func (s Score) Less(other Score) bool

Less checks if s < other using lexiographic ordering

type ScoreQueries

type ScoreQueries struct {
	Queries []Query
	Scores  MatchScore
}

ScoreQueries represents a buffer of queries to be scored and filtered

func (*ScoreQueries) Score

func (sq *ScoreQueries) Score(scoring func(q Query) float64) bool

Score applies scoring to the current list of queries. It modifies the scoring in place.

When score < 0, considers the scores as non-matching

func (ScoreQueries) ScoreFinal

func (sq ScoreQueries) ScoreFinal(scoring func(q Query) float64) (scores MatchScore, queries []Query)

func (*ScoreQueries) Use

func (sq *ScoreQueries) Use(Queries []Query)

Jump to

Keyboard shortcuts

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