Help us shape the future of Go! Take the 2026 Go Developer Survey

panel

package module
v0.0.0-...-3a85ee5 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2019 License: MIT Imports: 7 Imported by: 0

README

Panel Library

This is a golang API client library for interacting with Nanoleaf Canvas tiles. See sample.go for usage examples.

See GoDoc for detailed library documentation: https://godoc.org/github.com/weaseal/panel

Currently, you can use this library to interact with the Canvas tile in the following ways:

  • toggle on/off
  • brightness
  • colour tempeature
  • hue / saturation

Basically, you can set the panel to any solid color & brightness combination. It does not yet support other modes, such as effects. PRs welcome!

TODO

  • tests

Documentation

Overview

Package panel exports functions related to a Nanoleaf Canvas controller

Index

Constants

View Source
const (
	// On is true
	On PowerState = true
	// Off is false
	Off PowerState = false

	// APIPathState is the path for the power on/off state
	APIPathState APIPath = "state"
	// APIPathNew is the path for token credentials
	APIPathNew APIPath = "new"

	// MinimumTemperature lowest colour temperature in Kelvin
	MinimumTemperature Temperature = 1200
	// MaximumTemperature highest colour temperature in Kelvin
	MaximumTemperature Temperature = 6500
	// MinimumBrightness lowest possible Brightness
	MinimumBrightness Brightness = 0
	// MaximumBrightness lowest possible Brightness
	MaximumBrightness Brightness = 100
	// MinimumHue lowest possible Hue
	MinimumHue Hue = 0
	// MaximumHue highest possible Hue
	MaximumHue Hue = 360
	// MinimumSaturation lowest possible saturation
	MinimumSaturation Saturation = 0
	// MaximumSaturation highest possible saturation
	MaximumSaturation Saturation = 100
	// ColourModeTemperature is the API's colourMode name for temperature
	ColourModeTemperature ColourMode = "ct"
	// ColourModeHueSaturation is the API's colourMode name for hue/saturation
	ColourModeHueSaturation ColourMode = "hs"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type APIPath

type APIPath string

APIPath is the path after the auth-token, eg "state". See related consts

type AuthToken

type AuthToken string

AuthToken allows you to interact with the panel

type Brightness

type Brightness uint8

Brightness 0 - 100

type ColourMode

type ColourMode string

ColourMode describes the current method for setting colour, either "ct" or "hs", for temperature or hue/saturation

type Hue

type Hue uint16

Hue colour 0 - 360

type Panel

type Panel struct {
	Status status
	// contains filtered or unexported fields
}

Panel is a Nanoleaf panel

func NewPanel

func NewPanel() *Panel

NewPanel instantiates a new Panel

func (*Panel) Apply

func (panel *Panel) Apply(settings *StateSettings) error

Apply adjusts multiple settings in a single request. NOTE: As of firmware v1.5.0, the Canvas returns a 404 when multiple settings are sent -- although it does actually succeed at applying the change. Given this bug, consider discarding the returned error here.

func (*Panel) GetNewToken

func (panel *Panel) GetNewToken() (AuthToken, error)

GetNewToken attempts to get a new auth token from the panel. The panel must be in pairing mode for this to work. See notes under the API section 5.1, Authorization - https://forum.nanoleaf.me/docs/openapi the token is returned, and stored on the current panel object. The user should take care to save the returned token for future use.

func (*Panel) GetStateSettings

func (panel *Panel) GetStateSettings() (*StateSettings, error)

GetStateSettings returns the current state of the panel, omitting fields which are not really in use, such as hue when the colour mode is temperature, as they would fail to apply together. This is somewhat buggy, as the returned values are generally incorrect if the panel was configured by something other than direct API calls, such as via mobile app.

func (*Panel) Off

func (panel *Panel) Off() error

Off turn on the light

func (*Panel) On

func (panel *Panel) On() error

On turn on the light

func (*Panel) SetAPIAddr

func (panel *Panel) SetAPIAddr(apiAddr string) error

SetAPIAddr sets the address to be used when communicating with the API. Must be a valid URI.

func (*Panel) SetBrightness

func (panel *Panel) SetBrightness(brightness Brightness) error

SetBrightness adjusts panel brightness

func (*Panel) SetHue

func (panel *Panel) SetHue(hue Hue) error

SetHue adjusts panel colour by hue 0 - 360

func (*Panel) SetSaturation

func (panel *Panel) SetSaturation(saturation Saturation) error

SetSaturation adjusts panel saturation 0 - 100

func (*Panel) SetTemperature

func (panel *Panel) SetTemperature(temperature Temperature) error

SetTemperature adjusts panel colour by Kelvin temperature 1200 - 6500

func (*Panel) SetToken

func (panel *Panel) SetToken(token AuthToken)

SetToken sets the token to be used when communicating with the API

type PowerState

type PowerState bool

PowerState is the on/off value for the panel light

type Saturation

type Saturation uint16

Saturation for colour 0 - 100

type StateSettings

type StateSettings struct {
	Brightness  *brightnessSetting  `json:"brightness,omitempty"`
	Temperature *temperatureSetting `json:"ct,omitempty"`
	Hue         *hueSetting         `json:"hue,omitempty"`
	Saturation  *saturationSetting  `json:"saturation,omitempty"`
	ColourMode  *ColourMode         `json:"colorMode,omitempty"`
	On          *onSetting          `json:"on,omitempty"`
}

StateSettings settings for the panel display

func (*StateSettings) SetBrightness

func (settings *StateSettings) SetBrightness(brightness Brightness)

SetBrightness is a helper function that allows updating a StateSettings object with shorthand eg "settings.SetBrightness(20)"

func (*StateSettings) SetHue

func (settings *StateSettings) SetHue(hue Hue)

SetHue is a helper function that allows updating a StateSettings object with shorthand eg "settings.SetHue(20)"

func (*StateSettings) SetSaturation

func (settings *StateSettings) SetSaturation(saturation Saturation)

SetSaturation is a helper function that allows updating a StateSettings object with shorthand eg "settings.SetSaturation(20)"

func (*StateSettings) SetTemperature

func (settings *StateSettings) SetTemperature(temperature Temperature)

SetTemperature is a helper function that allows updating a StateSettings object with shorthand eg "settings.SetTemperature(1200)"

func (*StateSettings) Validate

func (settings *StateSettings) Validate()

Validate adjusts settings to required min/max

type Temperature

type Temperature uint16

Temperature colour in Kelvin 1200 - 6500

Jump to

Keyboard shortcuts

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