Commands was added

This commit is contained in:
2016-06-26 15:55:03 +05:00
parent 3cc52858f1
commit dcec154ed6

View File

@@ -2,21 +2,47 @@ package main
import (
"flag"
"fmt"
"github.com/dedkovd/noolite"
)
func main() {
channel := flag.Int("channel", -1, "Noolite adapter channel")
command := flag.String("command", "", "Command")
flag.Parse()
fmt.Println(*channel)
fmt.Println(*command)
if *channel == -1 {
panic ("Channel was not set")
}
if *command == "" {
panic("Command was not set")
}
n, err := noolite.DefaultNooliteAdapter()
commands := map[string]func(int) error{
"on": n.On,
"off": n.Off,
"switch": n.Switch,
}
if err != nil {
panic(err)
}
defer n.Close()
channel := *flag.Int("c", 0, "Noolite adapter channel")
cmd, ok := commands[*command]
err = n.Switch(channel)
if !ok {
panic("Command not found")
}
cmd(*channel)
if err != nil {
panic(err)