forked from Will1604/infinitive
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tables.go
186 lines (163 loc) · 4.26 KB
/
tables.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
package main
type InfinityTableAddr [3]byte
type InfinityTable interface {
addr() InfinityTableAddr
}
type TStatCurrentParams struct {
Z1CurrentTemp uint8
Z2CurrentTemp uint8
Z3CurrentTemp uint8
Z4CurrentTemp uint8
Z5CurrentTemp uint8
Z6CurrentTemp uint8
Z7CurrentTemp uint8
Z8CurrentTemp uint8
Z1CurrentHumidity uint8
Z2CurrentHumidity uint8
Z3CurrentHumidity uint8
Z4CurrentHumidity uint8
Z5CurrentHumidity uint8
Z6CurrentHumidity uint8
Z7CurrentHumidity uint8
Z8CurrentHumidity uint8
Unknown1 uint8
OutdoorAirTemp int8
ZoneUnocc uint8 // bitflags
Mode uint8
Unknown2 [5]uint8
DisplayedZone uint8
}
func (params TStatCurrentParams) addr() InfinityTableAddr {
return InfinityTableAddr{0x00, 0x3B, 0x02}
}
type TStatZoneParams struct {
Z1FanMode uint8
Z2FanMode uint8
Z3FanMode uint8
Z4FanMode uint8
Z5FanMode uint8
Z6FanMode uint8
Z7FanMode uint8
Z8FanMode uint8
ZoneHold uint8 // bitflags
Z1HeatSetpoint uint8
Z2HeatSetpoint uint8
Z3HeatSetpoint uint8
Z4HeatSetpoint uint8
Z5HeatSetpoint uint8
Z6HeatSetpoint uint8
Z7HeatSetpoint uint8
Z8HeatSetpoint uint8
Z1CoolSetpoint uint8
Z2CoolSetpoint uint8
Z3CoolSetpoint uint8
Z4CoolSetpoint uint8
Z5CoolSetpoint uint8
Z6CoolSetpoint uint8
Z7CoolSetpoint uint8
Z8CoolSetpoint uint8
Z1TargetHumidity uint8
Z2TargetHumidity uint8
Z3TargetHumidity uint8
Z4TargetHumidity uint8
Z5TargetHumidity uint8
Z6TargetHumidity uint8
Z7TargetHumidity uint8
Z8TargetHumidity uint8
FanAutoCfg uint8
Unknown uint8
Z1HoldDuration uint16
Z2HoldDuration uint16
Z3HoldDuration uint16
Z4HoldDuration uint16
Z5HoldDuration uint16
Z6HoldDuration uint16
Z7HoldDuration uint16
Z8HoldDuration uint16
Z1Name [12]byte
Z2Name [12]byte
Z3Name [12]byte
Z4Name [12]byte
Z5Name [12]byte
Z6Name [12]byte
Z7Name [12]byte
Z8Name [12]byte
}
func (params TStatZoneParams) addr() InfinityTableAddr {
return InfinityTableAddr{0x00, 0x3B, 0x03}
}
type DevInfoParams struct {
Description [24]byte
Unknown1 [24]byte
Software [16]byte
Product [20]byte
Unknown2 [12]byte
Serial [24]byte
}
func (params DevInfoParams) addr() InfinityTableAddr {
return InfinityTableAddr{0x00, 0x01, 0x04}
}
type TStatVacationParams struct {
Active uint8
Hours uint16
MinTemperature uint8
MaxTemperature uint8
MinHumidity uint8
MaxHumidity uint8
FanMode uint8 // matches fan mode from TStatZoneParams
}
func (params TStatVacationParams) addr() InfinityTableAddr {
return InfinityTableAddr{0x00, 0x3B, 0x04}
}
type APIVacationConfig struct {
Active *bool `json:"active"`
Days *uint8 `json:"days"`
MinTemperature *uint8 `json:"minTemperature"`
MaxTemperature *uint8 `json:"maxTemperature"`
MinHumidity *uint8 `json:"minHumidity"`
MaxHumidity *uint8 `json:"maxHumidity"`
FanMode *string `json:"fanMode"`
}
func (params TStatVacationParams) toAPI() APIVacationConfig {
api := APIVacationConfig{MinTemperature: ¶ms.MinTemperature,
MaxTemperature: ¶ms.MaxTemperature,
MinHumidity: ¶ms.MinHumidity,
MaxHumidity: ¶ms.MaxHumidity}
active := bool(params.Active == 1)
api.Active = &active
days := uint8(params.Hours / 7)
api.Days = &days
mode := rawFanModeToString(params.FanMode)
api.FanMode = &mode
return api
}
func (params *TStatVacationParams) fromAPI(config *APIVacationConfig) byte {
flags := byte(0)
if config.Days != nil {
params.Hours = uint16(*config.Days) * uint16(24)
flags |= 0x02
}
if config.MinTemperature != nil {
params.MinTemperature = *config.MinTemperature
flags |= 0x04
}
if config.MaxTemperature != nil {
params.MaxTemperature = *config.MaxTemperature
flags |= 0x08
}
if config.MinHumidity != nil {
params.MinHumidity = *config.MinHumidity
flags |= 0x10
}
if config.MaxHumidity != nil {
params.MaxHumidity = *config.MaxHumidity
flags |= 0x20
}
if config.FanMode != nil {
mode, _ := stringFanModeToRaw(*config.FanMode)
// FIXME: check for ok here
params.FanMode = mode
flags |= 0x40
}
return flags
}