vera

package module
v0.0.0-...-928f7ab Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2020 License: MIT Imports: 14 Imported by: 0

README

Vera Luup Golang (In Progress)

Use Golang to remotely login and make Luup calls to a Vera™ home controller UI7

Codacy Badge Go Report Card PkgGoDev

Features

  • Remote access using Vera account
  • Polling for device updates
  • Switching Power Status
  • Switching Lock Door Status

How to use

go get github.com/scorpionknifes/go-vera-luup

import vera "github.com/scorpionknifes/go-vera-luup"
  • examples shown in examples/main.go
  • config variables in .env
  • use Controller and Vera struct

TODO

  • Unit tests
  • Luup live_energy_usage
  • Luup variableset

Luup Information

Documentation

Overview

Package vera to remotely access Vera™ home controller UI7 and call Luup For more info about Luup http://wiki.micasaverde.com/index.php/Luup_Requests

Example

//Example Create new object e.g vera = New(username, password)
user := vera.New("username", "password")

//DeviceID = SN number on Vera controller
controller, err := user.GetDeviceRelay("12345670")
if err != nil {
	log.Println(err)
}

//Close controller by
controller.Close()

//Change Switch ID: 5 to Status: 1 aka Turn on Switch 5
controller.SwitchPowerStatus(5, 1)

//Lock door
controller.DoorLockStatus(LockID, 1) // 1 = lock, 0 = unlock

//Check Status using go channels
for {
	select {
	case <-controller.Updated:
		log.Println("Devices Updated")
		//Print out all device names
		for _, device := range *controller.Switches {
			log.Println("Device: " + device.Name + " ID: " + strconv.Itoa(device.ID) + " status: " + device.Status)
		}

		for _, lock := range *controller.Locks {
			log.Println("Lock: " + lock.Name + " ID: " + strconv.Itoa(lock.ID) + " status: " + lock.Locked)
		}
	}
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Controller

type Controller struct {
	Vera         *Vera
	DeviceID     string
	ServerRelay  string
	SessionToken string
	SData        SData     // SData will not be polled unlike Switches
	Switches     *[]Switch // Data here would be update to date
	Locks        *[]Lock
	Kill         chan bool
	Updated      chan bool
	// contains filtered or unexported fields
}

Controller class struct hold info about one controller Controller object has reference to parent Vera object.

func (*Controller) Close

func (con *Controller) Close() error

Close Removes controller from Vera and kills polling.

func (*Controller) CustomRequest

func (con *Controller) CustomRequest(params string) error

CustomRequest custom GET request controller using custom params params can be found http://wiki.micasaverde.com/index.php/Luup_Requests params after /port_3480/data_request? + "params" This function will not return GET data.

func (*Controller) CustomRequestReturn

func (con *Controller) CustomRequestReturn(params string, data interface{}) (interface{}, error)

CustomRequestReturn custom GET request controller using custom params params can be found http://wiki.micasaverde.com/index.php/Luup_Requests params after /port_3480/data_request? + "params" This function will return back struct.

func (*Controller) DoorLockStatus

func (con *Controller) DoorLockStatus(id int, status int) error

DoorLockStatus change lock status.

func (*Controller) GetSData

func (con *Controller) GetSData() error

GetSData Get SData from Hub through Relay Server aka all info Info is stored back inside vera. This should be only called to get new SData.

func (*Controller) GetSessionToken

func (con *Controller) GetSessionToken(vera Vera) error

GetSessionToken get relay session by using identity Call GetSessionToken() to manually renew session token.

func (*Controller) Polling

func (con *Controller) Polling()

Polling using http://wiki.micasaverde.com/index.php/UI_Simple#lu_sdata:_The_polling_loop Polling is achieved by calling GET request and server side timeout until a change is detected.

func (*Controller) Renew

func (con *Controller) Renew(vera Vera) error

Renew renews controller by getting sessions Kills polling and restart polling.

func (*Controller) SwitchPowerStatus

func (con *Controller) SwitchPowerStatus(id int, status int) error

SwitchPowerStatus change swtich status.

type Device

type Device struct {
	PKDevice        string `json:"PK_Device"`
	PKDeviceType    string `json:"PK_DeviceType"`
	PKDeviceSubType string `json:"PK_DeviceSubType"`
	MacAddress      string `json:"MacAddress"`
	ServerDevice    string `json:"Server_Device"`
	ServerDeviceAlt string `json:"Server_Device_Alt"`
	PKInstallation  string `json:"PK_Installation"`
	Name            string `json:"Name"`
	Using2G         string `json:"Using_2G"`
	DeviceAssigned  string `json:"DeviceAssigned"`
	Blocked         int    `json:"Blocked"`
}

Device represents on device (smart controler).

type DeviceInfo

type DeviceInfo struct {
	PKDevice             string `json:"PK_Device"`
	ServerRelay          string `json:"Server_Relay"`
	MacAddress           string `json:"MacAddress"`
	Using2G              int    `json:"Using_2G"`
	ExternalIP           string `json:"ExternalIP"`
	AccessiblePort       string `json:"AccessiblePort"`
	InternalIP           string `json:"InternalIP"`
	AliveDate            string `json:"AliveDate"`
	FirmwareVersion      string `json:"FirmwareVersion"`
	PriorFirmwareVersion string `json:"PriorFirmwareVersion"`
	UpgradeDate          string `json:"UpgradeDate"`
	Uptime               string `json:"Uptime"`
	ServerDevice         string `json:"Server_Device"`
	ServerEvent          string `json:"Server_Event"`
	ServerSupport        string `json:"Server_Support"`
	ServerStorage        string `json:"Server_Storage"`
	WifiSsid             string `json:"WifiSsid"`
	Timezone             string `json:"Timezone"`
	LocalPort            string `json:"LocalPort"`
	ZWaveLocale          string `json:"ZWaveLocale"`
	ZWaveVersion         string `json:"ZWaveVersion"`
	FKBranding           string `json:"FK_Branding"`
	Platform             string `json:"Platform"`
	UILanguage           string `json:"UILanguage"`
	UISkin               string `json:"UISkin"`
	HasWifi              string `json:"HasWifi"`
	HasAlarmPanel        string `json:"HasAlarmPanel"`
	UI                   string `json:"UI"`
	EngineStatus         string `json:"EngineStatus"`
	DistributionBuild    string `json:"DistributionBuild"`
	AccessPermissions    string `json:"AccessPermissions"`
	LinuxFirmware        int    `json:"LinuxFirmware"`
}

DeviceInfo for one device (smart controler).

type Devices

type Devices struct {
	Devices []Device `json:"Devices"`
}

Devices list all devices linked to an account.

type IdentityJSON

type IdentityJSON struct {
	Identity          string `json:"Identity"`
	IdentitySignature string `json:"IdentitySignature"`
	ServerEvent       string `json:"Server_Event"`
	ServerEventAlt    string `json:"Server_Event_Alt"`
	ServerAccount     string `json:"Server_Account"`
	ServerAccountAlt  string `json:"Server_Account_Alt"`
}

IdentityJSON parse GetLoginToken.

type Lock

type Lock struct {
	ID     int    `json:"ID"`
	Name   string `json:"Name"`
	Locked string `json:"Locked"`
}

Lock devices with lock/unlock from vera controller.

type Polling

type Polling struct {
	LoadTime            int
	DataVersion         int
	CurrentMinimumDelay int
	Controller          *Controller
}

Polling struct to poll Controller Polling is a class that is only used for polling in goroutine.

type SData

type SData struct {
	Full         int    `json:"full"`
	Version      string `json:"version"`
	Model        string `json:"model"`
	ZwaveHeal    int    `json:"zwave_heal"`
	Temperature  string `json:"temperature"`
	Skin         string `json:"skin"`
	SerialNumber string `json:"serial_number"`
	Fwd1         string `json:"fwd1"`
	Fwd2         string `json:"fwd2"`
	Mode         int    `json:"mode"`
	Sections     []struct {
		Name string      `json:"name"`
		ID   json.Number `json:"id"`
	} `json:"sections"`
	Rooms []struct {
		Name    string      `json:"name"`
		ID      json.Number `json:"id"`
		Section json.Number `json:"section"`
	} `json:"rooms"`
	Scenes []struct {
		Name    string      `json:"name"`
		ID      json.Number `json:"id"`
		Room    json.Number `json:"room"`
		Active  json.Number `json:"active"`
		State   json.Number `json:"state"`
		Comment string      `json:"comment"`
	} `json:"scenes"`
	Devices     []SDataDevice   `json:"devices"`
	Categories  []SDataCategory `json:"categories"`
	Ir          int             `json:"ir"`
	Irtx        string          `json:"irtx"`
	Loadtime    int             `json:"loadtime"`
	Dataversion int             `json:"dataversion"`
	State       int             `json:"state"`
	Comment     string          `json:"comment"`
}

SData struct to store SData from Luup Request on a device SData struct is designed to be public and users can store data in alternative locations json.Number is used cause Luup Request is not consistent when polling e.g int is received when full=1 and string is received when full=0.

type SDataCategory

type SDataCategory struct {
	Name string `json:"name"`
	ID   int    `json:"id"`
}

SDataCategory struct for category in SData.

type SDataDevice

type SDataDevice struct {
	Name         string      `json:"name"`
	Altid        string      `json:"altid"`
	ID           json.Number `json:"id"` // SData when polling returns string instead of int
	Category     json.Number `json:"category"`
	Subcategory  json.Number `json:"subcategory"`
	Room         json.Number `json:"room"`
	Parent       json.Number `json:"parent"`
	Configured   string      `json:"configured"`
	State        json.Number `json:"state"`
	Comment      string      `json:"comment"`
	Kwh          string      `json:"kwh,omitempty"`
	Status       string      `json:"status"`
	Watts        string      `json:"watts,omitempty"`
	Pincodes     string      `json:"pincodes,omitempty"`
	CommFailure  string      `json:"commFailure,omitempty"`
	Batterylevel string      `json:"batterylevel,omitempty"`
	Locked       string      `json:"locked,omitempty"`
}

SDataDevice struct for devices in SData.

type Switch

type Switch struct {
	ID     int    `json:"ID"`
	Name   string `json:"Name"`
	Status string `json:"Status"`
}

Switch devices with ON/OFF from vera controller.

type Vera

type Vera struct {
	Username     string
	Password     string
	Identity     IdentityJSON // NOTE Identity expires in 24 hrs
	AccountID    string
	SessionToken string
	Devices      Devices
	Controllers  *[]Controller // Add link so we can renew Identity
	// contains filtered or unexported fields
}

Vera class struct hold info about one user Vera object has reference to all Controller childs it creates.

func New

func New(username string, password string) Vera

New Create new Vera object that identify using username & password Login using Vera™ home controller UI7 account.

func (*Vera) GetAllDevices

func (vera *Vera) GetAllDevices() error

GetAllDevices linked to account Get new list of devices linked to vera account This should be used after adding new devices tp a live deployment.

func (*Vera) GetDeviceRelay

func (vera *Vera) GetDeviceRelay(deviceID string) (Controller, error)

GetDeviceRelay construct a Controller Object for the deviceID given Each new Vera controller would require a new Object and SessionToken to interact Each SessionToken also expires in 24 hrs the Object would auto renew with Vera Identity.

func (*Vera) GetIdentityToken

func (vera *Vera) GetIdentityToken() error

GetIdentityToken gets the identity token from vera using username and password.

func (*Vera) GetSessionToken

func (vera *Vera) GetSessionToken() error

GetSessionToken gets the session token using identity token.

func (*Vera) GetSessionTokenURL

func (vera *Vera) GetSessionTokenURL(url string) error

GetSessionTokenURL gets the session token using identity token and URL.

func (*Vera) Renew

func (vera *Vera) Renew() error

Renew Used to renew identity of Vera struct Call this Renew() to manually renew Vera Identity.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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