-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathaccessory_door.go
executable file
·101 lines (90 loc) · 2.85 KB
/
accessory_door.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
package homekit
import (
"github.com/brutella/hap/accessory"
haps "github.com/xxandev/homekit/hap-service"
)
//AccessoryDoor struct
type AccessoryDoor struct {
*accessory.A
Door *haps.Door
}
func (acc *AccessoryDoor) GetType() byte {
return acc.A.Type
}
func (acc *AccessoryDoor) GetID() uint64 {
return acc.A.Id
}
func (acc *AccessoryDoor) SetID(id uint64) {
acc.A.Id = id
}
func (acc *AccessoryDoor) GetSN() string {
return acc.A.Info.SerialNumber.Value()
}
func (acc *AccessoryDoor) GetName() string {
return acc.A.Info.Name.Value()
}
func (acc *AccessoryDoor) GetAccessory() *accessory.A {
return acc.A
}
//NewAccessoryDoor returns *Door.
// (COMPATIBILITY) - left for compatibility, recommended NewAcc...(id, info, args..)
//
// info (accessory.Info) - struct accessory.Info{Name, SerialNumber, Manufacturer, Model, Firmware string}
// args[0](int) - TargetPosition.SetValue(args[0]) default(0)
// args[1](int) - TargetPosition.SetMinValue(args[1]) default(0)
// args[2](int) - TargetPosition.SetMaxValue(args[2]) default(100)
// args[3](int) - TargetPosition.SetStepValue(args[3]) default(1)
func NewAccessoryDoor(info accessory.Info, args ...interface{}) *AccessoryDoor {
acc := AccessoryDoor{}
acc.A = accessory.New(info, accessory.TypeDoor)
acc.Door = haps.NewDoor()
n := len(args)
if n > 0 {
acc.Door.TargetPosition.SetValue(toi(args[0], 0))
}
if n > 1 {
acc.Door.TargetPosition.SetMinValue(toi(args[1], 0))
}
if n > 2 {
acc.Door.TargetPosition.SetMaxValue(toi(args[2], 100))
}
if n > 3 {
acc.Door.TargetPosition.SetStepValue(toi(args[3], 1))
}
acc.AddS(acc.Door.S)
return &acc
}
//NewAccDoor returns *Door.
// HomeKit requires that every accessory has a unique id, which must not change between system restarts.
// The best would be to specify the unique id for every accessory yourself.
//
// id (uint64) - accessory aid
// info (accessory.Info) - struct accessory.Info{Name, SerialNumber, Manufacturer, Model, Firmware string}
// args[0](int) - TargetPosition.SetValue(args[0]) default(0)
// args[1](int) - TargetPosition.SetMinValue(args[1]) default(0)
// args[2](int) - TargetPosition.SetMaxValue(args[2]) default(100)
// args[3](int) - TargetPosition.SetStepValue(args[3]) default(1)
func NewAccDoor(id uint64, info accessory.Info, args ...interface{}) *AccessoryDoor {
acc := AccessoryDoor{}
acc.A = accessory.New(info, accessory.TypeDoor)
acc.Door = haps.NewDoor()
n := len(args)
if n > 0 {
acc.Door.TargetPosition.SetValue(toi(args[0], 0))
}
if n > 1 {
acc.Door.TargetPosition.SetMinValue(toi(args[1], 0))
}
if n > 2 {
acc.Door.TargetPosition.SetMaxValue(toi(args[2], 100))
}
if n > 3 {
acc.Door.TargetPosition.SetStepValue(toi(args[3], 1))
}
acc.AddS(acc.Door.S)
acc.A.Id = id
return &acc
}
func (acc *AccessoryDoor) OnValuesRemoteUpdates(fn func()) {
acc.Door.TargetPosition.OnValueRemoteUpdate(func(int) { fn() })
}