-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodel.go
538 lines (497 loc) · 18.4 KB
/
model.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
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
package digitalstrom
import (
"encoding/json"
"errors"
"fmt"
)
/*
* Structure ┐
* └ Apartment ┐
* ├ Zones ┐
* | ├ Devices ┐
* | | ├ Sensors
* | | ├ BinaryInputs
* | | ├ OutputChannels
* | | ├ GroupIds
* | | ├ ModeFeatures
* | | └ PairdDeviceIDs
* | └ Groups ┐
* | └ DeviceIDs
* └ Floors ┐
* └ ZoneIDs
*/
// Structure represents the digitalSTROM structure of
// an installation.
type Structure struct {
Apartment Apartment `json:"apartment"`
}
// Apartment is the logical instance of a digitalSTROM installation. This includes
// all rooms and any device.
type Apartment struct {
Zones []Zone `json:"zones"`
Floors []Floor `json:"floors"`
}
// Zone is a logical representation of one room, hall or
// other partial structural works of a building.
type Zone struct {
ID int `json:"id"`
Name string `json:"name"`
IsPresent bool `json:"isPresent"`
FloorID int `json:"floorId"`
Devices []Device `json:"devices"`
Groups []Group `json:"groups"`
TemperatureControl *TemperatureControlState
}
// Floor contains Zones
type Floor struct {
ID int `json:"id"`
Order int `json:"order"`
Name string `json:"name"`
Zones []int `json:"zones"`
}
// Group is the representation of an application type
type Group struct {
ID int `json:"id"`
Name string `json:"name"`
Color int `json:"color"`
ApplicationType ApplicationType `json:"applicationType"`
IsPresent bool `json:"isPresent"`
IsValid bool `json:"isValid"`
Devices []string `json:"devices"`
}
// Circuit is the physical connection between the circuit breaker
// and digitalSTROM-Meter. For each circuit, the overall consumption
// and meter vaues could be received.
type Circuit struct {
Name string `json:"name"`
DSID string `json:"dsid"`
DSUID string `json:"dSUID"`
DisplayID string `json:"DisplayID"`
HwVersion int `json:"hwVersion"`
HwVersionString string `json:"hvVersionString"`
SwVersion string `json:"swVersion"`
ArmSwVersion int `json:"armSwVersion"`
DspSwVersion int `json:"dspSwVersion"`
IsUpToDate bool `json:"isUpToDate"`
APIVersion int `json:"apiVersion"`
Authorized bool `json:"authorized"`
HwName string `json:"HwName"`
IsPresent bool `json:"isPresent"`
IsValid bool `json:"isValid"`
BusMemberType int `json:"busMemberType"`
HasDevices bool `json:"hasDevices"`
HasMetering bool `json:"hasMetering"`
HasBlinking bool `json:"hasBlinking"`
VdcConfigURL string `json:"VdcConfigURL"`
VdcModelUID string `json:"VdcModelUID"`
VdcHardwareGUID string `json:"vdcHardwareGuid"`
VdcHardwareModelGUID string `json:"vdcHardwareModelGuid"`
VdcImplementationID string `json:"vdcImplementationId"`
VdcVendorGUID string `json:"vdcVendorGuid"`
VdcOemGUID string `json:"vdcOemGuid"`
IgnoreActionsFromNewDevices bool `json:"ignoreActionsFromNewDevices"`
Consumption int // not part of json, values have to be requested separately
MeterValue int // not part of json, values have to be requested separately
}
// Device ...
type Device struct {
ID string `json:"id"`
DisplayID string `json:"DisplayID"`
UUID string `json:"dSUID"`
Gtin string `json:"GTIN"`
Name string `json:"name"`
DsUIDIndex int `json:"dSUIDIndex"`
FunctionID int `json:"functionID"`
ProductRevision int `json:"productRevision"`
ProductID int `json:"productID"`
HwInfo string `json:"hwInfo"`
OemStatus string `json:"OemStatus"`
OemEanNumber string `json:"OemEanNumber"`
OemSerialNumber int `json:"OemSerialNumber"`
OemPartNumber int `json:"OemPartNumber"`
OemProductInfoState string `json:"OemProductInfoState"`
OemProductURL string `json:"OemProductURL"`
OemInternetState string `json:"OemInternetState"`
OemIsIndependent bool `json:"OemIsIndependent"`
//ModelFeatures ModelFeature `json:"modelFeatures"`
IsVdcDevice bool `json:"isVdcDevice"`
//SupportedBasicScenes []BasicScene
ButtonUsage string `json:"buttonUsage"`
MeterDSID string `json:"meterDSID"`
MeterDSUID string `json:"meterDSUID"`
MeterName string `json:"meterName"`
BusID int `json:"busID"`
ZoneID int `json:"zoneID"`
IsPresent bool `json:"isPresent"`
IsValid bool `json:"isValid"`
LastDiscovered string `json:"lastDiscovered"`
FirstSeen string `json:"firstSeen"`
InactiveSince string `json:"inactiveSince"`
On bool `json:"on"`
Locked bool `json:"locked"`
ConfigurationLocked bool `json:"configurationLocked"`
IgnoreOperationLock bool `json:"ignoreOperationLock"`
OutputMode int `json:"outputMode"`
ButtonID int `json:"buttonID"`
ButtonActiveGroup int `json:"buttonActiveGroup"`
ButtonGroupMemberShip int `json:"buttonMemberShip"`
ButtonInputMode int `json:"buttonInputMode"`
ButtonInputIndex int `json:"buttonInputIndex"`
ButtonInputCount int `json:"buttonInputCount"`
AKMInputProperty string `json:"AKMInputProperty"`
BinaryInputCount int `json:"binaryInputCount"`
BinaryInputs []*BinaryInput `json:"binaryInputs"`
SensorInputCount int `json:"sonsorInputCount"`
Sensors []*Sensor `json:"sensors"`
SensorDataValid bool `json:"sensorDataValid"`
OutputChannels []*OutputChannel `json:"outputChannels"`
PairedDevices []string `json:"pairedDevices"`
Groups []int `json:"groups"`
}
// BinaryInput ...
type BinaryInput struct {
TargetGroup int `json:"targetGroup"`
InputType BinaryInputType `json:"inputType"`
InputID int `json:"inputId"`
State int `json:"state"` // for generic: 1 = closed / 2 = open
}
// OutputChannel ....
type OutputChannel struct {
ChannelID string `json:"channelID"`
ChannelType OutputChannelType `json:"channelType"`
ChannelIndex int `json:"channelIndex"`
ChannelName string `json:"channelName"`
Value int
device *Device
}
// Sensor ...
type Sensor struct {
Type SensorType `json:"type"`
Valid bool `json:"valid"`
Value float64 `json:"value"`
Index int
device *Device
}
// System ...
type System struct {
Version string `json:"version"`
DistroVersion string `json:"distroVersion"`
EthernetID string `json:"EthernetID"`
Hardware string `json:"Hardware"`
Kernel string `json:"Kernel"`
Revision string `json:"Revision"`
Serial string `json:"Serial"`
}
// OutputChannelType ...
type OutputChannelType string
// ApplicationType ....
type ApplicationType int
// ApplicationColor ...
type ApplicationColor string
// BinaryInputType ...
type BinaryInputType int
// SensorType ...
type SensorType int
var binaryInputTypeNames = [...]string{
"Generic",
"Presence",
"Brightness",
"Presence",
"Twilight",
"Motion",
"Motion in darkness",
"Smoke",
"Wind strength above limit",
"Rain",
"Sun radiation",
"Temperature below limit",
"Battery status is low",
"Window is open",
"Door is open",
"Window is tilted",
"Garage door is open",
"Sun protection",
"Frost",
"Heating system enabled",
"Change-over signal",
"Initialization",
"Malfunction",
"Service"}
// Output Channel Types (OTC)
const (
OCTbrightness = OutputChannelType("brightness")
OCThue = OutputChannelType("hue")
OCTsaturation = OutputChannelType("saturation")
OCTcolortemp = OutputChannelType("colortemp")
OCTx = OutputChannelType("x")
OCTy = OutputChannelType("y")
OCTshadePositionOutside = OutputChannelType("shadePositionOutside")
OCTshadePositionIndoor = OutputChannelType("shadePositionIndoor")
OCTshadeOpeningAngleOutside = OutputChannelType("shadeOpeningAngleOutside")
OCTshadeOpeningAngleInside = OutputChannelType("shadeOpeningAngleInside")
OCTtransparency = OutputChannelType("transparency")
OCTairFlowIntensity = OutputChannelType("airFlowIntensity")
OCTairFlowDirection = OutputChannelType("airFlowDirection")
OCTairFlapPosition = OutputChannelType("airFlapPosition")
OCTairLouverPosition = OutputChannelType("airLouverPosition")
OCTheatingPower = OutputChannelType("heatingPower")
OCTcoolingCapacity = OutputChannelType("coolingCapacity")
OCTaudioVolume = OutputChannelType("audioVolume")
OCTpowerState = OutputChannelType("powerState")
OCTpowerLevel = OutputChannelType("powerLevel")
)
// Application Types
const (
ATlights ApplicationType = 1
ATblinds ApplicationType = 2
ATheating ApplicationType = 3
ATaudio ApplicationType = 4
ATvideo ApplicationType = 5
ATcooling ApplicationType = 9
ATventilation ApplicationType = 10
ATwindow ApplicationType = 11
ATrecirculation ApplicationType = 12
ATtemperatureControl ApplicationType = 48
ATapartmentVentilation ApplicationType = 64
ATsingleDevice ApplicationType = -1 // no id defined in specification
ATsecurity ApplicationType = -2 // no id defined in specification
ATaccess ApplicationType = -3 // no id defined in specification
)
// Available Colors
const (
ACwhite ApplicationColor = "white"
ACblack ApplicationColor = "black"
ACgreen ApplicationColor = "green"
ACgray ApplicationColor = "gray"
ACblue ApplicationColor = "blue"
ACcyan ApplicationColor = "cyan"
ACmagenta ApplicationColor = "magenta"
ACred ApplicationColor = "red"
)
// Binary Input Types
const (
BITgeneric BinaryInputType = 0
BITpresence BinaryInputType = 1
BITbrightness BinaryInputType = 2
BITpresenceInDarkness BinaryInputType = 3
BITtwilight BinaryInputType = 4
BITmotion BinaryInputType = 5
BITmotionInDarkness BinaryInputType = 6
BITsmoke BinaryInputType = 7
BITwindStrenghAboveLimit BinaryInputType = 8
BITrain BinaryInputType = 9
BITsunRadiation BinaryInputType = 10
BITtemperatureBelowLimit BinaryInputType = 11
BITBatteryStatusIsLow BinaryInputType = 12
BITwindowIsOpen BinaryInputType = 13
BITdoorIsOpen BinaryInputType = 14
BITwindowIsTilted BinaryInputType = 15
BITgarageDoorIsOpen BinaryInputType = 16
BITsunProtection BinaryInputType = 17
BITfrost BinaryInputType = 18
BITheatingSystemEnabled BinaryInputType = 19
BITchangeOverSignal BinaryInputType = 20
BITinitialization BinaryInputType = 21
BITmalfunction BinaryInputType = 22
BITservice BinaryInputType = 23
)
// SensorTypes
const (
STtemperature SensorType = 66
STrelativeHumidity SensorType = 68
STbrightness SensorType = 67
STsoundPressureLeve SensorType = 25
STroomTemperature SensorType = 9
STroomRelativeHumidity SensorType = 13
STroomBrightness SensorType = 11
STroomCarbonDioxideConcentration SensorType = 21
STroomCarbonMonoxideConcentration SensorType = 22
STroomTemperatureSetPoint SensorType = 50
STroomTemperatureControlVariable SensorType = 51
SToutdoorTemperature SensorType = 10
SToutdoorRelativeHumidity SensorType = 14
SToutdoorBrightness SensorType = 12
STairPressure SensorType = 15
STwindGustSpeed SensorType = 16
STwindGustDirection SensorType = 17
STwindSpeed SensorType = 18
STwindDirection SensorType = 19
STprecipitationIntensityOfLastHour SensorType = 20
STsunAzimuth SensorType = 76
STsunElevation SensorType = 77
STactivePower SensorType = 4
STapparentPower SensorType = 65
SToutputCurrent SensorType = 5
SToutputCurrentHighRange SensorType = 64
STelectricMeter SensorType = 6
STlength SensorType = 73
STmass SensorType = 74
STduration SensorType = 75
)
func (b BinaryInputType) String() string {
return fmt.Sprintf(" %d - %s", b.GetID(), b.GetName())
}
// GetID returns the id of the binary input type
func (b BinaryInputType) GetID() int {
return int(b)
}
// GetName returns the Name of the binary input type
func (b BinaryInputType) GetName() string {
if len(binaryInputTypeNames) < b.GetID() {
return "unknown binary input type"
}
return binaryInputTypeNames[b.GetID()]
}
// GetID returns the identifier for the application type
func (at ApplicationType) GetID() int {
return int(at)
}
// GetName returns the name of the application type
func (at ApplicationType) GetName() string {
switch at {
case ATlights:
return "lights"
case ATblinds:
return "blinds"
case ATheating:
return "heating"
case ATaudio:
return "audio"
case ATvideo:
return "video"
case ATcooling:
return "cooling"
case ATventilation:
return "ventilation"
case ATwindow:
return "window"
case ATrecirculation:
return "recirculation"
case ATtemperatureControl:
return "temperature control"
case ATapartmentVentilation:
return "apartment ventilation"
case ATsingleDevice:
return "single device"
case ATsecurity:
return "security"
case ATaccess:
return "access"
}
return "unknown application type"
}
func (st SensorType) IsUnknown() bool {
return st.GetName() == "Unknown SensorType"
}
// GetID returns the identifier of the sensor type
func (st SensorType) GetID() int {
return int(st)
}
// GetName returns a name of the sensor type
func (st SensorType) GetName() string {
switch st {
case STtemperature:
return "Temperature"
case STrelativeHumidity:
return "Relative Humidity"
case STbrightness:
return "Brightness"
case STsoundPressureLeve:
return "Sound Pressure"
case STroomTemperature:
return "Room Temperature"
case STroomRelativeHumidity:
return "Room Relative Humidity"
case STroomBrightness:
return "Room Brightness"
case STroomCarbonDioxideConcentration:
return "Room Carbon Dioxide Concentration"
case STroomCarbonMonoxideConcentration:
return "Room Carbon Monoxide Concentration"
case STroomTemperatureSetPoint:
return "Room Temperature Set-Point"
case STroomTemperatureControlVariable:
return "Room Temperature Control Variable"
case SToutdoorTemperature:
return "Outdoor Temperature"
case SToutdoorRelativeHumidity:
return "Outdoor Relative Humidity"
case SToutdoorBrightness:
return "Outdoor Brightness"
case STairPressure:
return "Air Pressure"
case STwindGustSpeed:
return "Wind Gust Speed"
case STwindGustDirection:
return "Wind Gust Direction"
case STwindSpeed:
return "Wind Speed"
case STwindDirection:
return "Wind Direction"
case STprecipitationIntensityOfLastHour:
return "Precipitation Intensity Of Last Hour"
case STsunAzimuth:
return "Sun Azimuth"
case STsunElevation:
return "Sun Elevation"
case STactivePower:
return "Active Power"
case STapparentPower:
return "Apperent Power"
case SToutputCurrent:
return "Output Current"
case SToutputCurrentHighRange:
return "Output Current (High Range)"
case STelectricMeter:
return "Electric Meter"
case STlength:
return "Length"
case STmass:
return "Mass"
case STduration:
return "Duration"
default:
return "Unknown SensorType"
}
}
func (d *Device) GetBinaryInputByInputID(inputId int) (*BinaryInput, error) {
for i := range d.BinaryInputs {
if d.BinaryInputs[i].InputID == inputId {
return d.BinaryInputs[i], nil
}
}
return nil, fmt.Errorf("device has no binaryInput with id %d", inputId)
}
// GetOutputChannel returns a corresponding channel with the given output channel type.
func (d *Device) GetOutputChannel(outputChannelType OutputChannelType) (*OutputChannel, error) {
for i := range d.OutputChannels {
if d.OutputChannels[i].ChannelType == outputChannelType {
return d.OutputChannels[i], nil
}
}
return nil, errors.New("device '" + d.DisplayID + "' has no output channel of application type '" + string(outputChannelType) + "'")
}
// GenerateApartment takes a json string and generates and returns an instance of structure Apartment
// or the error that may have occured.
func GenerateApartment(j string) (*Apartment, error) {
var apartement Apartment
err := json.Unmarshal([]byte(j), &apartement)
if err != nil {
return nil, err
}
return &apartement, nil
}
func (s *Structure) assignCrossReferences() {
for i := range s.Apartment.Zones {
for j := range s.Apartment.Zones[i].Devices {
device := s.Apartment.Zones[i].Devices[j]
for n := range device.Sensors {
device.Sensors[n].Index = n
device.Sensors[n].device = &device
}
for n := range device.OutputChannels {
device.OutputChannels[n].device = &device
}
}
}
}