hue

package module
v0.0.0-...-368729d Latest Latest
Warning

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

Go to latest
Published: May 14, 2020 License: GPL-3.0 Imports: 10 Imported by: 0

README

Go Report Card

go-hue-interface

Connect to a hue bridge

In your code create a hue bridge instance

    func main() {
        // ...
        // create a bridge config
        bridgeConf := &Config{
            Username:         "YOUR_DEVICE_USERNAME", // check below for detailed instructions
            BridgeAddr:       "YOUR_BRIDGE_IP_ADDR", // check below where to find the ip address of the hue
            BridgeAddrScheme: "http",
	    }

        // create bridge
        bridge := NewBridge(config)

        // now do stuff with bridge
        // get ligts as a map of lights over ids
        lights, errLights := bridge.GetLights()
        if errLights {
            fmt.Println("Failed to get lights")
        }

        // Turn all lights on
        for id, _ := range lights {
            bridge.ToggleLight(id, true)
        }
    }

Documentation

Index

Constants

View Source
const LightsEndpoint = "/lights"

LightsEndpoint for the lights

View Source
const TimeFormat = "2006-01-02T15:04:05"

Variables

This section is empty.

Functions

This section is empty.

Types

type AppData

type AppData struct {
	Version int    `json:"version,omitempty"`
	Data    string `json:"data,omitempty"`
}

type BaseScene

type BaseScene struct {
	Name        string   `json:"name,omitempty"`
	Type        string   `json:"type,omitempty"`
	Group       string   `json:"group,omitempty"`
	Lights      []int    `json:"lights,omitempty"`
	Owner       string   `json:"owner,omitempty"`
	Recycle     bool     `json:"recycle,omitempty"`
	Locked      bool     `json:"lcoked,omitempty"`
	AppData     *AppData `json:"appdata,omitempty"`
	Picture     string   `json:"picture,omitempty"`
	LastUpdated Time     `json:"lastupdated,omitempty"`
	Version     int      `json:"version,omitempty"`
}

TODO: maybe change the naming and hierachy of the types.

type Bridge

type Bridge struct {
	Config *Config
}

Bridge is the hue bridge interface

func NewBridge

func NewBridge(conf *Config) *Bridge

NewBridge creates a new bridge api instance

func (*Bridge) CreateGroup

func (b *Bridge) CreateGroup(name string, groupType GroupType, lights []string) (string, error)

CreateGroup creates a new hue group. For rooms please use the CreateRoom call since it also needs a class

func (*Bridge) CreateRoom

func (b *Bridge) CreateRoom(name string, class RoomClasses, lights []string) (string, error)

CreateRoom creates a new hue room.

func (*Bridge) CreateScene

func (b *Bridge) CreateScene(s *CreationScene) (string, error)

TODO: probably support the old version CreateScene will create a new Scene on the bridge. It will return the id of the new scene if no error occures.

func (*Bridge) DeleteScene

func (b *Bridge) DeleteScene(id string) error

DeleteScene deletes the scene specified by the id. Additional to communication errors a non 2xx status code of the response will trigger an error.

func (*Bridge) GetAllGroups

func (b *Bridge) GetAllGroups() (map[string]*Group, error)

GetAllGroups returns all the groups for a hue bridge

func (*Bridge) GetGroupAttributes

func (b *Bridge) GetGroupAttributes(id string) (*Group, error)

GetGroupAttributes returns the state of a group by id

func (*Bridge) GetLights

func (b *Bridge) GetLights() (result map[string]*Light, err error)

GetLights returns all the hue lights

func (*Bridge) GetScene

func (b *Bridge) GetScene(id string) (*Scene, error)

GetScene will return the scene specified by the id. The result will contain the lights states of lights within the scene.

func (*Bridge) GetScenes

func (b *Bridge) GetScenes() (map[string]*BaseScene, error)

GetScenes returns all the hue lights

func (*Bridge) GetState

func (b *Bridge) GetState() (state *BridgeState, err error)

GetState returns the current hue state

func (*Bridge) SetGroupAttributes

func (b *Bridge) SetGroupAttributes(id string, attributes *GroupAttributes) (*BridgeResponse, error)

SetGroupAttributes updates a groups settings by adding devices or changing name or class

func (*Bridge) SetGroupState

func (b *Bridge) SetGroupState(id string, action *GroupAction) ([]*BridgeResponse, error)

SetGroupState sets the state of a group by id

func (*Bridge) SetLightState

func (b *Bridge) SetLightState(id string, state *LightState) (result *BridgeResponse, err error)

SetLightState updates the light state

func (*Bridge) ToggleLight

func (b *Bridge) ToggleLight(id string, on bool) (resp *BridgeResponse, err error)

ToggleLight switches light on or off

type BridgeResponse

type BridgeResponse struct {
	Success map[string]interface{} `json:"success"`
	Error   *BridgeResponseError   `json:"error"`
}

BridgeResponse is the response object returned to a bridge command

type BridgeResponseError

type BridgeResponseError struct {
	Type        uint   `json:"type"`
	Address     string `json:"address"`
	Description string `json:"description"`
}

BridgeResponseError provides info about a bridge api error

func (*BridgeResponseError) String

func (err *BridgeResponseError) String() string

type BridgeState

type BridgeState struct {
	Lights map[string]*Light `json:"lights"`
}

BridgeState provides all data for a bridge

func (*BridgeState) String

func (bs *BridgeState) String() string

type BridgeUserConfig

type BridgeUserConfig struct {
	Name             string `json:"name"`
	APIVersion       string `json:"apiversion"`
	IPAddress        string `json:"ipaddress"`
	MAC              string `json:"mac"`
	BridgeID         string `json:"bridgeid"`
	DataStoreVersion string `json:"datastoreversion"`
	StarterKitID     string `json:"starterkitid"`
	ReplacesBridgeID string `json:"replacesbridgeid"`
}

BridgeUserConfig is the config provided for hue for a user

type Config

type Config struct {
	Username         string `yaml:"name"`
	Password         string `yaml:"userpassword"`
	BridgeAddr       string `yaml:"bridgeAddress"`
	BridgeAddrScheme string `yaml:"bridgeAddressScheme"`
}

Config hue api config

func ReadConfig

func ReadConfig(path string) (conf *Config, err error)

TODO: Rename if this will be placed in a seperate package ReadConfig ...

func (*Config) WriteConfig

func (c *Config) WriteConfig(path string) (err error)

type CreationScene

type CreationScene struct {
	Scene
	TransitionTime int `json:"transitiontime,omitempty"`
}

type DeviceConfig

type DeviceConfig struct {
	ArcheType string         `json:"archetype"`
	Function  string         `json:"function"`
	Direction string         `json:"direction"`
	Startup   *DeviceStartUp `json:"startup,omitempty"`
}

type DeviceStartUp

type DeviceStartUp struct {
	Mode       string `json:"mode"`
	Configured bool   `json:"configured"`
}

type Group

type Group struct {
	Name       string           `json:"name"`
	LightIDs   []string         `json:"lights"`
	SensorIDs  []string         `json:"sensors"`
	Type       string           `json:"type"`
	State      *GroupState      `json:"state"`
	Recycle    bool             `json:"recycle"`
	ModelID    string           `json:"modelid,omitempty"`
	UniqueID   string           `json:"uniqueid,omitempty"`
	Class      string           `json:"class,omitempty"`
	Action     LightState       `json:"action"`
	Presence   *GroupPresence   `json:"presence,omitempty"`
	LightLevel *GroupLightLevel `json:"lightlevel,omitempty"`
}

Group hue type

type GroupAction

type GroupAction struct {
	On             string    `json:"on,omitempty"`
	Bri            uint8     `json:"bri,omitempty"`
	Hue            uint16    `json:"hue,omitempty"`
	Sat            uint8     `json:"sat,omitempty"`
	Xy             []float32 `json:"xy,omitempty"`
	Ct             uint16    `json:"ct,omitempty"`
	Alert          string    `json:"alert,omitempty"`
	Effect         string    `json:"effect,omitempty"`
	TransitionTime uint16    `json:"transitiontime,omitempty"`
	BriInc         int16     `json:"bri_inc,omitempty"`
	SatInc         int16     `json:"sat_inc,omitempty"`
	HueInc         int       `json:"hue_inc,omitempty"`
	CtInc          int       `json:"ct_inc,omitempty"`
	XyInc          int8      `json:"xy_inc,omitempty"`
	Scene          string    `json:"scene,omitempty"`
}

GroupAction is struct for changing a state of a hue group TODO: merge with light actions maybe?

type GroupAttributes

type GroupAttributes struct {
	Name     string   `json:"name,omitempty"`
	LightIDs []string `json:"lights,omitempty"`
	Class    string   `json:"class"`
}

GroupAttributes that can be changed

type GroupCreateResponse

type GroupCreateResponse struct {
	Success struct {
		ID string `json:"id"`
	} `json:"success"`
}

GroupCreateResponse is returned after a create group request

type GroupLightLevel

type GroupLightLevel struct {
	// State?
	LastUpdated Time `json:"lastupdated"`
	Dark        bool `json:"dark"`
	DarkAll     bool `json:"dark_all"`
	Daylight    bool `json:"daylight"`
	DaylightAny bool `json:"daylight_any"`
	Level       int  `json:"lightlevel"`
	LevelMin    int  `json:"lightlevel_min"`
	LevelMax    int  `json:"lightlevel_max"`
}

GroupLightLevel light level struct

type GroupPresence

type GroupPresence struct {
	// State?
	LastUpdated Time `json:"lastupdated"`
	Presence    bool `json:"presence"`
	PresenceAll bool `json:"presence_all"`
}

GroupPresence only exists if sensors array contains a presence sensor of type “ZLLPresence”, “CLIPPresence” or “Geofence”. This object contains a state object which contains the aggregated state of the sensors

type GroupState

type GroupState struct {
	AllOn bool `json:"all_on"`
	AnyOn bool `json:"any_on"`
}

GroupState describes the state of a group

type GroupType

type GroupType int

GroupType hue group type

const (
	// All is a group containing all devices cannot be created
	All GroupType = iota
	Luminaire
	Lightsource
	LightGroup
	Room
	Entertainment
)

func (GroupType) String

func (g GroupType) String() string

type Light

type Light struct {
	State            *LightState        `json:"state,omitempty"`
	SwUpdate         *SwUpdate          `json:"swupdate,omitempty"`
	Type             string             `json:"type,omitempty"`
	Name             string             `json:"name,omitempty"`
	ModelID          string             `json:"modelid,omitempty"`
	ManufacturerName string             `json:"manufacturername,omitempty"`
	Productname      string             `json:"productname,omitempty"`
	Capabilities     *LightCapabilities `json:"capabilities,omitempty"`
	Config           *DeviceConfig      `json:"config"`
	UniqueID         string             `json:"uniqueid,omitempty"`
	SwVersion        string             `json:"swversion,omitempty"`
	SwConfigID       string             `json:"swconfigid,omitempty"`
	ProductID        string             `json:"productid,omitempty"`
}

Light hue object

func (*Light) String

func (l *Light) String() string

type LightCapabilities

type LightCapabilities struct {
	Certified bool                   `json:"certified"`
	Control   *LightControl          `json:"control"`
	Streaming *StreamingCapabilities `json:"streaming"`
}

LightCapabilities type providing control and certification settings

type LightControl

type LightControl struct {
	MinDimLevel    uint16      `json:"mindimlevel,omitempty"`
	MaxLumen       uint        `json:"maxlumen,omitempty"`
	ColorGamutType string      `json:"colorgamuttype,omitempty"`
	ColorGamut     [][]float32 `json:"colorgamut,omitempty"`
	Ct             *LightCt    `json:"ct,omitempty"`
}

type LightCt

type LightCt struct {
	Min uint `json:"min"`
	Max uint `json:"max"`
}

type LightState

type LightState struct {
	On             bool      `json:"on"`
	BridgeID       int       `json:"bri,omitempty"`
	Hue            uint16    `json:"hue,omitempty"`
	Sat            uint8     `json:"sat,omitempty"`
	Effect         string    `json:"effect,omitempty"`
	XY             []float32 `json:"xy,omitempty"`
	Ct             uint16    `json:"ct,omitempty"`
	Alert          string    `json:"alert,omitempty"`
	TransitionTime uint16    `json:"transitiontime,omitempty"`
	ColorMode      string    `json:"colormode,omitempty"`
	Mode           string    `json:"mode,omitempty"`
	Reachable      bool      `json:"reachable,omitempty"`
}

LightState is the hue light>state object

type RoomClasses

type RoomClasses int

RoomClasses in hue

const (
	LivingRoom RoomClasses = iota
	Kitchen
	Dining
	Bedroom
	KidsBedroom
	Bathroom
	Nursery
	Recreation
	Office
	Gym
	Hallway
	Toilet
	FrontDoor
	Garage
	Terrace
	Garden
	Driveway
	Carport
	Other
)

func (RoomClasses) String

func (r RoomClasses) String() string

type Scene

type Scene struct {
	BaseScene
	LightStates map[int][]*LightState `json:"lightstates,omitempty"`
}

type StreamingCapabilities

type StreamingCapabilities struct {
	Renderer bool `json:"renderer"`
	Proxy    bool `json:"proxy"`
}

type SwUpdate

type SwUpdate struct {
	State       string `json:"state,omitempty"`
	LastInstall Time   `json:"lastinstall,omitempty"`
}

SwUpdate provides the current sw state and last install

type Time

type Time struct {
	time.Time
}

func (*Time) MarshalJSON

func (t *Time) MarshalJSON() ([]byte, error)

MarshalJSON marshals mite time to json

func (*Time) UnmarshalJSON

func (t *Time) UnmarshalJSON(b []byte) (err error)

UnmarshalJSON unmarshals mite time from json

type User

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

func CreateUser

func CreateUser(addr string) (u *User, err error)

CreateNewUser will create a new user. This should be called only of there's none in the yaml config.

func CreateUserExtended

func CreateUserExtended(addr, application, deviceName string) (u *User, err error)

TODO: remove these comments

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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