gohue

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2021 License: BSD-3-Clause Imports: 11 Imported by: 12

README

gohue

Go API for controlling Hue lights. This library was developed apart from Phillips or Hue and is not affiliated with those brands.

This API is stable. Newly added API that is not yet stable will be clearly marked as draft API.

Using

import "github.com/keep94/gohue"

Documentation

Overview

Package gohue controls hue lights. See http://developers.meethue.com.

Index

Constants

This section is empty.

Variables

View Source
var (
	// Bright represents the brightest a light can be
	Bright = uint8(255)

	// Dim represents the dimmest a light can be.
	Dim = uint8(0)
)
View Source
var (
	// Indicates that the light ID is not found.
	NoSuchResourceError = errors.New("gohue: No such resource error.")

	// Indicates that some general error happened.
	GeneralError = errors.New("gohue: General error.")
)
View Source
var (
	Red     = NewColor(0.675, 0.322)
	Green   = NewColor(0.4077, 0.5154)
	Blue    = NewColor(0.167, 0.04)
	Yellow  = Red.Blend(Green, 0.5)
	Magenta = Blue.Blend(Red, 0.5)
	Cyan    = Blue.Blend(Green, 0.5)
	Purple  = NewColor(0.2522, 0.0882)
	White   = NewColor(0.3848, 0.3629)
	Pink    = NewColor(0.55, 0.3394)
	Orange  = Red.Blend(Yellow, 0.5)
)

Functions

This section is empty.

Types

type Color

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

Color represents a particular color. Programs using Colors should typically store and pass them as values, not pointers.

func NewColor

func NewColor(x, y float64) Color

NewColor returns a new Color. x and y are the coordinates of the color in the color XY space. x and y are between 0.0 and 1.0 inclusive.

func (Color) Blend

func (c Color) Blend(other Color, ratio float64) Color

Blend blends this color with another color returning the blended Color. ratio=0 means use only this color; ratio=1 means use only the other color.

func (Color) String

func (c Color) String() string

func (Color) X

func (c Color) X() float64

X returns the X value of this Color.

func (Color) Y

func (c Color) Y() float64

Y returns the Y value of this Color.

type Context

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

Context represents a connection with a hue bridge.

func NewContext

func NewContext(ipAddress, userId string) *Context

NewContext creates a new Context instance. ipAddress is the private ip address of the hue bridge, but could be a DNS name. userId is the user Id / developer Id (See hue documentation).

func NewContextWithOptions

func NewContextWithOptions(
	ipAddress, userId string, options *Options) *Context

NewContextWithOptions creates a new Context instance. ipAddress is the private ip address of the hue bridge, but could be a DNS name. userId is the user Id / developer Id (See hue documentation). options contains optional settings for the created context.

func (*Context) Get

func (c *Context) Get(lightId int) (
	properties *LightProperties, response []byte, err error)

Get gets the properties of a light. lightId is the ID of the light. properties is the returned properties. response is the raw response from the hue bridge or nil if communication failed. This function may return both a non-nil response and an error if the response from the hue bridge indicates an error. For most applications, it is enough just to look at properties and err.

func (*Context) Set

func (c *Context) Set(
	lightId int, properties *LightProperties) (response []byte, err error)

Set sets the properties of a light. lightId is the ID of the light to set. 0 means all lights. response is the raw response from the hue bridge or nil if communication failed. This function may return both a non-nil response and an error if the response from the hue bridge indicates an error. For most applications, it is enough just to look at err.

type LightProperties

type LightProperties struct {
	// C is the Color. Nothing means leave color as-is.
	C MaybeColor

	// Bri is the brightness. Nothing means leave brightness as is.
	Bri maybe.Uint8

	// On is true if light is on or false if it is off. Nothing
	// means leave the on/off state as is.
	On maybe.Bool

	// The transition time in multiples of 100ms. Nothing means the default
	// transition time. See http://developers.meethue.com.
	// Used only with Context.Set(). Context.Get() does not populate.
	TransitionTime maybe.Uint16
}

LightProperies represents the properties of a light.

type MaybeColor

type MaybeColor struct {
	Color
	// True if this instance represents a Color or false otherwise.
	Valid bool
}

MaybeColor instances represent a Color or nothing. The zero value is nothing.

func NewMaybeColor

func NewMaybeColor(c Color) MaybeColor

NewMaybeColor returns a new instance that represents c.

func (*MaybeColor) Clear

func (m *MaybeColor) Clear()

Clear makes this instance represent nothing.

func (*MaybeColor) Set

func (m *MaybeColor) Set(c Color)

Set makes this instance represent c.

func (MaybeColor) String

func (m MaybeColor) String() string

type Options

type Options struct {
	// Operations that take longer than this will fail with an error.
	// Zero or negative values means no timeout specified.
	Timeout time.Duration
}

Options contains optional settings for Context instance creation.

Directories

Path Synopsis
Package actions controls hue lights via asynchronous tasks.
Package actions controls hue lights via asynchronous tasks.
Package json_structs contains structures used internally for parsing json.
Package json_structs contains structures used internally for parsing json.

Jump to

Keyboard shortcuts

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