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