Add CLI as example usage
This commit is contained in:
parent
ca6e93abf4
commit
69a1770760
1 changed files with 35 additions and 0 deletions
35
cmd/plugctl/main.go
Normal file
35
cmd/plugctl/main.go
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
// The plugctl command provides manual CLI control over a Kasa KP105 smart plug.
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
|
||||||
|
"gitea.drjosh.dev/josh/plugctl"
|
||||||
|
)
|
||||||
|
|
||||||
|
var kasaPlugAddr = flag.String("kasa-addr", "KP105:9999", "Address of Kasa smart plug")
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
|
plug := plugctl.Plug{Addr: *kasaPlugAddr}
|
||||||
|
|
||||||
|
switch flag.Arg(0) {
|
||||||
|
case "on":
|
||||||
|
if err := plug.TurnOn(); err != nil {
|
||||||
|
log.Printf("Couldn't turn on smart plug: %v", err)
|
||||||
|
}
|
||||||
|
case "off":
|
||||||
|
if err := plug.TurnOff(); err != nil {
|
||||||
|
log.Printf("Couldn't turn off smart plug: %v", err)
|
||||||
|
}
|
||||||
|
case "state":
|
||||||
|
state, err := plug.RelayState()
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Couldn't get current relay state: %v", err)
|
||||||
|
}
|
||||||
|
fmt.Println(state)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue