strand

package
v0.0.0-...-167692a Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2013 License: MIT Imports: 6 Imported by: 4

README

go-hue/strand

The strand package allows you to map hue light ids to a physical socket position on a large strand of lights. You are then able to work the the hue.API via socket position rather than lightID.

Please see godoc.org for detailed API description.

Example

See the examples directory for a full program using this package. Below is an inline exerpt from that directory.

lightStrand := strand.NewLightStrand(len(lights), user)
lightStrand.MapUnmappedLights(func() string {
	fmt.Print("Enter the socket id of the red bulb: ")
	var socketId string
	fmt.Scanln(&socketId)
	return socketId
})

// Use lightStrand just like hue.API with socket id instead of light id
fmt.Println("Here are all the lights on the strand. Notice the ids match their location.")
lights, err = lightStrand.GetLights()
for _, light := range lights {
	fmt.Printf("Id: %s, Name: %s\n", light.Id, light.Name)
}

Documentation

Overview

Package with a LightStrand that implementes the hue.API interface. It maps light ids to socket locations on a strand of lights.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LightStrand

type LightStrand struct {
	API    hue.API
	Length int
	Lights *TwoWayMap
}

Structure that holds the mapping from socket id to light id. This implements the hue.API interface so it can be used as a drop in replacement.

func NewLightStrand

func NewLightStrand(length int, api hue.API) *LightStrand

Create a new light strand with the given length and hue.API to delegate to.

func NewLightStrandWithMap

func NewLightStrandWithMap(length int, api hue.API, initMap map[string]string) *LightStrand

Create a new light strand with the given length and hue.API to delegate to.

func (*LightStrand) ChangeLength

func (lg *LightStrand) ChangeLength(newLength int)

func (*LightStrand) CleanInvalidLightIds

func (lg *LightStrand) CleanInvalidLightIds() error

func (*LightStrand) GetLightAttributes

func (lg *LightStrand) GetLightAttributes(socketId string) (*hue.LightAttributes, error)

GetLightAttributes() is same as hue.User.GetLightAttributes() except all light ids are mapped to socket ids.

func (*LightStrand) GetLights

func (lg *LightStrand) GetLights() ([]hue.Light, error)

GetLights() is same as hue.User.GetLights() except all light ids are mapped to socket ids.

func (*LightStrand) GetMap

func (lg *LightStrand) GetMap() map[string]string

func (*LightStrand) GetNewLights

func (lg *LightStrand) GetNewLights() ([]hue.Light, time.Time, error)

GetNewLights() is same as hue.User.GetNewLights() except all light ids are mapped to socket ids.

func (*LightStrand) GetUnmappedLightIds

func (lg *LightStrand) GetUnmappedLightIds() ([]string, error)

Get a list of the unmapped light ids.

func (*LightStrand) IsMappedSocketId

func (lg *LightStrand) IsMappedSocketId(socketId string) bool

func (*LightStrand) MapUnmappedLights

func (lg *LightStrand) MapUnmappedLights(normalState, selectedState *hue.LightState,
	socketToLightFunc func(string) string) error

An interactive way of mapping all unmapped light bulbs on the hue bridge. This function does the following:

  1. Turn all lights normal state
  2. For each unmapped light a. Turn the bulb selectedState b. Call socketToLightFunc - The implementation should return the socket id for the unmapped light. If 'x' returned, skip mapping the bulb. c. Map the bulb to the socket id d. Turn the buld normal state and continue

This should be used to interactively prompt a person to map a light to a position in the strand.

func (*LightStrand) SearchForNewLights

func (lg *LightStrand) SearchForNewLights() error

SearchForNewLights() is same as hue.User.SearchForNewLights() except all light ids are mapped to socket ids.

func (*LightStrand) SetGroupState

func (lg *LightStrand) SetGroupState(groupId string, state *hue.LightState) error

SetGroupState() is same as hue.User.SetGroupState().

func (*LightStrand) SetLightName

func (lg *LightStrand) SetLightName(socketId string, name string) error

SetLightName() is same as hue.User.SetLightName() except all light ids are mapped to socket ids.

func (*LightStrand) SetLightState

func (lg *LightStrand) SetLightState(socketId string, state *hue.LightState) error

SetLightState() is same as hue.User.SetLightState() except all light ids are mapped to socket ids.

type TwoWayMap

type TwoWayMap struct {
	Normal   map[string]string
	Inverted map[string]string
}

func LoadTwoWayMap

func LoadTwoWayMap(initMap map[string]string) *TwoWayMap

func NewTwoWayMap

func NewTwoWayMap() *TwoWayMap

func (*TwoWayMap) DeleteWithKey

func (m *TwoWayMap) DeleteWithKey(key string) bool

func (*TwoWayMap) DeleteWithValue

func (m *TwoWayMap) DeleteWithValue(value string) bool

func (*TwoWayMap) GetKey

func (m *TwoWayMap) GetKey(value string) string

func (*TwoWayMap) GetKeys

func (m *TwoWayMap) GetKeys() []string

func (*TwoWayMap) GetValue

func (m *TwoWayMap) GetValue(key string) string

func (*TwoWayMap) GetValues

func (m *TwoWayMap) GetValues() []string

func (*TwoWayMap) Length

func (m *TwoWayMap) Length() int

func (*TwoWayMap) Set

func (m *TwoWayMap) Set(key, value string)

Directories

Path Synopsis
Examples of using strand
Examples of using strand

Jump to

Keyboard shortcuts

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