govee

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2023 License: BSD-3-Clause Imports: 6 Imported by: 3

README

go-vee Logo
go-vee - Govee API Wrapper for Go

go-vee is an unofficial Go wrapper for the Govee API. It makes it easy to control your Govee smart devices from your Go code. It is based on the official Govee API documentation. This project is a work in progress, use in production at your own risk.

To get started with the Govee API, you need to request an API key. You can do this from the Govee Home app. Open the app, go to Profile > Settings > Apply for API Key.

Installation

go get github.com/loxhill/go-vee

Usage

package main

import (
    "fmt"
    govee "github.com/loxhill/go-vee"
)

client := govee.New("your-api-key")

listRequest := client.ListDevices()
response, err := client.Run(listRequest)
if err != nil {
    panic(err)
}
devices := response.Devices()

controlRequest, _ := client.Device(devices[0].Device, devices[0].Model).TurnOn()
_, err = client.Run(controlRequest)
if err != nil {
    panic(err)
}

Documentation

Index

Constants

View Source
const Version = "0.0.1"

Variables

View Source
var (
	ErrUnsupportedCmd = errors.New("unsupported command")
)

Functions

This section is empty.

Types

type Client

type Client struct {
	APIKey string
}

func New

func New(apiKey string) *Client

func (*Client) Device

func (c *Client) Device(device string, model string) *Device

func (*Client) ListDevices

func (c *Client) ListDevices() DeviceListRequest

func (*Client) Run

func (c *Client) Run(request GoveeRequest) (GoveeResponse, error)

type Cmd

type Cmd struct {
	Name  string      `json:"name"`
	Value interface{} `json:"value"`
}

type Color

type Color struct {
	R int `json:"r"`
	G int `json:"g"`
	B int `json:"b"`
}

func Aqua

func Aqua() Color

func Blue

func Blue() Color

func Brown

func Brown() Color

func Cyan

func Cyan() Color

func DarkBlue

func DarkBlue() Color

func Gold

func Gold() Color

func Gray

func Gray() Color

func Green

func Green() Color

func GreenYellow

func GreenYellow() Color

func Indigo

func Indigo() Color

func Lime

func Lime() Color

func Magenta

func Magenta() Color

func Maroon

func Maroon() Color
func Navy() Color

func Olive

func Olive() Color

func Orange

func Orange() Color

func Pink

func Pink() Color

func Purple

func Purple() Color

func Red

func Red() Color

func Silver

func Silver() Color

func Teal

func Teal() Color

func Violet

func Violet() Color

func White

func White() Color

func Yellow

func Yellow() Color

type ColorTem

type ColorTem struct {
	Range Range `json:"range"`
}

type Device

type Device struct {
	Device       string     `json:"device"`
	Model        string     `json:"model"`
	DeviceName   string     `json:"deviceName"`
	Controllable bool       `json:"controllable"`
	Retrievable  bool       `json:"retrievable"`
	SupportCmds  []string   `json:"supportCmds"`
	Properties   Properties `json:"properties"`
}

func (*Device) Control

func (d *Device) Control(cmd string, value interface{}) (DeviceControlRequest, error)

func (*Device) SetBrightness

func (d *Device) SetBrightness(brightness int) (DeviceControlRequest, error)

func (*Device) SetColor

func (d *Device) SetColor(color Color) (DeviceControlRequest, error)

func (*Device) SetColorTem

func (d *Device) SetColorTem(colorTem int) (DeviceControlRequest, error)

func (*Device) State

func (d *Device) State() DeviceStateRequest

func (*Device) TurnOff

func (d *Device) TurnOff() (DeviceControlRequest, error)

func (*Device) TurnOn

func (d *Device) TurnOn() (DeviceControlRequest, error)

type DeviceControlBody

type DeviceControlBody struct {
	Device string `json:"device"`
	Model  string `json:"model"`
	Cmd    Cmd    `json:"cmd"`
}

type DeviceControlRequest

type DeviceControlRequest struct {
	Endpoint string
	Method   string
	Body     DeviceControlBody
}

func (DeviceControlRequest) GetBody

func (d DeviceControlRequest) GetBody() interface{}

func (DeviceControlRequest) GetEndpoint

func (d DeviceControlRequest) GetEndpoint() string

func (DeviceControlRequest) GetMethod

func (d DeviceControlRequest) GetMethod() string

func (DeviceControlRequest) GetParams

func (d DeviceControlRequest) GetParams() map[string]string

type DeviceListRequest

type DeviceListRequest struct {
	Endpoint string
	Method   string
}

func (DeviceListRequest) GetBody

func (d DeviceListRequest) GetBody() interface{}

func (DeviceListRequest) GetEndpoint

func (d DeviceListRequest) GetEndpoint() string

func (DeviceListRequest) GetMethod

func (d DeviceListRequest) GetMethod() string

func (DeviceListRequest) GetParams

func (d DeviceListRequest) GetParams() map[string]string

type DeviceStateRequest

type DeviceStateRequest struct {
	Endpoint string
	Method   string
	Params   map[string]string
}

func (DeviceStateRequest) GetBody

func (d DeviceStateRequest) GetBody() interface{}

func (DeviceStateRequest) GetEndpoint

func (d DeviceStateRequest) GetEndpoint() string

func (DeviceStateRequest) GetMethod

func (d DeviceStateRequest) GetMethod() string

func (DeviceStateRequest) GetParams

func (d DeviceStateRequest) GetParams() map[string]string

type Devices

type Devices []Device

type GoveeRequest

type GoveeRequest interface {
	GetEndpoint() string
	GetMethod() string
	GetBody() interface{}
	GetParams() map[string]string
}

type GoveeResponse

type GoveeResponse struct {
	Code    int          `json:"code"`
	Message string       `json:"message"`
	Data    ResponseData `json:"data"`
}

func (GoveeResponse) Device

func (g GoveeResponse) Device() string

func (GoveeResponse) Devices

func (g GoveeResponse) Devices() Devices

func (GoveeResponse) Model

func (g GoveeResponse) Model() string

func (GoveeResponse) Properties

func (g GoveeResponse) Properties() []map[string]interface{}

type Properties

type Properties struct {
	ColorTem ColorTem `json:"colorTem"`
}

type Range

type Range struct {
	Min int `json:"min"`
	Max int `json:"max"`
}

type ResponseData

type ResponseData struct {
	Device     string                   `json:"device"`
	Model      string                   `json:"model"`
	Properties []map[string]interface{} `json:"properties"`
	Devices    []Device                 `json:"devices"`
}

Jump to

Keyboard shortcuts

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