forked from muka/go-bluetooth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen_Attention1.go
231 lines (192 loc) · 5.87 KB
/
gen_Attention1.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
// Code generated by go-bluetooth generator DO NOT EDIT.
package mesh
import (
"sync"
"github.com/godbus/dbus/v5"
"github.com/muka/go-bluetooth/bluez"
"github.com/muka/go-bluetooth/props"
"github.com/muka/go-bluetooth/util"
)
var Attention1Interface = "org.bluez.mesh.Attention1"
// NewAttention1 create a new instance of Attention1
//
// Args:
// - servicePath: unique name
// - objectPath: freely definable
func NewAttention1(servicePath string, objectPath dbus.ObjectPath) (*Attention1, error) {
a := new(Attention1)
a.client = bluez.NewClient(
&bluez.Config{
Name: servicePath,
Iface: Attention1Interface,
Path: dbus.ObjectPath(objectPath),
Bus: bluez.SystemBus,
},
)
a.Properties = new(Attention1Properties)
_, err := a.GetProperties()
if err != nil {
return nil, err
}
return a, nil
}
/*
Attention1 Mesh Attention Hierarchy
*/
type Attention1 struct {
client *bluez.Client
propertiesSignal chan *dbus.Signal
objectManagerSignal chan *dbus.Signal
objectManager *bluez.ObjectManager
Properties *Attention1Properties
watchPropertiesChannel chan *dbus.Signal
}
// Attention1Properties contains the exposed properties of an interface
type Attention1Properties struct {
lock sync.RWMutex `dbus:"ignore"`
}
//Lock access to properties
func (p *Attention1Properties) Lock() {
p.lock.Lock()
}
//Unlock access to properties
func (p *Attention1Properties) Unlock() {
p.lock.Unlock()
}
// Close the connection
func (a *Attention1) Close() {
a.unregisterPropertiesSignal()
a.client.Disconnect()
}
// Path return Attention1 object path
func (a *Attention1) Path() dbus.ObjectPath {
return a.client.Config.Path
}
// Client return Attention1 dbus client
func (a *Attention1) Client() *bluez.Client {
return a.client
}
// Interface return Attention1 interface
func (a *Attention1) Interface() string {
return a.client.Config.Iface
}
// GetObjectManagerSignal return a channel for receiving updates from the ObjectManager
func (a *Attention1) GetObjectManagerSignal() (chan *dbus.Signal, func(), error) {
if a.objectManagerSignal == nil {
if a.objectManager == nil {
om, err := bluez.GetObjectManager()
if err != nil {
return nil, nil, err
}
a.objectManager = om
}
s, err := a.objectManager.Register()
if err != nil {
return nil, nil, err
}
a.objectManagerSignal = s
}
cancel := func() {
if a.objectManagerSignal == nil {
return
}
a.objectManagerSignal <- nil
a.objectManager.Unregister(a.objectManagerSignal)
a.objectManagerSignal = nil
}
return a.objectManagerSignal, cancel, nil
}
// ToMap convert a Attention1Properties to map
func (a *Attention1Properties) ToMap() (map[string]interface{}, error) {
return props.ToMap(a), nil
}
// FromMap convert a map to an Attention1Properties
func (a *Attention1Properties) FromMap(props map[string]interface{}) (*Attention1Properties, error) {
props1 := map[string]dbus.Variant{}
for k, val := range props {
props1[k] = dbus.MakeVariant(val)
}
return a.FromDBusMap(props1)
}
// FromDBusMap convert a map to an Attention1Properties
func (a *Attention1Properties) FromDBusMap(props map[string]dbus.Variant) (*Attention1Properties, error) {
s := new(Attention1Properties)
err := util.MapToStruct(s, props)
return s, err
}
// ToProps return the properties interface
func (a *Attention1) ToProps() bluez.Properties {
return a.Properties
}
// GetWatchPropertiesChannel return the dbus channel to receive properties interface
func (a *Attention1) GetWatchPropertiesChannel() chan *dbus.Signal {
return a.watchPropertiesChannel
}
// SetWatchPropertiesChannel set the dbus channel to receive properties interface
func (a *Attention1) SetWatchPropertiesChannel(c chan *dbus.Signal) {
a.watchPropertiesChannel = c
}
// GetProperties load all available properties
func (a *Attention1) GetProperties() (*Attention1Properties, error) {
a.Properties.Lock()
err := a.client.GetProperties(a.Properties)
a.Properties.Unlock()
return a.Properties, err
}
// SetProperty set a property
func (a *Attention1) SetProperty(name string, value interface{}) error {
return a.client.SetProperty(name, value)
}
// GetProperty get a property
func (a *Attention1) GetProperty(name string) (dbus.Variant, error) {
return a.client.GetProperty(name)
}
// GetPropertiesSignal return a channel for receiving udpdates on property changes
func (a *Attention1) GetPropertiesSignal() (chan *dbus.Signal, error) {
if a.propertiesSignal == nil {
s, err := a.client.Register(a.client.Config.Path, bluez.PropertiesInterface)
if err != nil {
return nil, err
}
a.propertiesSignal = s
}
return a.propertiesSignal, nil
}
// Unregister for changes signalling
func (a *Attention1) unregisterPropertiesSignal() {
if a.propertiesSignal != nil {
a.propertiesSignal <- nil
a.propertiesSignal = nil
}
}
// WatchProperties updates on property changes
func (a *Attention1) WatchProperties() (chan *bluez.PropertyChanged, error) {
return bluez.WatchProperties(a)
}
func (a *Attention1) UnwatchProperties(ch chan *bluez.PropertyChanged) error {
return bluez.UnwatchProperties(a, ch)
}
/*
SetTimer The element_index parameter is the element's index within the
node where the health server model is hosted.
The time parameter indicates how many seconds the attention
state shall be on.
PossibleErrors:
org.bluez.mesh.Error.NotSupported
*/
func (a *Attention1) SetTimer(element_index uint8, time uint16) error {
return a.client.Call("SetTimer", 0, element_index, time).Store()
}
/*
GetTimer The element parameter is the unicast address within the node
where the health server model is hosted.
Returns the number of seconds for how long the attention action
remains staying on.
PossibleErrors:
org.bluez.mesh.Error.NotSupported
*/
func (a *Attention1) GetTimer(element uint16) (uint16, error) {
var val0 uint16
err := a.client.Call("GetTimer", 0, element).Store(&val0)
return val0, err
}