Documentation ¶
Overview ¶
A simple library that allows you to interface with a REST API compatible with Hive Home smart devices.
Index ¶
- Variables
- type Change
- func (c *Change) Brightness(brightness int) *Change
- func (c *Change) Color(hsv HSV) *Change
- func (c *Change) ColorTemperature(temperature int) *Change
- func (c *Change) ColorTemperaturePercent(percent int) *Change
- func (c *Change) Name(name string) *Change
- func (c *Change) TurnOff() *Change
- func (c *Change) TurnOn() *Change
- type Client
- type Credentials
- type Device
- func (d *Device) Brightness() int
- func (d *Device) Color() HSV
- func (d *Device) ColorTemperature() int
- func (d *Device) ColorTemperaturePercent() int
- func (d *Device) Created() time.Time
- func (d *Device) Do(c *Change) error
- func (d *Device) HasMotion() bool
- func (d *Device) ID() string
- func (d *Device) IsColorLight() bool
- func (d *Device) IsLight() bool
- func (d *Device) IsMotionSensor() bool
- func (d *Device) IsOn() bool
- func (d *Device) IsOnline() bool
- func (d *Device) LastMotionEnd() time.Time
- func (d *Device) LastMotionStart() time.Time
- func (d *Device) LastSeen() time.Time
- func (d *Device) Mode() string
- func (d *Device) Name() string
- func (d *Device) String() string
- func (d *Device) Type() string
- type HSV
Constants ¶
This section is empty.
Variables ¶
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") )
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") )
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} 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 (*Change) Brightness ¶
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 ¶
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 ¶
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 ¶
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.
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 ¶
Device returns the device with the given ID or null if no such device could be found.
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 ¶
RefreshDevices updates the devices available and their current states.
type Credentials ¶
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 ¶
Brightness returns the current brightness level of this light bulb, between 0 and 100.
func (*Device) Color ¶
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 ¶
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 ¶
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) HasMotion ¶
HasMotion returns true if this device is a motion sensor and is currently detecting motion.
func (*Device) IsColorLight ¶
IsColorLight returns true if this device is a color light bulb.
func (*Device) IsMotionSensor ¶
IsMotionSensor checks if this device is a motion sensor.
func (*Device) IsOnline ¶
IsOnline returns true if this device is currently powered on and connected, false otherwise.
func (*Device) LastMotionEnd ¶
LastMotionEnd returns the end time of the last detected motion by this device, if it's a motion sensor.
func (*Device) LastMotionStart ¶
LastMotionStart returns the start time of the last detected motion by this device, if it's a motion sensor.
func (*Device) Name ¶
Name returns the user-given name of this device, or an empty string if no name is given.
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.