godeconz

package module
v0.0.14 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2023 License: MIT Imports: 2 Imported by: 0

README

godeconz

... is a binding for the deconz Rest and Websocket API It has exchangeable HTTP Client (default Resty) and Logger (default standard go logger)

Features

  • Alarm Systems
  • Configuration
  • Groups
  • Lights
  • Rules
  • Scenes
  • Schedules
  • Sensors
  • Button Events
  • Touchlink
  • Websocket
  • ETag support

Etag Support Note

Currently, it is implemented on request level. Could be improved to be on entity level because when you request a group of lights for example you receive ETags also that aren't processed yet.

Example

Query all lights:

package main

import (
	"github.com/PerformLine/go-stockutil/log"
	"github.com/go-resty/resty/v2"
	"github.com/kanimaru/godeconz"
	"os"
)

func getEnv(key string, fallback string) string {
	if value, ok := os.LookupEnv(key); ok {
		return value
	}
	if len(fallback) == 0 {
		log.Fatalf("Missing %q", key)
	}
	return fallback
}

func main() {
	setting := godeconz.Settings{
		Address:      getEnv("DECONZ_ADDRESS", ""),
		HttpProtocol: getEnv("DECONZ_PROTO", "http"),
		ApiKey:       getEnv("DECONZ_API_KEY", ""),
	}

	httpAdapter := godeconz.CreateAdapterHttpClientResty(resty.New(), Logger{}, false)
	deconzClient := godeconz.CreateClient(httpAdapter, setting)

	var container map[string]godeconz.LightResponseState
	_, err := deconzClient.GetAllLights(&container)
	if err != nil {
		log.Fatalf("Can't query lights", err)
	}

	for _, light := range container {
		log.Noticef("Name: %v", light.Name)
	}
}

Resources

https://dresden-elektronik.github.io/deconz-rest-doc/

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BuiltinLogger

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

func NewBuiltinLogger

func NewBuiltinLogger() *BuiltinLogger

func (BuiltinLogger) Debugf

func (l BuiltinLogger) Debugf(format string, args ...interface{})

func (BuiltinLogger) Errorf

func (l BuiltinLogger) Errorf(format string, args ...interface{})

func (BuiltinLogger) Infof added in v0.0.6

func (l BuiltinLogger) Infof(format string, args ...interface{})

func (BuiltinLogger) Warnf

func (l BuiltinLogger) Warnf(format string, args ...interface{})

type Config added in v0.0.11

type Config interface {
	IsOn() bool
	IsReachable() *bool
	GetBattery() *uint8
}

type Logger

type Logger interface {
	Errorf(format string, v ...interface{})
	Infof(format string, v ...interface{})
	Warnf(format string, v ...interface{})
	Debugf(format string, v ...interface{})
}

Logger supports trace for maximal information, debug for general debug information and error in case of an error.

type Settings

type Settings struct {
	// Address the base path of deconz without protocol example: 192.168.178.56
	Address string
	// Protocol that should be used default: http
	HttpProtocol string
	// ApiKey that should be used for authorization
	ApiKey string
}

type StateDevice added in v0.0.13

type StateDevice interface {
	IsOn() bool
}

StateDevice is the base for all "light" devices also for OnOff Sockets

type StateLight added in v0.0.11

type StateLight interface {
	GetAlert() interface{}
	GetBrightness() int
	IsOn() bool
}

StateLight is the base for all lights

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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