Documentation
¶
Overview ¶
Package govee provides a Go client for the Govee Developer REST API v1. It supports listing devices, querying device state, and sending control commands (on/off, brightness, RGB color, color temperature).
Usage:
client := govee.New("your-api-key")
devices, err := client.GetDevices(ctx)
err = client.TurnOn(ctx, devices[0].DeviceID, devices[0].Model)
Index ¶
- type APIError
- type Client
- func (c *Client) GetDeviceState(ctx context.Context, deviceID, model string) (*DeviceState, error)
- func (c *Client) GetDevices(ctx context.Context) ([]Device, error)
- func (c *Client) SetBrightness(ctx context.Context, deviceID, model string, brightness int) error
- func (c *Client) SetColor(ctx context.Context, deviceID, model string, r, g, b int) error
- func (c *Client) SetColorTemp(ctx context.Context, deviceID, model string, kelvin int) error
- func (c *Client) TurnOff(ctx context.Context, deviceID, model string) error
- func (c *Client) TurnOn(ctx context.Context, deviceID, model string) error
- type Color
- type ColorTempRange
- type Device
- type DeviceProperties
- type DeviceState
- type Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a Govee API client. Create one with New().
func (*Client) GetDeviceState ¶
GetDeviceState queries the current state of a device. Only devices with Retrievable=true return useful state. Note: the "online" field is cached on Govee's side and may be stale.
func (*Client) GetDevices ¶
GetDevices returns all Govee devices associated with the API key.
func (*Client) SetBrightness ¶
SetBrightness sets the brightness of the device (0–100). A value of 0 turns the device off.
func (*Client) SetColorTemp ¶
SetColorTemp sets the color temperature of the device in Kelvin. The valid range is device-specific (reported in DeviceProperties.ColorTemp).
type ColorTempRange ¶
ColorTempRange is the supported color temperature range for a device, in Kelvin.
type Device ¶
type Device struct {
// DeviceID is the MAC address of the device, used to identify it in control and state requests.
DeviceID string `json:"device"`
// Model is the product model string (e.g. "H6159").
Model string `json:"model"`
// DeviceName is the user-assigned name from the Govee app.
DeviceName string `json:"deviceName"`
// Controllable is true when the device accepts control commands.
Controllable bool `json:"controllable"`
// Retrievable is true when the device state can be queried.
Retrievable bool `json:"retrievable"`
// SupportCmds lists the commands the device accepts: "turn", "brightness", "color", "colorTem".
SupportCmds []string `json:"supportCmds"`
// Properties holds optional per-device property constraints.
Properties DeviceProperties `json:"properties"`
}
Device represents a Govee smart device returned by the API.
func (Device) SupportsCmd ¶
SupportsCmd reports whether the device supports the given command name.
type DeviceProperties ¶
type DeviceProperties struct {
// ColorTemp is non-nil when the device supports the "colorTemp" command.
ColorTemp *ColorTempRange `json:"colorTemp,omitempty"`
}
DeviceProperties holds optional per-device constraints returned by DeviceList.
type DeviceState ¶
type DeviceState struct {
// Online indicates whether the device is reachable. Note: this is cached by
// the Govee API and may be stale; control commands should still be attempted
// even when Online is false.
Online bool
// PowerState is "on" or "off".
PowerState string
// Brightness is the current brightness level (0–100). 0 means off or unknown.
Brightness int
// Color is the current RGB color, or nil if not reported.
Color *Color
// ColorTemp is the current color temperature in Kelvin, or 0 if not reported.
ColorTemp int
}
DeviceState is the current reported state of a device.
type Option ¶
type Option func(*Client)
Option is a functional option for configuring a Client.
func WithBaseURL ¶
WithBaseURL overrides the default API base URL. Useful for testing.
func WithHTTPClient ¶
WithHTTPClient replaces the default *http.Client. Useful for custom transports or timeouts.