Giter VIP home page Giter VIP logo

hc2-tools's Introduction

hc2-tools

hc2-tools, implemented in go (golang) provides tools to, upload, download and interact with scene on Fibaro HC2 system.

The design goal of the tools where to be easily integrable into IDEs like Visual Studio Code (VSC) or others, to enable comfortable Fibaro Lua script development, testing and deployment. While there can be very different applications on how to use the tools, USAGE.md has examples on how the development workflow can be enhanced by using the hc2-tools.

It is in public beta; you are free to use it and improve it (do pull requests).

WARNING: THIS SOFTWARE CAN'T BE ERROR FREE, SO USE IT AT YOUR OWN RISK. DON'T USE IT IF YOU HAVEN'T MADE AN ACTUAL BACKUP COPY OF YOUR FIBARO HC2 SYSTEM. IF YOU DO NOT HOW TO DO THIS, PLEASE RECONSIDER TO USE THIS SOFTWARE ANYWAY. I HAVE DONE MY BEST TO MAKE SURE THAT THE TOOLS BEHAVE AS EXPECTED. BUT AGAIN ... USE IT AT YOUR OWN RISK. I AM NOT GIVING ANY KIND OF WARRANTY, NEITHER EXPLICITELY NOR IMPLICITELY.

Installation binaries

You can download the binaries directly from the releases section. Unzip/untar the downloaded archive and copy the files to a location of your choice, e.g. /usr/local/bin/ on *NIX or MacOS. If you install only the binaries, make sure that they are accessible from the command line. Ideally, they are accessible via $PATH or %PATH%, respectively.

Configuring your installation

hc2-tools need access to your Fibaro HC2 system. You can configure and test your installation just by

hc2DownloadScene -u <fibaroHc2Login> -p <secretPassword> --url http://<ip.address.of.hc2> -i -t

This tests the connection to your Fibaro HC2 system and creates a config-file in ~/.hc2-tool/* so that you do not have to reenter the information in subsequent to the hc2-tools calls. Of course, you have to replace <fibaroHc2Login> and <secretPassword> with your credentials, and <ip.address.of.hc2> with the IP or DNS of your Fibaro HC2 system.

To test the successfull configuration just use

hc2DownloadScene -t which should get you the same result as above. All h2-tools use the same configuration file, so you don't have to configure the individually. Actually you could perfom this configuration steps, with any of the tools.

If you would like to learn about more about the technology in the background take a look at TECHNOLOGY.md.

Installation From Source

hc2-tools requires golang version 1.13 or newer, the Makefile requires GNU make.

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

There is no particular requirement beyong the fact that you should have a working go installation.

Install Go >=1.13

Installing

Download hc2-tools source by running

go get -u github.com/theovassiliou/hc2-tools

This gets you your copy of hc2-tools installed under $GOPATH/src/github.com/theovassiliou/hc2-tools

Run make from the source directory by running

cd $GOPATH/src/github.com/theovassiliou/hc2-tools
make all

to compile and build the three executables

and run

make go-install

to install a copy of the executables into $GOPATH/bin

To test whether build integrates with your Fibaro system use

hc2DownloadScene -u <fibaroHc2Login> -p <secretPassword> --url http://<ip.address.of.hc2> -i -t

Successfull connected to ...
  Name         : Hal
  Serial       : HC2-033533
  IP           : <ip.address.of.hc2>
  Version      : 4.560
  ZWaveVersion : 3.67

and logged in as:
  User:         <fibaroHc2Login>
  Type:         superuser

This tests the connection to your Fibaro HC2 system and -i creates a config-file in ~/.hc2-tool/* so that you do not have to reenter the information in subsequent to the hc2-tools calls. Of course you have to replace <fibaroHc2Login> and <secretPassword> with your credentials, and <ip.address.of.hc2> with the IP or DNS of your Fibaro HC2 system.

To test the successfull configuration just use

hc2DownloadScene -t which should get you the same result as above.

Now make your head-start by calling

hc2DownloadScene

which downloads all scripts on the Fibaro HC2 into the default created directory ./download/

Running the tests

We are using to different make targets for running tests.

make test

go test -short ./...
?    github.com/theovassiliou/hc2-tools/cmd/expandRequire [no test files]
?    github.com/theovassiliou/hc2-tools/cmd/hc2DownloadScene [no test files]
?    github.com/theovassiliou/hc2-tools/cmd/hc2SceneInteract [no test files]
?    github.com/theovassiliou/hc2-tools/cmd/hc2UploadScene [no test files]
ok   github.com/theovassiliou/hc2-tools/pkg 0.036s

executes all short package tests, while

make test-all
go vet $(go list ./...)
go test ./...
?    github.com/theovassiliou/hc2-tools/cmd/expandRequire [no test files]
?    github.com/theovassiliou/hc2-tools/cmd/hc2DownloadScene [no test files]
?    github.com/theovassiliou/hc2-tools/cmd/hc2SceneInteract [no test files]
?    github.com/theovassiliou/hc2-tools/cmd/hc2UploadScene [no test files]
ok   github.com/theovassiliou/hc2-tools/pkg 0.036s

executes in addition go veton the package. Before committing to the code base please use make test-all to ensure that all tests pass.

Break down into end to end tests

After creating your configuration call hc2DownloadScene without -u -p parameters.

hc2DownloadScene -t

Successful connected to ...
  Name         : Hal
  Serial       : HC2-033533
  IP           : 192.10.66.55
  Version      : 4.560
  ZWaveVersion : 3.67

and logged in as:
  User:         [email protected]
  Type:         superuser

to test whether command can execute correctly.

Deployment

After running

make install

go build -ldflags " -X main.commit=99f909d -X main.branch=master" ./cmd/hc2UploadScene
go build -ldflags " -X main.commit=99f909d -X main.branch=master" ./cmd/hc2DownloadScene
go build -ldflags " -X main.commit=99f909d -X main.branch=master" ./cmd/hc2SceneInteract
mkdir -p /usr/local/bin/
cp hc2UploadScene /usr/local/bin/
cp hc2DownloadScene /usr/local/bin/
cp hc2SceneInteract /usr/local/bin/

you can find your executables in /usr/local/bin. Make sure /usr/local/bin/ is in your path.

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Authors

License

This project is licensed under the MIT License - see the LICENSE file for details

Acknowledgments

Thanks to all the people out there that produce amazing open-source software, which supported the creation of this piece of software. In particular I wasn't only able to use libraries etc. But also, to learn and understand golang better. In particular I wanted to thank


History

This project has been developed as I was seeking for a way to upload scenes from my favorite development Lua development environment to the Fibaro HC2 system. Finally I came up with the idea to upload a scene whenever I do a git commit. For this I needed a cmd line tool can be integrated as commithook into the git repository.

With this I could solve two problems at a single time.

  1. Enforcing a version control system, e.g. git
  2. Automatically uploading the modified script

After implementing a first version, new ideas emerged, so for example retrieving debug messages where implemented.

hc2-tools's People

Contributors

theovassiliou avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

anto35 nilmoty

hc2-tools's Issues

Check requiered go version in Makefile

Normally if you are providing a Makefile people do not read to much documentation but make just use of the normal make approach. So checking the requiered golang version would be very conventient.

deflate previously included libraries

On Upload hc2UploadScene expands via the require() statment included libraries.
So for a full round-trip engineering it would be beneficial to "deflate" the included libraries again.

In other words to replace code like

--^ require('library/Debug');
-- LIBRARY BEGIN -------------------------
-- DO NOT MODIFY THE CODE
...
-- LIBRARY END -------------------------

back to
require('library/Debug');

Time stamp in uploaded file

It would be in some situations helpful if we could identify when the scene in the Fibaro HC2 system has been uploaded. A timestamp would be beneficial.

A related but perhaps different feature could be, to include the commit code in case it has been uploaded via a pre-commit hook. So the status of the uploaded scene could be visualised very easy.

Handle multiple require statements

It seems to be a common problem, that multiple libraries import the same libraries. For example a "debug" library can be imported multiple times. As a result only one expanded import should be used. The othe required() should be just commented.

Example

file1.lua
require('libary/debug')
require('library/hueLights')
libary/debug.lua
...
--- Print an error message in the console
Error = function ( message )
  Debug("red", "error: " .. message ) 
end
...

And finally

library/hueLights.lua
require('libary/debug')
.....

Currently we get an expanded file1.lua as

file1.lua
--^ require('libary/debug')
-- LIBRARY BEGIN -------------------------
-- DO NOT MODIFY THE CODE
...
--- Print an error message in the console
Error = function ( message )
  Debug("red", "error: " .. message ) 
end
...
-- LIBRARY END -------------------------

--^ require('library/hueLights')
-- LIBRARY BEGIN -------------------------
-- DO NOT MODIFY THE CODE
--^ require('libary/debug')
-- LIBRARY BEGIN -------------------------
-- DO NOT MODIFY THE CODE
...
--- Print an error message in the console
Error = function ( message )
  Debug("red", "error: " .. message ) 
end
...
-- LIBRARY END -------------------------
-- LIBRARY END -------------------------

This is definitely not what we want.

Instead

file1.lua
--^ require('libary/debug')
-- LIBRARY BEGIN -------------------------
-- DO NOT MODIFY THE CODE
...
--- Print an error message in the console
Error = function ( message )
  Debug("red", "error: " .. message ) 
end
...
-- LIBRARY END -------------------------

--^ require('library/hueLights')
-- LIBRARY BEGIN -------------------------
-- DO NOT MODIFY THE CODE
--^ require('libary/debug')
-- LIBRARY END -------------------------

Or something similiar would be required.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.