nuki

package module
v0.0.0-...-7050623 Latest Latest
Warning

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

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

README

TODO

  • test nuki.go
  • write documentation
  • implement remaining todos

Documentation

Overview

Package nuki provides an simple implementation of the bridge api Versoin: v1.7 (30.03.2018)

Index

Constants

View Source
const (
	StateUncalibrated    State = 0
	StateLocked          State = 1
	StateUnlocking       State = 2
	StateUnlocked        State = 3
	StateLocking         State = 4
	StateUnlatched       State = 5
	StateUnlockedLockNgo State = 6
	StateUnlatching      State = 7
	StateMotorBlocked    State = 254
	StateUndefined       State = 255

	ActionUnlock             Action = 1
	ActionLock               Action = 2
	ActionUnlatch            Action = 3
	ActionLockNgo            Action = 4
	ActionLockNgoWithUnlatch Action = 5
)

Variables

View Source
var (
	// ErrNotImplemented function not implemented
	ErrNotImplemented = errors.New("not implemented")
	// ErrAuthFailed Auth() failed
	ErrAuthFailed = errors.New("authentication failed")
	// ErrInvalidURL : 400
	ErrInvalidURL = errors.New("given url is invalid or to long")
	// ErrInvalidToken : 401
	ErrInvalidToken = errors.New("token is invalid")
	// ErrAuthDisabled : 403
	ErrAuthDisabled = errors.New("authentication disabled")
	// ErrSmartLockUnknown : 404
	ErrSmartLockUnknown = errors.New("given smart lock is unknown")
	// ErrSmartLockOffline : 503
	ErrSmartLockOffline = errors.New("given smart lock is offline")
	// ErrUnknown : nobody knows
	ErrUnknown = errors.New("something went wrong")
)
View Source
var ActionName = map[int]string{
	1: "UNLOCK",
	2: "LOCK",
	3: "UNLATCH",
	4: "LOCK_N_GO",
	5: "LOCK_N_GO_WITH_UNLATCH",
}
View Source
var ActionValue = map[string]int{
	"UNLOCK":                 1,
	"LOCK":                   2,
	"UNLATCH":                3,
	"LOCK_N_GO":              4,
	"LOCK_N_GO_WITH_UNLATCH": 5,
}

Action_Lock_value represents ...

View Source
var StateName = map[int]string{
	0:   "UNCALIBRATED",
	1:   "LOCKED",
	2:   "UNLOCKING",
	3:   "UNLOCKED",
	4:   "LOCKING",
	5:   "UNLATCHED",
	6:   "UNLOCKED_LOCK_N_GO",
	7:   "UNLATCHING",
	254: "MOTOR_BLOCKED",
	255: "UNDEFINED",
}
View Source
var StateValue = map[string]int{
	"UNCALIBRATED":       0,
	"LOCKED":             1,
	"UNLOCKING":          2,
	"UNLOCKED":           3,
	"LOCKING":            4,
	"UNLATCHED":          5,
	"UNLOCKED_LOCK_N_GO": 6,
	"UNLATCHING":         7,
	"MOTOR_BLOCKED":      254,
	"UNDEFINED":          255,
}

Functions

func ErrorFromStatus

func ErrorFromStatus(status int) error

ErrorFromStatus returns the matching error based on the given status code

Types

type Action

type Action int

type AuthReponse

type AuthReponse struct {
	Token   string `json:"token"`
	Success bool   `json:"success"`
}

type AutoGenerated

type AutoGenerated struct {
}

type Bridge

type Bridge struct {
	BridgeID    int    `json:"bridgeId"`
	IP          string `json:"ip"`
	Port        int    `json:"port"`
	DateUpdated string `json:"dateUpdated"`
}

type BridgesResponse

type BridgesResponse struct {
	Bridges   []Bridge `json:"bridges"`
	ErrorCode int      `json:"errorCode"`
}

type CallbackReponse

type CallbackReponse struct {
	Success   bool        `json:"success"`
	Callbacks []Callbacks `json:"callbacks"`
}

type Callbacks

type Callbacks struct {
	ID  int    `json:"id"`
	URL string `json:"url"`
}

type Client

type Client interface {
	Do(req *http.Request) (*http.Response, error)
}

Client is the interface implemented by types that can deliver a http response based on the given request.

type ConfigAuthResponse

type ConfigAuthResponse struct {
	Success string `json:"success"`
}

type Ds

type Ds struct {
	HardwareID int `json:"hardwareId"`
	ServerID   int `json:"serverId"`
}

type InfoResponse

type InfoResponse struct {
	BridgeType      int          `json:"bridgeType"`
	Ds              Ds           `json:"ds"`
	Versions        Versions     `json:"versions"`
	Uptime          int          `json:"uptime"`
	CurrentTime     time.Time    `json:"currentTime"`
	ServerConnected bool         `json:"serverConnected"`
	ScanResults     []ScanResult `json:"scanResults"`
}

type LastKnownState

type LastKnownState struct {
	State           int       `json:"state"`
	StateName       string    `json:"stateName"`
	BatteryCritical bool      `json:"batteryCritical"`
	Timestamp       time.Time `json:"timestamp"`
}

type ListResponse

type ListResponse struct {
	NukiID         int            `json:"nukiId"`
	Name           string         `json:"name"`
	LastKnownState LastKnownState `json:"lastKnownState"`
}

type LockActionResponse

type LockActionResponse struct {
	Success         bool `json:"success"`
	BatteryCritical bool `json:"batteryCritical"`
}

type LockStateResponse

type LockStateResponse struct {
	State           int    `json:"state"`
	StateName       string `json:"stateName"`
	BatteryCritical bool   `json:"batteryCritical"`
	Success         bool   `json:"success"`
}

type Log

type Log struct {
	Timestamp time.Time `json:"timestamp"`
	Type      string    `json:"type"`
}

type LogResponse

type LogResponse []Log

type Nuki

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

Nuki holds you access token and connection information

func NewNuki

func NewNuki(address string, opts ...Option) *Nuki

NewNuki returns a new nuki entrypoint without a token to request a new token, the auth function can be called. this connects to the bridge and stores the token internally.

func (*Nuki) Auth

func (n *Nuki) Auth() (*AuthReponse, error)

Auth Enables the api (if not yet enabled) and returns the api token. If no api token has yet been set, a new (random) one is generated. When issuing this API-call the bridge turns on its LED for 30 seconds. The button of the bridge has to be pressed within this timeframe. Otherwise the bridge returns a negative success and no token.

func (*Nuki) CallbackAdd

func (n *Nuki) CallbackAdd(nukiURL string) (*CallbackReponse, error)

CallbackAdd registers a new callback url

func (*Nuki) CallbackList

func (n *Nuki) CallbackList() (*CallbackReponse, error)

CallbackList returns a CallbackReponse with all registered url callbacks

func (*Nuki) CallbackRemove

func (n *Nuki) CallbackRemove(callbackID int) (*CallbackReponse, error)

CallbackRemove removes a previously added callback by ID

func (*Nuki) ClearLog

func (n *Nuki) ClearLog() error

ClearLog clears the log of the Bridge

func (*Nuki) ConfigAuth

func (n *Nuki) ConfigAuth(enable bool) (*ConfigAuthResponse, error)

ConfigAuth enables or disables the authorization via /auth and the publication of the local IP and port to the discovery URL The api token configured via the Nuki app when enabling the API enable: Flag (0 or 1) indicating whether or not the authorization should be enabled

func (*Nuki) FWUpdate

func (n *Nuki) FWUpdate() error

FWUpdate immediately checks for a new firmware update and installs it

func (*Nuki) FactoryReset

func (n *Nuki) FactoryReset() error

FactoryReset performs a factory reset

func (*Nuki) Info

func (n *Nuki) Info() (*InfoResponse, error)

Info returns all smart locks in range and some device information of the bridge itself

func (*Nuki) List

func (n *Nuki) List() ([]ListResponse, error)

List returns all paired Smart Locks a valid token is required

func (*Nuki) LockAction

func (n *Nuki) LockAction(nukiID int, action Action, noWait bool) (*LockActionResponse, error)

LockAction performs a lock operation on the given smart lock given by the id action: the desired lock action noWait: indicating whether or not to wait for the lock action to complete and return its result

func (*Nuki) LockState

func (n *Nuki) LockState(nukiID int) (*LockStateResponse, error)

LockState returns the current lock state of a smart lock by give id

func (*Nuki) Log

func (n *Nuki) Log() (*LogResponse, error)

Log returns a log of the Bridge

func (*Nuki) Reboot

func (n *Nuki) Reboot() error

Reboot s the bridge

func (*Nuki) Token

func (n *Nuki) Token() string

Token returns a token provided by nuki

func (*Nuki) Unpair

func (n *Nuki) Unpair(nukiID int) (*UnpairResponse, error)

Unpair removes the pairing with a given smart lock

type Option

type Option func(*Nuki)

Option allows additional options to be specified for a nuki client

func WithHTTPClient

func WithHTTPClient(c Client) Option

WithHTTPClient allows to set a Client when creating a Nuki.

func WithToken

func WithToken(t string) Option

WithToken allows to set a token when creating a Nuki.

type ScanResult

type ScanResult struct {
	NukiID int    `json:"nukiId"`
	Name   string `json:"name"`
	Rssi   int    `json:"rssi"`
	Paired bool   `json:"paired"`
}

type State

type State int

type UnpairResponse

type UnpairResponse struct {
	Success string `json:"success"`
}

type Versions

type Versions struct {
	FirmwareVersion     string `json:"firmwareVersion"`
	WifiFirmwareVersion string `json:"wifiFirmwareVersion"`
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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