-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
78 lines (69 loc) · 2.25 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package main
import (
"strconv"
"strings"
)
func main() {
args := parseArgs()
switch args.Command {
case "set":
setParamsOnDevice(args.Params, args.DeviceId)
case "list":
GetDeviceList().Print()
case "status":
GetDeviceStatus().Print()
}
}
func setParamsOnDevice(argParams DeviceParamList, deviceId string) {
var sendParams string
// This clownery is necessary, because golang can't remove elements from an unmarshal
// We only want to set the specific arguments we are changing
if argParams.EcoFunctionData != -999 {
sendParams += `"ecoFunctionData":` + strconv.Itoa(argParams.EcoFunctionData) + `,`
}
if argParams.AirSwingLR != -999 {
sendParams += `"airSwingLR":` + strconv.Itoa(argParams.AirSwingLR) + `,`
}
if argParams.Nanoe != -999 {
sendParams += `"nanoe":` + strconv.Itoa(argParams.Nanoe) + `,`
}
if argParams.EcoNavi != -999 {
sendParams += `"ecoNavi":` + strconv.Itoa(argParams.EcoNavi) + `,`
}
if argParams.EcoMode != -999 {
sendParams += `"ecoMode":` + strconv.Itoa(argParams.EcoMode) + `,`
}
if argParams.OperationMode != -999 {
sendParams += `"operationMode":` + strconv.Itoa(argParams.OperationMode) + `,`
}
if argParams.FanAutoMode != -999 {
sendParams += `"fanAutoMode":` + strconv.Itoa(argParams.FanAutoMode) + `,`
}
if argParams.TemperatureSet != -999 {
sendParams += `"temperatureSet":` + strconv.FormatFloat(argParams.TemperatureSet, 'f', 1, 64) + `,`
}
if argParams.FanSpeed != -999 {
sendParams += `"fanSpeed":` + strconv.Itoa(argParams.FanSpeed) + `,`
}
if argParams.IAuto != -999 {
sendParams += `"iAuto":` + strconv.Itoa(argParams.IAuto) + `,`
}
if argParams.AirQuality != -999 {
sendParams += `"airQuality":` + strconv.Itoa(argParams.AirQuality) + `,`
}
if argParams.Operate != -999 {
sendParams += `"operate":` + strconv.Itoa(argParams.Operate) + `,`
}
if argParams.AirDirection != -999 {
sendParams += `"airDirection":` + strconv.Itoa(argParams.AirDirection) + `,`
}
if argParams.ActualNanoe != -999 {
sendParams += `"actualNanoe":` + strconv.Itoa(argParams.ActualNanoe) + `,`
}
if argParams.AirSwingUD != -999 {
sendParams += `"airSwingUD":` + strconv.Itoa(argParams.AirSwingUD) + `,`
}
// remove last comma
sendParams = strings.TrimRight(sendParams, ",")
SetDeviceStatus(sendParams)
}