forked from jimjibone/goopenzwave
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalues.go
554 lines (511 loc) · 21.9 KB
/
values.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
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
package goopenzwave
// #include "gzw_manager.h"
// #include "gzw_valueid.h"
// #include "zwbytes.h"
// #include "zwlist.h"
// #include <stdlib.h>
import "C"
import (
"fmt"
"unsafe"
)
// GetValueLabel returns the user-friendly label for the value.
func GetValueLabel(homeID uint32, valueID uint64) string {
cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID))
defer C.valueid_free(cvalueid)
cstr := C.manager_getValueLabel(cmanager, cvalueid)
gostr := C.GoString(cstr)
C.free(unsafe.Pointer(cstr))
return gostr
}
// SetValueLabel sets the user-friendly label for the value.
func SetValueLabel(homeID uint32, valueID uint64, value string) {
cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID))
defer C.valueid_free(cvalueid)
cstr := C.CString(value)
C.manager_setValueLabel(cmanager, cvalueid, cstr)
C.free(unsafe.Pointer(cstr))
}
// GetValueUnits returns the units that the value is measured in.
func GetValueUnits(homeID uint32, valueID uint64) string {
cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID))
defer C.valueid_free(cvalueid)
cstr := C.manager_getValueUnits(cmanager, cvalueid)
gostr := C.GoString(cstr)
C.free(unsafe.Pointer(cstr))
return gostr
}
// SetValueUnits sets the units that the value is measured in.
func SetValueUnits(homeID uint32, valueID uint64, value string) {
cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID))
defer C.valueid_free(cvalueid)
cstring := C.CString(value)
C.manager_setValueUnits(cmanager, cvalueid, cstring)
C.free(unsafe.Pointer(cstring))
}
// GetValueHelp returns a help string describing the value's purpose and usage.
func GetValueHelp(homeID uint32, valueID uint64) string {
cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID))
defer C.valueid_free(cvalueid)
cstr := C.manager_getValueHelp(cmanager, cvalueid)
gostr := C.GoString(cstr)
C.free(unsafe.Pointer(cstr))
return gostr
}
// SetValueHelp sets a help string describing the value's purpose and usage.
func SetValueHelp(homeID uint32, valueID uint64, value string) {
cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID))
defer C.valueid_free(cvalueid)
cstring := C.CString(value)
C.manager_setValueHelp(cmanager, cvalueid, cstring)
C.free(unsafe.Pointer(cstring))
}
// GetValueMin returns the minimum that this value may contain.
func GetValueMin(homeID uint32, valueID uint64) int32 {
cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID))
defer C.valueid_free(cvalueid)
return int32(C.manager_getValueMin(cmanager, cvalueid))
}
// GetValueMax returns the maximum that this value may contain.
func GetValueMax(homeID uint32, valueID uint64) int32 {
cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID))
defer C.valueid_free(cvalueid)
return int32(C.manager_getValueMax(cmanager, cvalueid))
}
// IsValueReadOnly returns true if the value is read-only.
func IsValueReadOnly(homeID uint32, valueID uint64) bool {
cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID))
defer C.valueid_free(cvalueid)
return bool(C.manager_isValueReadOnly(cmanager, cvalueid))
}
// IsValueWriteOnly returns true if the value is write-only.
func IsValueWriteOnly(homeID uint32, valueID uint64) bool {
cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID))
defer C.valueid_free(cvalueid)
return bool(C.manager_isValueWriteOnly(cmanager, cvalueid))
}
// IsValueSet returns true if the value has been set.
func IsValueSet(homeID uint32, valueID uint64) bool {
cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID))
defer C.valueid_free(cvalueid)
return bool(C.manager_isValueSet(cmanager, cvalueid))
}
// IsValuePolled returns true if the value is currently being polled.
func IsValuePolled(homeID uint32, valueID uint64) bool {
cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID))
defer C.valueid_free(cvalueid)
return bool(C.manager_isValuePolled(cmanager, cvalueid))
}
// GetValueAsBool returns the value as a bool. It will also return an error if
// the value is not a bool type.
func GetValueAsBool(homeID uint32, valueID uint64) (bool, error) {
cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID))
defer C.valueid_free(cvalueid)
var cbool C.bool
ok := bool(C.manager_getValueAsBool(cmanager, cvalueid, &cbool))
if ok == false {
return bool(cbool), fmt.Errorf("value is not of bool type")
}
return bool(cbool), nil
}
// GetValueAsByte returns the value as an 8-bit unsigned integer. It will also
// return an error if the value is not of byte type.
func GetValueAsByte(homeID uint32, valueID uint64) (byte, error) {
cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID))
defer C.valueid_free(cvalueid)
var cbyte C.uint8_t
ok := bool(C.manager_getValueAsByte(cmanager, cvalueid, &cbyte))
if ok == false {
return byte(cbyte), fmt.Errorf("value is not of byte type")
}
return byte(cbyte), nil
}
// GetValueAsFloat returns the value as a float. It will also return an error if
// the value is not a decimal type.
func GetValueAsFloat(homeID uint32, valueID uint64) (float32, error) {
cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID))
defer C.valueid_free(cvalueid)
var cfloat C.float
ok := bool(C.manager_getValueAsFloat(cmanager, cvalueid, &cfloat))
if ok == false {
return float32(cfloat), fmt.Errorf("value is not of decimal type")
}
return float32(cfloat), nil
}
// GetValueAsInt returns the value as a 32-bit signed integer. It will also
// return an error if the value is not of 32-bit signed integer type.
func GetValueAsInt(homeID uint32, valueID uint64) (int32, error) {
cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID))
defer C.valueid_free(cvalueid)
var cint C.int32_t
ok := bool(C.manager_getValueAsInt(cmanager, cvalueid, &cint))
if ok == false {
return int32(cint), fmt.Errorf("value is not of 32-bit signed integer type")
}
return int32(cint), nil
}
// GetValueAsShort returns the value as a 16-bit signed integer. It will also
// return an error if the value is not of 16-bit signed integer type.
func GetValueAsShort(homeID uint32, valueID uint64) (int16, error) {
cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID))
defer C.valueid_free(cvalueid)
var cshort C.int16_t
ok := bool(C.manager_getValueAsShort(cmanager, cvalueid, &cshort))
if ok == false {
return int16(cshort), fmt.Errorf("value is not of 16-bit signed integer type")
}
return int16(cshort), nil
}
// GetValueAsString returns the value as a string, regardless of its actual
// type.
func GetValueAsString(homeID uint32, valueID uint64) string {
cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID))
defer C.valueid_free(cvalueid)
var cstr *C.char
_ = C.manager_getValueAsString(cmanager, cvalueid, &cstr)
gostr := C.GoString(cstr)
C.free(unsafe.Pointer(cstr))
return gostr
}
// GetValueAsRaw returns the value as a raw byte slice. It will also return an
// error if the value is not of raw type.
func GetValueAsRaw(homeID uint32, valueID uint64) ([]byte, error) {
cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID))
defer C.valueid_free(cvalueid)
zwbytes := C.zwbytes_new()
ok := bool(C.manager_getValueAsRaw(cmanager, cvalueid, zwbytes))
if ok == false {
return nil, fmt.Errorf("value is not of raw type")
}
gobytes := make([]byte, zwbytes.size)
for i := 0; i < int(zwbytes.size); i++ {
gobytes[i] = byte(C.zwbytes_at(zwbytes, C.size_t(i)))
}
return gobytes, nil
}
// GetValueListSelectionAsString returns selected item from a list as a string.
// It will also return an error if the value is not of list type.
func GetValueListSelectionAsString(homeID uint32, valueID uint64) (string, error) {
cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID))
defer C.valueid_free(cvalueid)
var cstr *C.char
ok := bool(C.manager_getValueListSelectionAsString(cmanager, cvalueid, &cstr))
gostr := C.GoString(cstr)
C.free(unsafe.Pointer(cstr))
if ok == false {
return gostr, fmt.Errorf("value is not of list type")
}
return gostr, nil
}
// GetValueListSelectionAsInt32 returns selected item from a list as an integer.
// It will also return an error if the value is not of list type.
func GetValueListSelectionAsInt32(homeID uint32, valueID uint64) (int32, error) {
cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID))
defer C.valueid_free(cvalueid)
var cint C.int32_t
ok := bool(C.manager_getValueListSelectionAsInt32(cmanager, cvalueid, &cint))
if ok == false {
return int32(cint), fmt.Errorf("value is not of list type")
}
return int32(cint), nil
}
// GetValueListItems returns the list of items from a list value. It will also
// return an error if the value is not of list type.
func GetValueListItems(homeID uint32, valueID uint64) ([]string, error) {
cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID))
defer C.valueid_free(cvalueid)
var clist *C.zwlist_t
ok := bool(C.manager_getValueListItems(cmanager, cvalueid, &clist))
golist := make([]string, int(C.zwlist_size(clist)))
if ok == false {
return nil, fmt.Errorf("value is not of list type")
}
for i := 0; i < int(C.zwlist_size(clist)); i++ {
cstr := C.zwlist_at(clist, C.size_t(i))
golist[i] = C.GoString(cstr)
}
C.zwlist_free(clist)
return golist, nil
}
// GetValueFloatPrecision returns the float value's precision. It will also
// return an error if the value is not of decimal type.
func GetValueFloatPrecision(homeID uint32, valueID uint64) (uint8, error) {
cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID))
defer C.valueid_free(cvalueid)
var cprecision C.uint8_t
ok := bool(C.manager_getValueFloatPrecision(cmanager, cvalueid, &cprecision))
if ok == false {
return uint8(cprecision), fmt.Errorf("value is not of decimal type")
}
return uint8(cprecision), nil
}
// SetValueBool sets the state of a bool. It will return an error if the value
// is not of bool type.
//
// Due to the possibility of a device being asleep, the command is assumed to
// succeed, and the value held by the node is updated directly. This will be
// reverted by a future status message from the device if the Z-Wave message
// actually failed to get through. Notification callbacks will be sent in both
// cases.
func SetValueBool(homeID uint32, valueID uint64, value bool) error {
cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID))
defer C.valueid_free(cvalueid)
ok := bool(C.manager_setValueBool(cmanager, cvalueid, C.bool(value)))
if ok == false {
return fmt.Errorf("value is not of bool type")
}
return nil
}
// SetValueUint8 sets the value of a byte. It will return an error if the value
// is not of byte type.
//
// Due to the possibility of a device being asleep, the command is assumed to
// succeed, and the value held by the node is updated directly. This will be
// reverted by a future status message from the device if the Z-Wave message
// actually failed to get through. Notification callbacks will be sent in both
// cases.
func SetValueUint8(homeID uint32, valueID uint64, value uint8) error {
cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID))
defer C.valueid_free(cvalueid)
ok := bool(C.manager_setValueUint8(cmanager, cvalueid, C.uint8_t(value)))
if ok == false {
return fmt.Errorf("value is not of byte type")
}
return nil
}
// SetValueFloat sets the value of a decimal. It will return an error if the
// value is not of decimal type.
//
// It is usually better to handle decimal values using strings rather than
// floats, to avoid floating point accuracy issues. Due to the possibility of a
// device being asleep, the command is assumed to succeed, and the value held by
// the node is updated directly. This will be reverted by a future status
// message from the device if the Z-Wave message actually failed to get through.
// Notification callbacks will be sent in both cases.
func SetValueFloat(homeID uint32, valueID uint64, value float32) error {
cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID))
defer C.valueid_free(cvalueid)
ok := bool(C.manager_setValueFloat(cmanager, cvalueid, C.float(value)))
if ok == false {
return fmt.Errorf("value is not of decimal type")
}
return nil
}
// SetValueInt32 sets the value of a 32-bit signed integer. It will return an
// error if the value is not of 32-bit signed integer type.
//
// Due to the possibility of a device being asleep, the command is assumed to
// succeed, and the value held by the node is updated directly. This will be
// reverted by a future status message from the device if the Z-Wave message
// actually failed to get through. Notification callbacks will be sent in both
// cases.
func SetValueInt32(homeID uint32, valueID uint64, value int32) error {
cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID))
defer C.valueid_free(cvalueid)
ok := bool(C.manager_setValueInt32(cmanager, cvalueid, C.int32_t(value)))
if ok == false {
return fmt.Errorf("value is not of 32-bit signed integer type")
}
return nil
}
// SetValueInt16 sets the value of a 16-bit signed integer. It will return an
// error if the value is not of 16-bit signed integer type.
//
// Due to the possibility of a device being asleep, the command is assumed to
// succeed, and the value held by the node is updated directly. This will be
// reverted by a future status message from the device if the Z-Wave message
// actually failed to get through. Notification callbacks will be sent in both
// cases.
func SetValueInt16(homeID uint32, valueID uint64, value int16) error {
cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID))
defer C.valueid_free(cvalueid)
ok := bool(C.manager_setValueInt16(cmanager, cvalueid, C.int16_t(value)))
if ok == false {
return fmt.Errorf("value is not of 16-bit signed integer type")
}
return nil
}
// SetValueBytes sets the value of a raw value. It will return an error if the
// value is not of raw type.
//
// Due to the possibility of a device being asleep, the command is assumed to
// succeed, and the value held by the node is updated directly. This will be
// reverted by a future status message from the device if the Z-Wave message
// actually failed to get through. Notification callbacks will be sent in both
// cases.
func SetValueBytes(homeID uint32, valueID uint64, value []byte) error {
cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID))
defer C.valueid_free(cvalueid)
zwbytes := C.zwbytes_new()
C.zwbytes_reserve(zwbytes, C.size_t(len(value)))
for i := range value {
C.zwbytes_set(zwbytes, C.size_t(i), C.uint8_t(value[i]))
}
ok := bool(C.manager_setValueBytes(cmanager, cvalueid, zwbytes))
C.zwbytes_free(zwbytes)
if ok == false {
return fmt.Errorf("value is not of raw type")
}
return nil
}
// SetValueString sets the value from a string, regardless of type. It will
// return an error if the value could not be parsed into the correct type for
// the value.
//
// Due to the possibility of a device being asleep, the command is assumed to
// succeed, and the value held by the node is updated directly. This will be
// reverted by a future status message from the device if the Z-Wave message
// actually failed to get through. Notification callbacks will be sent in both
// cases.
func SetValueString(homeID uint32, valueID uint64, value string) error {
cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID))
defer C.valueid_free(cvalueid)
cstring := C.CString(value)
ok := bool(C.manager_setValueString(cmanager, cvalueid, cstring))
C.free(unsafe.Pointer(cstring))
if ok == false {
return fmt.Errorf("could not parse string into correct type for value")
}
return nil
}
// SetValueListSelection sets the selected item in a list. It will return an
// error if the value is not of list type or if the selection is not in the
// list.
//
// Due to the possibility of a device being asleep, the command is assumed to
// succeed, and the value held by the node is updated directly. This will be
// reverted by a future status message from the device if the Z-Wave message
// actually failed to get through. Notification callbacks will be sent in both
// cases.
func SetValueListSelection(homeID uint32, valueID uint64, selection string) error {
cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID))
defer C.valueid_free(cvalueid)
cstring := C.CString(selection)
ok := bool(C.manager_setValueListSelection(cmanager, cvalueid, cstring))
C.free(unsafe.Pointer(cstring))
if ok == false {
return fmt.Errorf("value is not of list type or selection is not in the list")
}
return nil
}
// RefreshValue refreshes the specified value from the Z-Wave network. It will
// return true if the driver and node were found, otherwise false.
//
// A call to this function causes the library to send a message to the network
// to retrieve the current value of the specified ValueID (just like a poll,
// except only one-time, not recurring).
func RefreshValue(homeID uint32, valueID uint64) bool {
cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID))
defer C.valueid_free(cvalueid)
return bool(C.manager_refreshValue(cmanager, cvalueid))
}
// SetChangeVerified sets a flag indicating whether value changes noted upon a
// refresh should be verified. If so, the library will immediately refresh the
// value a second time whenever a change is observed. This helps to filter out
// spurious data reported occasionally by some devices.
func SetChangeVerified(homeID uint32, valueID uint64, verify bool) {
cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID))
defer C.valueid_free(cvalueid)
C.manager_setChangeVerified(cmanager, cvalueid, C.bool(verify))
}
// GetChangeVerified returns true if value changes upon a refresh should be
// verified. If so, the library will immediately refresh the value a second time
// whenever a change is observed. This helps to filter out spurious data
// reported occasionally by some devices.
func GetChangeVerified(homeID uint32, valueID uint64) bool {
cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID))
defer C.valueid_free(cvalueid)
return bool(C.manager_getChangeVerified(cmanager, cvalueid))
}
// PressButton starts an activity in a device. It will return an error if the
// value is not of button type.
//
// Since buttons are write-only values that do not report a state, no
// notification callbacks are sent.
func PressButton(homeID uint32, valueID uint64) error {
cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID))
defer C.valueid_free(cvalueid)
ok := bool(C.manager_pressButton(cmanager, cvalueid))
if ok == false {
return fmt.Errorf("value is not of button type")
}
return nil
}
// ReleaseButton stops an activity in a device. It will return an error if the
// value is not of button type.
//
// Since buttons are write-only values that do not report a state, no
// notification callbacks are sent.
func ReleaseButton(homeID uint32, valueID uint64) error {
cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID))
defer C.valueid_free(cvalueid)
ok := bool(C.manager_releaseButton(cmanager, cvalueid))
if ok == false {
return fmt.Errorf("value is not of button type")
}
return nil
}
//
// Also, climate control schedules.
//
// GetNumSwitchPoints returns the number of switch points defined in a schedule.
// It will return zero if the value if not of schedule type.
func GetNumSwitchPoints(homeID uint32, valueID uint64) (uint8, error) {
cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID))
defer C.valueid_free(cvalueid)
result := uint8(C.manager_getNumSwitchPoints(cmanager, cvalueid))
if result == 0 {
return result, fmt.Errorf("value is not of schedule type")
}
return result, nil
}
// SetSwitchPoint sets a switch point in the schedule. It will return an error
// if the value is not of schedule type.
//
// Inserts a new switch point into the schedule, unless a switch point already
// exists at the specified time in which case that switch point is updated with
// the new setback value instead. A maximum of nine switch points can be set in
// the schedule.
func SetSwitchPoint(homeID uint32, valueID uint64, hours, minutes uint8, setback int8) error {
cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID))
defer C.valueid_free(cvalueid)
ok := bool(C.manager_setSwitchPoint(cmanager, cvalueid, C.uint8_t(hours), C.uint8_t(minutes), C.int8_t(setback)))
if ok == false {
return fmt.Errorf("value is not of schedule type")
}
return nil
}
// RemoveSwitchPoint removes a switch point from the schedule. It will return an
// error if the value is not of schedule type or there is no switch point with
// the specified time values.
func RemoveSwitchPoint(homeID uint32, valueID uint64, hours, minutes uint8) error {
cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID))
defer C.valueid_free(cvalueid)
ok := bool(C.manager_removeSwitchPoint(cmanager, cvalueid, C.uint8_t(hours), C.uint8_t(minutes)))
if ok == false {
return fmt.Errorf("value is not of schedule type or no switch point found with specified time values")
}
return nil
}
// ClearSwitchPoints clears all switch points from the schedule.
func ClearSwitchPoints(homeID uint32, valueID uint64) {
cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID))
defer C.valueid_free(cvalueid)
C.manager_clearSwitchPoints(cmanager, cvalueid)
}
// GetSwitchPoint returns switch point data from the schedule. It will also
// return an error if the value is not of schedule type.
//
// It retrieves the time and setback values from a switch point in the schedule.
func GetSwitchPoint(homeID uint32, valueID uint64, idx uint8) (uint8, uint8, int8, error) {
cvalueid := C.valueid_create(C.uint32_t(homeID), C.uint64_t(valueID))
defer C.valueid_free(cvalueid)
var chours C.uint8_t
var cminutes C.uint8_t
var csetback C.int8_t
ok := bool(C.manager_getSwitchPoint(cmanager, cvalueid, C.uint8_t(idx), &chours, &cminutes, &csetback))
if ok == false {
return uint8(chours), uint8(cminutes), int8(csetback), fmt.Errorf("value is not of schedule type")
}
return uint8(chours), uint8(cminutes), int8(csetback), nil
}