plugctl/cmd/plugctl/main.go

35 lines
726 B
Go

// 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)
}
}