-
Notifications
You must be signed in to change notification settings - Fork 9
/
attributes.go
324 lines (307 loc) · 8.2 KB
/
attributes.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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
package vitotrol
import (
"fmt"
"strconv"
)
// An AttrID defines an attribute ID.
type AttrID uint16
// Attribute IDs currently supported by the library. For each, the
// Vitotrol™ name.
const (
IndoorTemp AttrID = 5367 // temp_rts_r
OutdoorTemp AttrID = 5373 // temp_ats_r
SmokeTemp AttrID = 5372 // temp_agt_r
BoilerTemp AttrID = 5374 // temp_kts_r
HotWaterTemp AttrID = 5381 // temp_ww_r
HotWaterOutTemp AttrID = 5382 // temp_auslauf_r
HeatWaterOutTemp AttrID = 6052 // temp_vts_r
HeatNormalTemp AttrID = 82 // konf_raumsolltemp_rw
PartyModeTemp AttrID = 79 // konf_partysolltemp_rw
HeatReducedTemp AttrID = 85 // konf_raumsolltemp_reduziert_rw
HotWaterSetpointTemp AttrID = 51 // konf_ww_solltemp_rw
BurnerHoursRun AttrID = 104 // anzahl_brennerstunden_r
BurnerHoursRunReset AttrID = 106 // anzahl_brennerstunden_w
BurnerState AttrID = 600 // zustand_brenner_r
BurnerStarts AttrID = 111 // anzahl_brennerstart_r
InternalPumpStatus AttrID = 245 // zustand_interne_pumpe_r
HeatingPumpStatus AttrID = 729 // zustand_heizkreispumpe_r
CirculationPumpState AttrID = 7181 // zustand_zirkulationspumpe_r
PartyMode AttrID = 7855 // konf_partybetrieb_rw
EnergySavingMode AttrID = 7852 // konf_sparbetrieb_rw
DateTime AttrID = 5385 // konf_uhrzeit_rw
CurrentError AttrID = 7184 // aktuelle_fehler_r
HolidaysStart AttrID = 306 // konf_ferien_start_rw
HolidaysEnd AttrID = 309 // konf_ferien_ende_rw
HolidaysStatus AttrID = 714 // zustand_ferienprogramm_r
Way3ValveStatus AttrID = 5389 // info_status_umschaltventil_r
OperatingModeRequested AttrID = 92 // konf_betriebsart_rw
OperatingModeCurrent AttrID = 708 // aktuelle_betriebsart_r
FrostProtectionStatus AttrID = 717 // zustand_frostgefahr_r
NoAttr AttrID = 0xffff // Used in error cases
)
// An AttrAccess defines attributes access rights.
type AttrAccess uint8
// Availables access rights.
const (
ReadOnly AttrAccess = 1 << iota
WriteOnly
ReadWrite AttrAccess = ReadOnly | WriteOnly
)
// AccessToStr map allows to translate AttrAccess values to strings.
var AccessToStr = map[AttrAccess]string{
ReadOnly: "read-only",
WriteOnly: "write-only",
ReadWrite: "read/write",
}
// An AttrRef describes an attribute reference: its type, access and name.
type AttrRef struct {
Type VitodataType
Access AttrAccess
Name string
Doc string
Custom bool
}
// String returns all information contained in this attribute reference.
func (r *AttrRef) String() string {
return fmt.Sprintf("%s: %s (%s - %s)",
r.Name, r.Doc, r.Type.Type(), AccessToStr[r.Access])
}
// AttributesRef lists the reference for each attribute ID.
var AttributesRef = map[AttrID]*AttrRef{
IndoorTemp: {
Type: TypeDouble,
Access: ReadOnly,
Doc: "Indoor temperature",
Name: "IndoorTemp",
},
OutdoorTemp: {
Type: TypeDouble,
Access: ReadOnly,
Doc: "Outdoor temperature",
Name: "OutdoorTemp",
},
SmokeTemp: {
Type: TypeDouble,
Access: ReadOnly,
Doc: "Smoke temperature",
Name: "SmokeTemp",
},
BoilerTemp: {
Type: TypeDouble,
Access: ReadOnly,
Doc: "Boiler temperature",
Name: "BoilerTemp",
},
HotWaterTemp: {
Type: TypeDouble,
Access: ReadOnly,
Doc: "Hot water temperature",
Name: "HotWaterTemp",
},
HotWaterOutTemp: {
Type: TypeDouble,
Access: ReadOnly,
Doc: "Hot water outlet temperature",
Name: "HotWaterOutTemp",
},
HeatWaterOutTemp: {
Type: TypeDouble,
Access: ReadOnly,
Doc: "Heating water outlet temperature",
Name: "HeatWaterOutTemp",
},
HeatNormalTemp: {
Type: TypeDouble,
Access: ReadWrite,
Doc: "Setpoint of the normal room temperature",
Name: "HeatNormalTemp",
},
PartyModeTemp: {
Type: TypeDouble,
Access: ReadWrite,
Doc: "Party mode temperature",
Name: "PartyModeTemp",
},
HeatReducedTemp: {
Type: TypeDouble,
Access: ReadWrite,
Doc: "Setpoint of the reduced room temperature",
Name: "HeatReducedTemp",
},
HotWaterSetpointTemp: {
Type: TypeDouble,
Access: ReadWrite,
Doc: "Setpoint of the domestic hot water temperature",
Name: "HotWaterSetpointTemp",
},
BurnerHoursRun: {
Type: TypeDouble,
Access: ReadOnly,
Doc: "Burner hours run",
Name: "BurnerHoursRun",
},
BurnerHoursRunReset: {
Type: TypeDouble,
Access: WriteOnly,
Doc: "Reset the burner hours run",
Name: "BurnerHoursRunReset",
},
BurnerState: {
Type: TypeOnOffEnum,
Access: ReadOnly,
Doc: "Burner status",
Name: "BurnerState",
},
BurnerStarts: {
Type: TypeDouble,
Access: ReadWrite,
Doc: "Burner starts",
Name: "BurnerStarts",
},
InternalPumpStatus: {
Type: NewEnum([]string{ // 0 -> 3
"off",
"on",
"off2",
"on2",
}),
Access: ReadOnly,
Doc: "Internal pump status",
Name: "InternalPumpStatus",
},
HeatingPumpStatus: {
Type: TypeOnOffEnum,
Access: ReadOnly,
Doc: "Heating pump status",
Name: "HeatingPumpStatus",
},
CirculationPumpState: {
Type: TypeOnOffEnum,
Access: ReadOnly,
Doc: "Statut pompe circulation",
Name: "CirculationPumpState",
},
PartyMode: {
Type: TypeEnabledEnum,
Access: ReadWrite,
Doc: "Party mode status",
Name: "PartyMode",
},
EnergySavingMode: {
Type: TypeEnabledEnum,
Access: ReadWrite,
Doc: "Energy saving mode status",
Name: "EnergySavingMode",
},
DateTime: {
Type: TypeDate,
Access: ReadWrite,
Doc: "Current date and time",
Name: "DateTime",
},
CurrentError: {
Type: TypeString,
Access: ReadOnly,
Doc: "Current error",
Name: "CurrentError",
},
HolidaysStart: {
Type: TypeDate,
Access: ReadWrite,
Doc: "Holidays begin date",
Name: "HolidaysStart",
},
HolidaysEnd: {
Type: TypeDate,
Access: ReadWrite,
Doc: "Holidays end date",
Name: "HolidaysEnd",
},
HolidaysStatus: {
Type: TypeEnabledEnum,
Access: ReadOnly,
Doc: "Holidays program status",
Name: "HolidaysStatus",
},
Way3ValveStatus: {
Type: NewEnum([]string{ // 0 -> 3
"undefined",
"heating",
"middle position",
"hot water",
}),
Access: ReadOnly,
Doc: "3-way valve status",
Name: "3WayValveStatus",
},
OperatingModeRequested: {
Type: NewEnum([]string{ // 0 -> 4
"off",
"DHW only",
"heating+DHW",
"continuous reduced",
"continuous normal",
}),
Access: ReadWrite,
Doc: "Operating mode requested",
Name: "OperatingModeRequested",
},
OperatingModeCurrent: {
Type: NewEnum([]string{ // 0 -> 3
"stand-by",
"reduced",
"normal",
"continuous normal",
}),
Access: ReadOnly,
Doc: "Operating mode",
Name: "OperatingModeCurrent",
},
FrostProtectionStatus: {
Type: TypeEnabledEnum,
Access: ReadOnly,
Doc: "Frost protection status",
Name: "FrostProtectionStatus",
},
}
// AddAttributeRef adds a new attribute to the "official" list. This
// new attribute will only differ from others by its Custom field set
// to true.
//
// No check is done to avoid overriding existing attributes.
func AddAttributeRef(attrID AttrID, ref AttrRef) {
ref.Custom = true
AttributesRef[attrID] = &ref
AttributesNames2IDs = computeNames2IDs()
Attributes = computeAttributes()
}
func computeNames2IDs() map[string]AttrID {
ret := make(map[string]AttrID, len(AttributesRef))
for attrID, pAttrRef := range AttributesRef {
ret[pAttrRef.Name] = attrID
}
return ret
}
func computeAttributes() []AttrID {
ret := make([]AttrID, 0, len(AttributesRef))
for attrID := range AttributesRef {
ret = append(ret, attrID)
}
return ret
}
// AttributesNames2IDs maps the attributes names to their AttrID
// counterpart.
var AttributesNames2IDs = computeNames2IDs()
// Attributes lists the AttrIDs for all available attributes.
var Attributes = computeAttributes()
// Value is the timestamped value of an attribute.
type Value struct {
Value string
Time Time
}
// Num returns the numerical value of this value. If the value is not
// a numerical one, 0 is returned.
func (v *Value) Num() (ret float64) {
ret, _ = strconv.ParseFloat(v.Value, 64)
return
}