@@ -153,7 +153,10 @@ public class Device {
153
153
// The first accessory must be aid 1
154
154
accessories [ 0 ] . aid = 1
155
155
156
- addAccessories ( accessories)
156
+ addToAccessoryList ( accessories)
157
+
158
+ // Write configuration data to persist updated aid's and notify listeners
159
+ updatedConfiguration ( )
157
160
}
158
161
159
162
private func persistConfig( ) {
@@ -188,7 +191,7 @@ public class Device {
188
191
/// It is an error to try and add accessories with duplicate serial numbers.
189
192
/// It is an error to try and add accessories to a non-bridge device.
190
193
/// It is an error to try and increase the number of accessories above 99.
191
- public func addAccessories ( _ newAccessories: [ Accessory ] ) {
194
+ private func addToAccessoryList ( _ newAccessories: [ Accessory ] ) {
192
195
let totalNumberOfAccessories = accessories. count + newAccessories. count
193
196
precondition (
194
197
( isBridge && totalNumberOfAccessories <= 100 ) ||
@@ -231,12 +234,24 @@ public class Device {
231
234
configuration. aidForAccessorySerialNumber [ serialNumber] = accessory. aid
232
235
}
233
236
}
237
+ }
238
+
239
+ /// Add an array of accessories to this bridge device, and notify changes
240
+ ///
241
+ /// It is an error to try and add accessories with duplicate serial numbers.
242
+ /// It is an error to try and add accessories to a non-bridge device.
243
+ /// It is an error to try and increase the number of accessories above 99.
244
+ public func addAccessories( _ newAccessories: [ Accessory ] ) {
245
+
246
+ addToAccessoryList ( newAccessories)
247
+
248
+ delegate? . didChangeAccessoryList ( )
234
249
235
250
// Write configuration data to persist updated aid's and notify listeners
236
251
updatedConfiguration ( )
237
252
}
238
253
239
- /// When a configuration changes
254
+ /// If a configuration has changed
240
255
/// - update the configuration number
241
256
/// - write the configuration to storage
242
257
/// - notify interested parties of the change
@@ -245,13 +260,14 @@ public class Device {
245
260
if newStableHash != configuration. stableHash {
246
261
configuration. number = configuration. number &+ 1
247
262
configuration. stableHash = newStableHash
248
- }
249
- if configuration. number < 1 {
250
- configuration. number = 1
251
- }
252
263
253
- persistConfig ( )
254
- notifyConfigurationChange ( )
264
+ if configuration. number < 1 {
265
+ configuration. number = 1
266
+ }
267
+
268
+ persistConfig ( )
269
+ notifyConfigurationChange ( )
270
+ }
255
271
}
256
272
257
273
/// Generate uniqueness hash for device configuration, used to determine
@@ -292,6 +308,8 @@ public class Device {
292
308
configuration. aidForAccessorySerialNumber. removeValue ( forKey: serialNumber)
293
309
}
294
310
}
311
+ delegate? . didChangeAccessoryList ( )
312
+
295
313
// write configuration data to persist updated aid's
296
314
updatedConfiguration ( )
297
315
}
0 commit comments