fibarohc2

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2019 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Hc2DefaultConfigFile is the default name of the configuration file
	Hc2DefaultConfigFile string = ".hc2-tools/config.json"

	// RepoName is the name of this repository
	RepoName string = "github.com/theovassiliou/hc2-tools"

	// Version contains the actuall version number. Might be replaces using the LDFLAGS.
	Version = "0.9.0-src"
)
View Source
const (
	TriggerAndManual string = "TRIGGER_AND_MANUAL"
	ManualOnly       string = "MANUAL_ONLY"
	Disabled         string = "DISABLED"
)

Possible values to the used as runconfig field. Others are prohibited

Variables

This section is empty.

Functions

func AssertEqual

func AssertEqual(t *testing.T, a interface{}, b interface{})

AssertEqual checks if values are equal

func AssertHc2SceneEqual

func AssertHc2SceneEqual(t *testing.T, got Hc2Scene, want Hc2Scene)

AssertHc2SceneEqual checks if two Hc2Scenes are equal, provided that the wanted Lua field contains a filename instead of a the actual lua script

func AssertHc2SceneWOLuaEqual

func AssertHc2SceneWOLuaEqual(t *testing.T, got Hc2Scene, want Hc2Scene)

AssertHc2SceneWOLuaEqual checks if two Hc2Scenes are equal, without looking into the lua field

func Default

func Default(fc *FibaroConfig)

Default defines the default values for possible configuration file fields

func FormatFullVersion

func FormatFullVersion(cmdName, version, branch, commit string) string

FormatFullVersion formats for a cmdName the version number based on version, branch and commit

Types

type FibaroConfig

type FibaroConfig struct {
	BaseURL      string `json:"url"`
	Username     string `json:"username"`
	Password     string `json:"password"`
	CreateHeader bool   `json:"createHeader"`
}

FibaroConfig represents the configuration on how to access the Fibaro HC2 system

type FibaroHc2

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

FibaroHc2 represents the Fibaro HC2 system.

func NewFibaroHc2Config

func NewFibaroHc2Config(file string) *FibaroHc2

NewFibaroHc2Config creates a new FibaroHc2 object with the configuration read from a file. The information in the file is JSON encoded

func (*FibaroHc2) Action

func (f *FibaroHc2) Action(sceneID int, c SceneActionCommand) error

Action starts an actions on a given sceneID

func (*FibaroHc2) AllScenes

func (f *FibaroHc2) AllScenes() []Hc2Scene

AllScenes downloads and returns all scenes of the FibaroHC2 system. nil will be returned in case an error occured while downloading the scenes.

func (*FibaroHc2) Config

func (f *FibaroHc2) Config() *FibaroConfig

Config returns the configuration of the Fibaro system

func (*FibaroHc2) CreateScene

func (f *FibaroHc2) CreateScene(scene Hc2Scene) (newSceneID int)

CreateScene creates a new scene in the fibaro system with the name parameters set in the scene. SceneID will be updated with the new scene id being allocated. the header in the lua field will be updated. On sucess CreateScene will return the allocated SceneID, or -1 on error.

func (*FibaroHc2) DebugMessages

func (f *FibaroHc2) DebugMessages(sceneID int) []Hc2DebugMessage

DebugMessages downloads and returns all debug messages for a given sceneID

func (*FibaroHc2) Info

func (f *FibaroHc2) Info(indent int) string

Info returns a human-readable string on information of the HC2 TODO: Write Tests

func (*FibaroHc2) OneRoom

func (f *FibaroHc2) OneRoom(roomID int) Hc2Room

OneRoom downloads and returns a room as identified by the roomID

func (*FibaroHc2) OneScene

func (f *FibaroHc2) OneScene(sceneID int) Hc2Scene

OneScene downloads and returns one scene as identified by the sceneID

func (*FibaroHc2) OneSection

func (f *FibaroHc2) OneSection(sectionID int) Hc2Section

OneSection downloads and returns a section as identified by the sectionID

func (*FibaroHc2) PutOneScene

func (f *FibaroHc2) PutOneScene(scene Hc2Scene) (resp *resty.Response, err error)

PutOneScene upploads a scene to the FibaroHc2 system and returns the response, or any error encountered.

func (*FibaroHc2) SetConfig

func (f *FibaroHc2) SetConfig(fc FibaroConfig)

SetConfig sets the configuration of the FibaroHC2

func (*FibaroHc2) WriteInitConfigFile

func (f *FibaroHc2) WriteInitConfigFile(path string) (bytesWrote int)

WriteInitConfigFile writes the configuration to a file. Paths required will be created if not presend.

type Hc2DebugMessage

type Hc2DebugMessage struct {
	Timestamp int64  `json:"timestamp,omitempty"`
	Type      string `json:"type,omitempty"`
	Txt       string `json:"txt,omitempty"`
}

Hc2DebugMessage represents a debug message of the FibaroHC2 system

type Hc2Info

type Hc2Info struct {
	SerialNumber string `json:"serialNumber,omitempty"`
	HcName       string `json:"hcName,omitempty"`
	Mac          string `json:"mac,omitempty"`
	SoftVersion  string `json:"softVersion,omitempty"`
	Beta         bool   `json:"beta,omitempty"`
	ZwaveVersion string `json:"zwaveVersion,omitempty"`
	ZwaveRegion  string `json:"zwaveRegion,omitempty"`
	ServerStatus int    `json:"serverStatus,omitempty"`
}

Hc2Info represents the general information of the HC2 system. Can be encoded as JSON.

type Hc2LoginStatus

type Hc2LoginStatus struct {
	Status   bool   `json:"status,omitempty"`
	UserID   int    `json:"userID,omitempty"`
	Username string `json:"username,omitempty"`
	Type     string `json:"type,omitempty"`
	ErrorMsg string
}

Hc2LoginStatus represents information on the logged user. Can be encoded as JSON.

type Hc2Network

type Hc2Network struct {
	Dhcp                bool   `json:"dhcp"`
	IP                  string `json:"ip"`
	Mask                string `json:"mask"`
	Gateway             string `json:"gateway"`
	DNS                 string `json:"dns"`
	RemoteAccess        bool   `json:"remoteAccess"`
	RemoteAccessSupport int    `json:"remoteAccessSupport"`
}

Hc2Network represents the network information of the HC2 system. Can be encoded as JSON.

type Hc2Room

type Hc2Room struct {
	RoomID    int    `json:"id"`
	Name      string `json:"name"`
	SectionID int    `json:"sectionID"`
}

Hc2Room represents a room in the HC2 system. Can be encoded as JSON.

type Hc2Scene

type Hc2Scene struct {
	SceneID             int    `json:"id,omitempty"`
	Name                string `json:"name,omitempty"`
	RoomID              int    `json:"roomID,omitempty"`
	RunConfig           string `json:"runConfig,omitempty"`
	MaxRunningInstances int    `json:"maxRunningInstances,omitempty"`
	Lua                 string `json:"lua,omitempty"`
	Type                string `json:"type,omitempty"`
	Autostart           bool   `json:"autostart,omitempty"`
	IsLua               bool   `json:"isLua,omitempty"`
	Visible             bool   `json:"visible,omitempty"`
}

Hc2Scene represents a LUA scene of the FibaroHC2 system

func NewHc2Scene

func NewHc2Scene() (scene Hc2Scene)

NewHc2Scene creates a new Hc2Scene object properly initialized

func (*Hc2Scene) Parse

func (scene *Hc2Scene) Parse(input []byte)

Parse parses a file input, and extracts the scene information located in comments. Comments are supposed to have the following format

--[[ FIBARO_GIT_HOOK
@sceneID=203
@name="A_Trial_2"
@roomID=305
@runConfig=TRIGGER_AND_MANUAL
@maxRunningInstances=2
--]]

If there is no header included then SceneID will be set to -1, and lua will still contain the file content If there is a header and the appropriate tag is not included then the field will not be touched

func (*Hc2Scene) ParseFile

func (scene *Hc2Scene) ParseFile(path string, trim bool)

ParseFile parses a file provided by it's path, and extracts the scene information located in comments, i.e. the FIBARO_GIT_HEADER. If trim set to true, existing FIBARO_GIT_HEADERs will be removed from the Lua field.

func (*Hc2Scene) SanityCheck

func (scene *Hc2Scene) SanityCheck() (pass bool)

SanityCheck performs checks on the value of some fields and returns false if a rule is beeing violated, true otherwise

func (*Hc2Scene) ToComment

func (scene *Hc2Scene) ToComment() string

ToComment translates a Hc2Scene into a LUA comment and returns it as string.m

func (*Hc2Scene) TrimLuaHeaders

func (scene *Hc2Scene) TrimLuaHeaders()

TrimLuaHeaders removes all FIBARO_GIT_HOOK headers from the Lua field and updates the field. If multiple headers are included all will be removed. No other fields of the Hc2Scene will be modified

func (*Hc2Scene) UpdateLuaHeader

func (scene *Hc2Scene) UpdateLuaHeader()

UpdateLuaHeader deletes all headers and appends a new one add the end of the Lua scene with all field set to the Hc2Scene values.

type Hc2Section

type Hc2Section struct {
	SectionID int    `json:"id"`
	Name      string `json:"name"`
}

Hc2Section represents a section in the HC2 system. Can be encoded as JSON.

type SceneActionCommand

type SceneActionCommand int

SceneActionCommand are the commands to be used in an action

const (
	Undef SceneActionCommand = iota
	Start
	Stop
	Enable
	Disable
)

Start, Stop, Enable, Disable are the commands to be used when triggering an action on a scene.

func (*SceneActionCommand) Set

func (b *SceneActionCommand) Set(s string) error

Set the SceneActionCommand based on the string to be parsed. Returns error if not defined.

func (SceneActionCommand) String

func (b SceneActionCommand) String() string

Jump to

Keyboard shortcuts

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