diff --git a/README.md b/README.md index 3c8e740..dedaa1f 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,7 @@ A cli to control your thermostat! ``` usage: venstar-cli [-h|--help] -i|--ip "" [--set-mode (off|heat|cool|auto)] [--set-cool-temp ] + [--set-fan-mode (auto|on)] Access Venstar Thermostat @@ -15,4 +16,5 @@ Arguments: thermostat --set-mode Set the thermostat mode --set-cool-temp Set the cool-to temperature + --set-fan-mode Set current fan mode to on or auto ``` diff --git a/api.go b/api.go index 4b3c975..a61d4b3 100644 --- a/api.go +++ b/api.go @@ -50,6 +50,17 @@ func convertThermostatMode(mode string) int { } } +func convertFanMode(mode string) int { + switch mode { + case "auto": + return 0 + case "on": + return 1 + default: + return 0 + } +} + func getThermostatInfo(ipaddress string) thermostatInfo { resp, err := http.Get(fmt.Sprintf("http://%s/query/info", ipaddress)) if err != nil { @@ -78,3 +89,12 @@ func setCoolTemp(ipaddress string, coolTemp int, currentInfo thermostatInfo) boo _, reqErr := http.PostForm(fmt.Sprintf("http://%s/control", ipaddress), url.Values(data)) return reqErr == nil } + +func setFanMode(ipaddress string, fanMode int, currentInfo thermostatInfo) bool { + data := url.Values{} + data.Set("heattemp", fmt.Sprintf("%d", currentInfo.HeatTemp)) + data.Set("cooltemp", fmt.Sprintf("%d", currentInfo.CoolTemp)) + data.Set("fan", fmt.Sprintf("%d", fanMode)) + _, reqErr := http.PostForm(fmt.Sprintf("http://%s/control", ipaddress), url.Values(data)) + return reqErr == nil +} diff --git a/main.go b/main.go index b773fac..a5f4175 100644 --- a/main.go +++ b/main.go @@ -12,6 +12,7 @@ func main() { ip := parser.String("i", "ip", &argparse.Options{Required: true, Help: "An IP (or hostname) is required to actually access a thermostat"}) setMode := parser.Selector("", "set-mode", []string{"off", "heat", "cool", "auto"}, &argparse.Options{Required: false, Help: "Set the thermostat mode"}) coolTemp := parser.Int("", "set-cool-temp", &argparse.Options{Required: false, Help: "Set the cool-to temperature"}) + fanMode := parser.Selector("", "set-fan-mode", []string{"auto", "on"}, &argparse.Options{Required: false, Help: "Set current fan mode to on or auto"}) err := parser.Parse(os.Args) if err != nil { fmt.Print(parser.Usage(err)) @@ -25,5 +26,8 @@ func main() { if *coolTemp != 0 { setCoolTemp(*ip, *coolTemp, thermostatData) } + if *fanMode != "" { + setFanMode(*ip, convertFanMode(*fanMode), thermostatData) + } printThermostatInfo(thermostatData) }