light

package
v0.0.0-...-1392edb Latest Latest
Warning

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

Go to latest
Published: May 11, 2019 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ChannelRed   = "red"
	ChannelGreen = "green"
	ChannelBlue  = "blue"
)

Holds strings for the different channel types

View Source
const (
	TypeHue     = "hue"
	TypeDMX     = "DMX"
	TypeGeneric = "generic"
)

constants for the different types of lights

Variables

This section is empty.

Functions

func DebugString

func DebugString(l Light) string

DebugString gives info

func SendDMXWorker

func SendDMXWorker(ctx context.Context, client OLAClient, tick time.Duration, manager Manager, wg *sync.WaitGroup) error

SendDMXWorker sends OLA the current dmxState across all universes

Types

type DMXLight

type DMXLight struct {
	Name         string `json:"name" yaml:"name"`
	StartAddress int    `json:"start_address" yaml:"start_address"`
	Universe     int    `json:"universe" yaml:"universe"`
	Profile      string `json:"profile" yaml:"profile"`
}

DMXLight is a DMX light

func (*DMXLight) GetID

func (d *DMXLight) GetID() string

GetID returns the a unique id: dmx address info + profile mame

func (*DMXLight) GetName

func (d *DMXLight) GetName() string

GetName returns the light's name.

func (*DMXLight) GetType

func (d *DMXLight) GetType() string

GetType returns the type of light.

func (*DMXLight) SetState

func (d *DMXLight) SetState(ctx context.Context, m Manager, target TargetState)

SetState updates the light's state. TODO: other properties? on/off?

type DMXState

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

DMXState holds the DMX512 values for each channel

type DiscoveredHues

type DiscoveredHues struct {
	AllLights []lights.Light `json:"all_lights"`
	ByName    map[string]int `json:"by_name"`
}

DiscoveredHues is for wrapping hue info

type GenericLight

type GenericLight struct {
	Name string `json:"name" yaml:"name"`
}

GenericLight is for testing

func (*GenericLight) GetID

func (gl *GenericLight) GetID() string

GetID returns a fake light id

func (*GenericLight) GetName

func (gl *GenericLight) GetName() string

GetName returns the light's name.

func (*GenericLight) GetType

func (gl *GenericLight) GetType() string

GetType returns the type of light.

func (*GenericLight) SetState

func (gl *GenericLight) SetState(ctx context.Context, m Manager, target TargetState)

SetState updates the light's state.

type HueConnection

type HueConnection interface {
	SetLightState(lightID int, state lights.State) ([]hue.ApiResponse, error)
	GetAllLights() ([]lights.Light, error)
}

HueConnection represents a connection to a hue bridge

type HueLight

type HueLight struct {
	HueID int    `json:"hue_id" yaml:"hue_id"`
	Name  string `json:"name" yaml:"name"`
	// contains filtered or unexported fields
}

HueLight is a philips hue light.

func (*HueLight) GetID

func (hl *HueLight) GetID() string

GetID returns the type of light.

func (*HueLight) GetName

func (hl *HueLight) GetName() string

GetName returns the light's name.

func (*HueLight) GetType

func (hl *HueLight) GetType() string

GetType returns the type of light.

func (*HueLight) SetState

func (hl *HueLight) SetState(ctx context.Context, m Manager, s TargetState)

SetState updates the Hue's state.

type Light

type Light interface {
	GetName() string
	GetType() string
	GetID() string
	SetState(context.Context, Manager, TargetState)
}

Light is a light

type Manager

type Manager interface {
	SetState(name string, new State)
	GetState(name string) *State
	GetLightNames() []string
	GetAllStates() *StateMap
	GetByName(name string) Light
	GetLightsByName() NameMap
	GetDMXState() *DMXState
	SetDMXState(ctx context.Context, ops ...dmxOperation) error
	GetHueConnection() HueConnection
	GetDiscoveredHues() DiscoveredHues
}

Manager is the light manager interface

func NewManager

func NewManager(ctx context.Context, h HueConnection) (Manager, error)

NewManager parses light config

type MockHueConnection

type MockHueConnection struct {
	mock.Mock
}

MockHueConnection is an autogenerated mock type for the HueConnection type

func (*MockHueConnection) GetAllLights

func (_m *MockHueConnection) GetAllLights() ([]lights.Light, error)

GetAllLights provides a mock function with given fields:

func (*MockHueConnection) SetLightState

func (_m *MockHueConnection) SetLightState(lightID int, state lights.State) ([]hue.ApiResponse, error)

SetLightState provides a mock function with given fields: lightID, state

type MockLight

type MockLight struct {
	mock.Mock
}

MockLight is an autogenerated mock type for the Light type

func (*MockLight) GetID

func (_m *MockLight) GetID() string

GetID provides a mock function with given fields:

func (*MockLight) GetName

func (_m *MockLight) GetName() string

GetName provides a mock function with given fields:

func (*MockLight) GetType

func (_m *MockLight) GetType() string

GetType provides a mock function with given fields:

func (*MockLight) SetState

func (_m *MockLight) SetState(_a0 context.Context, _a1 Manager, _a2 TargetState)

SetState provides a mock function with given fields: _a0, _a1, _a2

type MockManager

type MockManager struct {
	mock.Mock
}

MockManager is an autogenerated mock type for the Manager type

func (*MockManager) GetAllStates

func (_m *MockManager) GetAllStates() *StateMap

GetAllStates provides a mock function with given fields:

func (*MockManager) GetByName

func (_m *MockManager) GetByName(name string) Light

GetByName provides a mock function with given fields: name

func (*MockManager) GetDMXState

func (_m *MockManager) GetDMXState() *DMXState

GetDMXState provides a mock function with given fields:

func (*MockManager) GetDiscoveredHues

func (_m *MockManager) GetDiscoveredHues() DiscoveredHues

GetDiscoveredHues provides a mock function with given fields:

func (*MockManager) GetHueConnection

func (_m *MockManager) GetHueConnection() HueConnection

GetHueConnection provides a mock function with given fields:

func (*MockManager) GetLightNames

func (_m *MockManager) GetLightNames() []string

GetLightNames provides a mock function with given fields:

func (*MockManager) GetLightsByName

func (_m *MockManager) GetLightsByName() NameMap

GetLightsByName provides a mock function with given fields:

func (*MockManager) GetState

func (_m *MockManager) GetState(name string) *State

GetState provides a mock function with given fields: name

func (*MockManager) SetDMXState

func (_m *MockManager) SetDMXState(ctx context.Context, ops ...dmxOperation) error

SetDMXState provides a mock function with given fields: ctx, ops

func (*MockManager) SetState

func (_m *MockManager) SetState(name string, new State)

SetState provides a mock function with given fields: name, new

type MockOLAClient

type MockOLAClient struct {
	mock.Mock
}

MockOLAClient is an autogenerated mock type for the OLAClient type

func (*MockOLAClient) Close

func (_m *MockOLAClient) Close()

Close provides a mock function with given fields:

func (*MockOLAClient) SendDmx

func (_m *MockOLAClient) SendDmx(universe int, values []byte) (bool, error)

SendDmx provides a mock function with given fields: universe, values

type NameMap

type NameMap map[string]Light

NameMap holds string-keyed Lights

type OLAClient

type OLAClient interface {
	SendDmx(universe int, values []byte) (status bool, err error)
	Close()
}

OLAClient is the interface for communicating with ola

type State

type State struct {
	RGB color.RGB `json:"rgb"` //RGB color
}

State represents the current state of the light

type StateManager

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

StateManager holds the state of lights

func (*StateManager) GetAllStates

func (m *StateManager) GetAllStates() *StateMap

GetAllStates will get the current state for all lights

func (*StateManager) GetByName

func (m *StateManager) GetByName(name string) Light

GetByName looks up a light by name

func (*StateManager) GetDMXState

func (m *StateManager) GetDMXState() *DMXState

GetDMXState returns the current dmx state

func (*StateManager) GetDiscoveredHues

func (m *StateManager) GetDiscoveredHues() DiscoveredHues

GetDiscoveredHues finds all the hues on the network

func (*StateManager) GetHueConnection

func (m *StateManager) GetHueConnection() HueConnection

GetHueConnection returns the hue connection object

func (*StateManager) GetLightNames

func (m *StateManager) GetLightNames() []string

GetLightNames returns all the light names

func (*StateManager) GetLightsByName

func (m *StateManager) GetLightsByName() NameMap

GetLightsByName returns lights keyed by name

func (*StateManager) GetState

func (m *StateManager) GetState(name string) *State

GetState will get the current state for a light

func (*StateManager) SetDMXState

func (m *StateManager) SetDMXState(ctx context.Context, ops ...dmxOperation) error

SetDMXState updates the dmxstate

func (*StateManager) SetState

func (m *StateManager) SetState(name string, new State)

SetState will set the current state for a light

type StateMap

type StateMap map[string]State

StateMap holds Global light state

type TargetState

type TargetState struct {
	// On   bool
	State
	Duration time.Duration `json:"duration"` //time to transition to the new state
}

TargetState represents the state of a light, is source of truth

func (*TargetState) String

func (t *TargetState) String() string

func (*TargetState) ToState

func (t *TargetState) ToState() State

ToState converts a TargetState to a State

Jump to

Keyboard shortcuts

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