hive

package
v0.0.0-...-9cdf544 Latest Latest
Warning

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

Go to latest
Published: May 28, 2017 License: MIT Imports: 10 Imported by: 2

Documentation

Overview

A simple library that allows you to interface with a REST API compatible with Hive Home smart devices.

Index

Constants

This section is empty.

Variables

View Source
var (
	// Returned when the login fails due to the server not returning a valid token.
	ErrNoToken = errors.New("no token returned from server")

	// Returned when the login fails to the server not returning an endpoint.
	ErrNoEndpoint = errors.New("no endpoint URL returned from server")
)
View Source
var (
	// Returned when the Credentials object contains no username.
	ErrCredsNoUsername = errors.New("no username specified")

	// Returned when the Credentials object contains no password.
	ErrCredsNoPassword = errors.New("no password specified")

	// Returned when the Credentials object contains no URL.
	ErrCredsNoURL = errors.New("no URL specified")
)
View Source
var (

	// Some color constants in the HSV space.
	ColorWhite  = HSV{0, 0, 100}
	ColorGrey   = HSV{0, 0, 50}
	ColorBlack  = HSV{0, 0, 0}
	ColorRed    = HSV{0, 99, 100}
	ColorGreen  = HSV{120, 99, 50}
	ColorBlue   = HSV{250, 89, 100}
	ColorCyan   = HSV{180, 50, 100}
	ColorNavy   = HSV{250, 75, 50}
	ColorYellow = HSV{60, 50, 100}
	ColorOrange = HSV{14, 66, 100}
	ColorPurple = HSV{284, 75, 100}
)

Functions

This section is empty.

Types

type Change

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

Change represents a single update to the device's current state. For example, for a light bulb, a change may include both turning it on and setting the brightness to a certain level, which will be done in a single request via the Do method of a device.

Change methods are built to be chained, so an example use would be:

someDevice.Do(hive.NewChange().TurnOn().Brightness(50))

func NewChange

func NewChange() *Change

NewChange simply returns an empty Change object.

func (*Change) Brightness

func (c *Change) Brightness(brightness int) *Change

Brightness makes this change set the brightness to the given value. Valid values are numbers between 0 and 100 (inclusive). An invalid value will result in a panic.

func (*Change) Color

func (c *Change) Color(hsv HSV) *Change

Color makes this change set the color to the given value. It will also change the lightbulb mode to *color* if set to *color temperature*. This method will panic if either of hue, saturation or value are set to an invalid value.

func (*Change) ColorTemperature

func (c *Change) ColorTemperature(temperature int) *Change

ColorTemperature makes this change set the color temperature to the given value (in kelvins). It will also change the lightbulb mode to *color temperature* if set to *color*. Valid values are numbers between 2700 and 6535 (inclusive). An invalid value will result in a panic.

func (*Change) ColorTemperaturePercent

func (c *Change) ColorTemperaturePercent(percent int) *Change

ColorTemperaturePercent makes this change set the color temperature to the given percentage. It will also change the lightbulb mode to *color temperature* if set to *color*. Valid values are numbers between 0 and 100 (inclusive). An invalid value will result in a panic.

func (*Change) Name

func (c *Change) Name(name string) *Change

Name sets the device name this change will apply.

func (*Change) TurnOff

func (c *Change) TurnOff() *Change

TurnOff makes this change turn the light off.

func (*Change) TurnOn

func (c *Change) TurnOn() *Change

TurnOn makes this change turn the light on.

type Client

type Client struct {
	// Token represents an authentication token used for all calls to the API.
	Token string

	// EndpointURL is the URL to the given API endpoint all calls will be sent to.
	EndpointURL string
	// contains filtered or unexported fields
}

Client is the main object used to obtain credentials and interface with the REST API.

func NewClient

func NewClient() *Client

NewClient returns a new client that's ready to use the Login method or use a saved token.

func (*Client) Device

func (c *Client) Device(id string) *Device

Device returns the device with the given ID or null if no such device could be found.

func (*Client) Devices

func (c *Client) Devices() []*Device

Devices returns a slice with all the devices present.

func (*Client) Login

func (c *Client) Login(creds *Credentials) error

Login uses the given credentials object to authenticate and obtain a token and an endpoint URL. It will also load the initial list of devices.

func (*Client) RefreshDevices

func (c *Client) RefreshDevices() error

RefreshDevices updates the devices available and their current states.

type Credentials

type Credentials struct {
	Username string
	Password string
	URL      string
}

Credentials contains the user's username, password and URL used to perform the login operation.

type Device

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

Device represents a reference to a single device. It can be a light, sensor thermostat or anything else.

func (*Device) Brightness

func (d *Device) Brightness() int

Brightness returns the current brightness level of this light bulb, between 0 and 100.

func (*Device) Color

func (d *Device) Color() HSV

Color returns the current color set on this colored light bulb. Will return the last used color if the device is not currently in color mode or turned off.

func (*Device) ColorTemperature

func (d *Device) ColorTemperature() int

ColorTemperature returns the current temperature of this colored light bulb in kelvins. Will return the last temperature value if the device is off or in color mode.

func (*Device) ColorTemperaturePercent

func (d *Device) ColorTemperaturePercent() int

ColorTemperaturePercent returns the current temperature of this colored light bulb in percents between 0 and 100, with 100 being the warmest possible setting. Will return the last temperature value if the device is off or in color mode.

func (*Device) Created

func (d *Device) Created() time.Time

Created returns the time when this device was added.

func (*Device) Do

func (d *Device) Do(c *Change) error

Do sends the request to apply the given change to this device.

func (*Device) HasMotion

func (d *Device) HasMotion() bool

HasMotion returns true if this device is a motion sensor and is currently detecting motion.

func (*Device) ID

func (d *Device) ID() string

ID returns the unique ID of this device.

func (*Device) IsColorLight

func (d *Device) IsColorLight() bool

IsColorLight returns true if this device is a color light bulb.

func (*Device) IsLight

func (d *Device) IsLight() bool

IsLight returns true if this device is a light bulb of any kind.

func (*Device) IsMotionSensor

func (d *Device) IsMotionSensor() bool

IsMotionSensor checks if this device is a motion sensor.

func (*Device) IsOn

func (d *Device) IsOn() bool

IsOn returns true if this device is a light bulb and is currently turned on.

func (*Device) IsOnline

func (d *Device) IsOnline() bool

IsOnline returns true if this device is currently powered on and connected, false otherwise.

func (*Device) LastMotionEnd

func (d *Device) LastMotionEnd() time.Time

LastMotionEnd returns the end time of the last detected motion by this device, if it's a motion sensor.

func (*Device) LastMotionStart

func (d *Device) LastMotionStart() time.Time

LastMotionStart returns the start time of the last detected motion by this device, if it's a motion sensor.

func (*Device) LastSeen

func (d *Device) LastSeen() time.Time

LastSeen returns the time when this device was last online.

func (*Device) Mode

func (d *Device) Mode() string

func (*Device) Name

func (d *Device) Name() string

Name returns the user-given name of this device, or an empty string if no name is given.

func (*Device) String

func (d *Device) String() string

String returns a string representation of this device, containing the ID, name and type.

func (*Device) Type

func (d *Device) Type() string

Type returns the type of this device.

type HSV

type HSV struct {
	// Hue of the color. Valid values are [0, 359].
	Hue int
	// Saturation of the color. Valid values are [0, 99].
	Saturation int
	// Value of the color (brightness). Valid values are [0, 100].
	Value int
}

HSV contains the Hue, Saturation and Value used when setting the color of a colored light bulb.

Jump to

Keyboard shortcuts

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