-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
221 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package cmd | ||
|
||
const ( | ||
devicePortName = "devicePort" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package cmd | ||
|
||
import ( | ||
"bisecure/cli" | ||
"bisecure/sdk" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
func init() { | ||
groupsCmd := &cobra.Command{ | ||
Use: "groups", | ||
Short: "Manages users defined in your Hörmann BiSecur gateway.", | ||
Long: ``, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
// TODO implement query user list and rights, add and delete user, password change of an already existing user | ||
|
||
mac, err := cli.ParesMacString(deviceMac) | ||
if err != nil { | ||
fmt.Printf("%v\n", err) | ||
os.Exit(1) | ||
} | ||
|
||
err = listGroups(localMac, mac, host, port) | ||
if err != nil { | ||
fmt.Printf("%v\n", err) | ||
os.Exit(2) | ||
} | ||
}, | ||
} | ||
|
||
rootCmd.AddCommand(groupsCmd) | ||
} | ||
|
||
func listGroups(localMac [6]byte, mac [6]byte, host string, port int) error { | ||
client := sdk.NewClient(localMac, mac, host, port) | ||
err := client.Open() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
defer func() { | ||
err2 := client.Close() | ||
if err2 != nil { | ||
fmt.Printf("%v", err) // TODO add log message | ||
} | ||
}() | ||
|
||
groups, err := client.GetGroups() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
fmt.Printf("Groups: %s\n", groups.String()) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,70 @@ | ||
package cmd | ||
|
||
import ( | ||
"bisecure/cli" | ||
"bisecure/sdk" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
// setStateCmd represents the setState command | ||
var setStateCmd = &cobra.Command{ | ||
Use: "set-state", | ||
Short: "Open or close a door connected to your Hörmann BiSecur gateway.", | ||
Long: ``, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
fmt.Println("setState called") | ||
}, | ||
} | ||
|
||
func init() { | ||
var devicePort int | ||
|
||
setStateCmd := &cobra.Command{ | ||
Use: "set-state", | ||
Short: "Open or close a door connected to your Hörmann BiSecur gateway.", | ||
Long: ``, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
mac, err := cli.ParesMacString(deviceMac) | ||
if err != nil { | ||
fmt.Printf("%v\n", err) | ||
os.Exit(1) | ||
} | ||
|
||
err = setStatus(localMac, mac, host, port, username, password, byte(devicePort)) | ||
if err != nil { | ||
fmt.Printf("%v\n", err) | ||
os.Exit(2) | ||
} | ||
}, | ||
} | ||
|
||
rootCmd.AddCommand(setStateCmd) | ||
|
||
// Here you will define your flags and configuration settings. | ||
setStateCmd.Flags().IntVar(&devicePort, devicePortName, 0, "Port number of the door") | ||
setStateCmd.MarkFlagsOneRequired(devicePortName) | ||
} | ||
|
||
func setStatus(localMac [6]byte, mac [6]byte, host string, port int, username string, password string, devicePort byte) error { | ||
client := sdk.NewClient(localMac, mac, host, port) | ||
err := client.Open() | ||
if err != nil { | ||
fmt.Printf("%v", err) | ||
} | ||
|
||
defer func() { | ||
err2 := client.Close() | ||
if err2 != nil { | ||
fmt.Printf("%v", err2) | ||
os.Exit(2) | ||
} | ||
}() | ||
|
||
err = client.Login(username, password) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
fmt.Println("Logged in successfully.") | ||
|
||
err = client.SetState(devicePort) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// Cobra supports Persistent Flags which will work for this command | ||
// and all subcommands, e.g.: | ||
// setStateCmd.PersistentFlags().String("foo", "", "A help for foo") | ||
fmt.Printf("Done\n") | ||
|
||
// Cobra supports local flags which will only run when this command | ||
// is called directly, e.g.: | ||
// setStateCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,70 @@ | ||
package cmd | ||
|
||
import ( | ||
"bisecure/cli" | ||
"bisecure/sdk" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
// statusCmd represents the status command | ||
var statusCmd = &cobra.Command{ | ||
Use: "status", | ||
Short: "Queries the status (open/closed/etc) of your door.", | ||
Long: ``, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
fmt.Println("status called") | ||
}, | ||
} | ||
|
||
func init() { | ||
var devicePort int | ||
|
||
statusCmd := &cobra.Command{ | ||
Use: "status", | ||
Short: "Queries the status (open/closed/etc) of your door.", | ||
Long: ``, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
mac, err := cli.ParesMacString(deviceMac) | ||
if err != nil { | ||
fmt.Printf("%v\n", err) | ||
os.Exit(1) | ||
} | ||
|
||
err = getStatus(localMac, mac, host, port, username, password, byte(devicePort)) | ||
if err != nil { | ||
fmt.Printf("%v\n", err) | ||
os.Exit(2) | ||
} | ||
}, | ||
} | ||
|
||
rootCmd.AddCommand(statusCmd) | ||
|
||
// Here you will define your flags and configuration settings. | ||
statusCmd.Flags().IntVar(&devicePort, devicePortName, 0, "Port number of the door") | ||
statusCmd.MarkFlagsOneRequired(devicePortName) | ||
} | ||
|
||
func getStatus(localMac [6]byte, mac [6]byte, host string, port int, username string, password string, devicePort byte) error { | ||
client := sdk.NewClient(localMac, mac, host, port) | ||
err := client.Open() | ||
if err != nil { | ||
fmt.Printf("%v", err) | ||
} | ||
|
||
defer func() { | ||
err2 := client.Close() | ||
if err2 != nil { | ||
fmt.Printf("%v", err2) | ||
os.Exit(2) | ||
} | ||
}() | ||
|
||
err = client.Login(username, password) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
fmt.Println("Logged in successfully.") | ||
|
||
status, err := client.GetTransition(devicePort) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// Cobra supports Persistent Flags which will work for this command | ||
// and all subcommands, e.g.: | ||
// statusCmd.PersistentFlags().String("foo", "", "A help for foo") | ||
fmt.Printf("Transition: %+v\n", status) | ||
|
||
// Cobra supports local flags which will only run when this command | ||
// is called directly, e.g.: | ||
// statusCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,58 @@ | ||
package cmd | ||
|
||
import ( | ||
"bisecure/cli" | ||
"bisecure/sdk" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
// usersCmd represents the users command | ||
var usersCmd = &cobra.Command{ | ||
Use: "users", | ||
Short: "Manages users defined in your Hörmann BiSecur gateway.", | ||
Long: ``, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
// TODO implement query user list and rights, add and delete user, password change of an already existing user | ||
fmt.Println("users called") | ||
}, | ||
} | ||
|
||
func init() { | ||
usersCmd := &cobra.Command{ | ||
Use: "users", | ||
Short: "Manages users defined in your Hörmann BiSecur gateway.", | ||
Long: ``, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
// TODO implement query user list and rights, add and delete user, password change of an already existing user | ||
mac, err := cli.ParesMacString(deviceMac) | ||
if err != nil { | ||
fmt.Printf("%v\n", err) | ||
os.Exit(1) | ||
} | ||
|
||
err = listUsers(localMac, mac, host, port) | ||
if err != nil { | ||
fmt.Printf("%v\n", err) | ||
os.Exit(2) | ||
} | ||
}, | ||
} | ||
|
||
rootCmd.AddCommand(usersCmd) | ||
} | ||
|
||
func listUsers(localMac [6]byte, mac [6]byte, host string, port int) error { | ||
client := sdk.NewClient(localMac, mac, host, port) | ||
err := client.Open() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
defer func() { | ||
err2 := client.Close() | ||
if err2 != nil { | ||
fmt.Printf("%v", err) // TODO add log message | ||
} | ||
}() | ||
|
||
// Here you will define your flags and configuration settings. | ||
users, err := client.GetUsers() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// Cobra supports Persistent Flags which will work for this command | ||
// and all subcommands, e.g.: | ||
// usersCmd.PersistentFlags().String("foo", "", "A help for foo") | ||
fmt.Printf("Users: %s\n", users.String()) | ||
|
||
// Cobra supports local flags which will only run when this command | ||
// is called directly, e.g.: | ||
// usersCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") | ||
return nil | ||
} |