forked from brutella/hc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bool.go
40 lines (32 loc) · 815 Bytes
/
bool.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
package characteristic
import (
"net"
)
type Bool struct {
*Characteristic
}
func NewBool(typ string) *Bool {
number := NewCharacteristic(typ)
number.Format = FormatBool
return &Bool{number}
}
// SetValue sets a value
func (c *Bool) SetValue(value bool) {
c.UpdateValue(value)
}
// GetValue returns the value as bool
func (c *Bool) GetValue() bool {
return c.Characteristic.GetValue().(bool)
}
// OnValueRemoteGet calls fn when the value was read by a client.
func (c *Bool) OnValueRemoteGet(fn func() bool) {
c.OnValueGet(func() interface{} {
return fn()
})
}
// OnValueRemoteUpdate calls fn when the value was updated by a client.
func (c *Bool) OnValueRemoteUpdate(fn func(bool)) {
c.OnValueUpdateFromConn(func(conn net.Conn, c *Characteristic, new, old interface{}) {
fn(new.(bool))
})
}