diff --git a/cmd/plugctl/main.go b/cmd/plugctl/main.go new file mode 100644 index 0000000..7631145 --- /dev/null +++ b/cmd/plugctl/main.go @@ -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) + } +}