forked from brutella/hc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
int.go
62 lines (49 loc) · 1.12 KB
/
int.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
package characteristic
import (
"net"
)
type Int struct {
*Characteristic
}
func NewInt(typ string) *Int {
number := NewCharacteristic(typ)
return &Int{number}
}
// SetValue sets a value
func (c *Int) SetValue(value int) {
c.UpdateValue(value)
}
func (c *Int) SetMinValue(value int) {
c.MinValue = value
}
func (c *Int) SetMaxValue(value int) {
c.MaxValue = value
}
func (c *Int) SetStepValue(value int) {
c.StepValue = value
}
// GetValue returns the value as int
func (c *Int) GetValue() int {
return c.Characteristic.GetValue().(int)
}
func (c *Int) GetMinValue() int {
return c.MinValue.(int)
}
func (c *Int) GetMaxValue() int {
return c.MaxValue.(int)
}
func (c *Int) GetStepValue() int {
return c.StepValue.(int)
}
// OnValueRemoteGet calls fn when the value was read by a client.
func (c *Int) OnValueRemoteGet(fn func() int) {
c.OnValueGet(func() interface{} {
return fn()
})
}
// OnValueRemoteUpdate calls fn when the value was updated by a client.
func (c *Int) OnValueRemoteUpdate(fn func(int)) {
c.OnValueUpdateFromConn(func(conn net.Conn, c *Characteristic, new, old interface{}) {
fn(new.(int))
})
}