Skip to content

Commit 2f432ee

Browse files
committed
add setFanMode
1 parent d862b63 commit 2f432ee

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ A cli to control your thermostat!
55
```
66
usage: venstar-cli [-h|--help] -i|--ip "<value>" [--set-mode
77
(off|heat|cool|auto)] [--set-cool-temp <integer>]
8+
[--set-fan-mode (auto|on)]
89
910
Access Venstar Thermostat
1011
@@ -15,4 +16,5 @@ Arguments:
1516
thermostat
1617
--set-mode Set the thermostat mode
1718
--set-cool-temp Set the cool-to temperature
19+
--set-fan-mode Set current fan mode to on or auto
1820
```

api.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,17 @@ func convertThermostatMode(mode string) int {
5050
}
5151
}
5252

53+
func convertFanMode(mode string) int {
54+
switch mode {
55+
case "auto":
56+
return 0
57+
case "on":
58+
return 1
59+
default:
60+
return 0
61+
}
62+
}
63+
5364
func getThermostatInfo(ipaddress string) thermostatInfo {
5465
resp, err := http.Get(fmt.Sprintf("http://%s/query/info", ipaddress))
5566
if err != nil {
@@ -78,3 +89,12 @@ func setCoolTemp(ipaddress string, coolTemp int, currentInfo thermostatInfo) boo
7889
_, reqErr := http.PostForm(fmt.Sprintf("http://%s/control", ipaddress), url.Values(data))
7990
return reqErr == nil
8091
}
92+
93+
func setFanMode(ipaddress string, fanMode int, currentInfo thermostatInfo) bool {
94+
data := url.Values{}
95+
data.Set("heattemp", fmt.Sprintf("%d", currentInfo.HeatTemp))
96+
data.Set("cooltemp", fmt.Sprintf("%d", currentInfo.CoolTemp))
97+
data.Set("fan", fmt.Sprintf("%d", fanMode))
98+
_, reqErr := http.PostForm(fmt.Sprintf("http://%s/control", ipaddress), url.Values(data))
99+
return reqErr == nil
100+
}

main.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ func main() {
1212
ip := parser.String("i", "ip", &argparse.Options{Required: true, Help: "An IP (or hostname) is required to actually access a thermostat"})
1313
setMode := parser.Selector("", "set-mode", []string{"off", "heat", "cool", "auto"}, &argparse.Options{Required: false, Help: "Set the thermostat mode"})
1414
coolTemp := parser.Int("", "set-cool-temp", &argparse.Options{Required: false, Help: "Set the cool-to temperature"})
15+
fanMode := parser.Selector("", "set-fan-mode", []string{"auto", "on"}, &argparse.Options{Required: false, Help: "Set current fan mode to on or auto"})
1516
err := parser.Parse(os.Args)
1617
if err != nil {
1718
fmt.Print(parser.Usage(err))
@@ -25,5 +26,8 @@ func main() {
2526
if *coolTemp != 0 {
2627
setCoolTemp(*ip, *coolTemp, thermostatData)
2728
}
29+
if *fanMode != "" {
30+
setFanMode(*ip, convertFanMode(*fanMode), thermostatData)
31+
}
2832
printThermostatInfo(thermostatData)
2933
}

0 commit comments

Comments
 (0)