first functional version
This commit is contained in:
@@ -1,23 +1,21 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"math"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"tplink/internal/tplink"
|
||||
)
|
||||
|
||||
func main() {
|
||||
initialize()
|
||||
|
||||
_, _, err := nextSunriseSunsetTime(config.CalculateDate)
|
||||
if err != nil {
|
||||
log.Fatalf("[ERROR] Unable to calculate sunrise/sunset: %v\n", err)
|
||||
}
|
||||
|
||||
if config.NextSunrise || config.NextSunset {
|
||||
sR, sS, err := nextSunriseSunsetTime(config.SunRiseSet.Date)
|
||||
switch {
|
||||
case config.NextSunrise || config.NextSunset:
|
||||
sR, sS, err := nextSunriseSunsetTime(config.CalculateDate.In(config.TimeZone))
|
||||
if err != nil {
|
||||
runError(fmt.Sprintf("Unable to calculate sunrise/sunset: %v\n", err))
|
||||
}
|
||||
@@ -30,5 +28,37 @@ func main() {
|
||||
}
|
||||
|
||||
os.Exit(0)
|
||||
case config.On:
|
||||
tp := tplink.Tplink{Host: config.Host, SwitchID: config.DeviceID}
|
||||
if err := tp.ChangeStateMultiSwitch(true); err != nil {
|
||||
runError(fmt.Sprintf("Error communcating with device: %v", err))
|
||||
}
|
||||
case config.Off:
|
||||
tp := tplink.Tplink{Host: config.Host, SwitchID: config.DeviceID}
|
||||
if err := tp.ChangeStateMultiSwitch(false); err != nil {
|
||||
runError(fmt.Sprintf("Error communcating with device: %v", err))
|
||||
}
|
||||
case config.GetState:
|
||||
tp := tplink.Tplink{Host: config.Host, SwitchID: config.DeviceID}
|
||||
info, err := tp.SystemInfo()
|
||||
if err != nil {
|
||||
runError(fmt.Sprintf("Error communcating with device: %v", err))
|
||||
}
|
||||
var state int
|
||||
if len(info.System.GetSysinfo.Children) == 0 {
|
||||
fmt.Printf("Name:\t\t%s\n", info.System.GetSysinfo.Alias)
|
||||
state = info.System.GetSysinfo.RelayState
|
||||
} else {
|
||||
fmt.Printf("Name:\t\t%s\n", info.System.GetSysinfo.Children[config.DeviceID].Alias)
|
||||
state = info.System.GetSysinfo.Children[config.DeviceID].State
|
||||
}
|
||||
fmt.Printf("MAC Address:\t%s\n", info.System.GetSysinfo.Mac)
|
||||
if state == 0 {
|
||||
fmt.Printf("Power is:\t%s\n", "Off")
|
||||
} else {
|
||||
fmt.Printf("Power is:\t%s\n", "On")
|
||||
}
|
||||
default:
|
||||
flag.PrintDefaults()
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user