]> git.basschouten.com Git - openhab-addons.git/blob
35b5f26d79cb5b323f9bef1542891810e50c71f4
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.io.homekit.internal;
14
15 import java.lang.reflect.InvocationTargetException;
16 import java.time.Clock;
17 import java.time.Duration;
18 import java.util.ArrayList;
19 import java.util.Collection;
20 import java.util.HashMap;
21 import java.util.HashSet;
22 import java.util.List;
23 import java.util.Map;
24 import java.util.Map.Entry;
25 import java.util.Optional;
26 import java.util.Set;
27 import java.util.concurrent.ExecutionException;
28 import java.util.concurrent.ScheduledExecutorService;
29 import java.util.stream.Collectors;
30
31 import org.eclipse.jdt.annotation.NonNullByDefault;
32 import org.eclipse.jdt.annotation.Nullable;
33 import org.openhab.core.common.ThreadPoolManager;
34 import org.openhab.core.common.registry.RegistryChangeListener;
35 import org.openhab.core.items.GroupItem;
36 import org.openhab.core.items.Item;
37 import org.openhab.core.items.ItemNotFoundException;
38 import org.openhab.core.items.ItemRegistry;
39 import org.openhab.core.items.ItemRegistryChangeListener;
40 import org.openhab.core.items.Metadata;
41 import org.openhab.core.items.MetadataKey;
42 import org.openhab.core.items.MetadataRegistry;
43 import org.openhab.core.storage.Storage;
44 import org.openhab.io.homekit.internal.accessories.AbstractHomekitAccessoryImpl;
45 import org.openhab.io.homekit.internal.accessories.DummyHomekitAccessory;
46 import org.openhab.io.homekit.internal.accessories.HomekitAccessoryFactory;
47 import org.slf4j.Logger;
48 import org.slf4j.LoggerFactory;
49
50 import io.github.hapjava.accessories.HomekitAccessory;
51 import io.github.hapjava.characteristics.impl.common.NameCharacteristic;
52 import io.github.hapjava.server.impl.HomekitRoot;
53
54 /**
55  * Listens for changes to the item and metadata registry. When changes are detected, check
56  * for HomeKit tags and, if present, add the items to the HomekitAccessoryRegistry.
57  *
58  * @author Andy Lintner - Initial contribution
59  */
60 @NonNullByDefault
61 public class HomekitChangeListener implements ItemRegistryChangeListener {
62     private final Logger logger = LoggerFactory.getLogger(HomekitChangeListener.class);
63     private static final String REVISION_CONFIG = "revision";
64     private static final String ACCESSORY_COUNT = "accessory_count";
65     private static final String KNOWN_ACCESSORIES = "known_accessories";
66     private final ItemRegistry itemRegistry;
67     private final HomekitAccessoryRegistry accessoryRegistry = new HomekitAccessoryRegistry();
68     private final MetadataRegistry metadataRegistry;
69     private final Storage<Object> storage;
70     private final RegistryChangeListener<Metadata> metadataChangeListener;
71     private HomekitAccessoryUpdater updater = new HomekitAccessoryUpdater();
72     private HomekitSettings settings;
73     private int lastAccessoryCount;
74     private Map<String, String> knownAccessories = new HashMap<>();
75     private int instance;
76     private List<String> priorDummies = new ArrayList<>();
77
78     private final Set<String> pendingUpdates = new HashSet<>();
79
80     private final ScheduledExecutorService scheduler = ThreadPoolManager
81             .getScheduledPool(ThreadPoolManager.THREAD_POOL_NAME_COMMON);
82
83     /**
84      * Rather than reacting to item added/removed/modified changes directly, we mark them as dirty (and the groups to
85      * which they belong)
86      *
87      * We wait for a second to pass until no more items are changed. This allows us to add a group of items all at once,
88      * rather than for each update at a time, preventing us from showing an error message with each addition until the
89      * group is complete.
90      */
91     private final Debouncer applyUpdatesDebouncer;
92
93     HomekitChangeListener(ItemRegistry itemRegistry, HomekitSettings settings, MetadataRegistry metadataRegistry,
94             Storage<Object> storage, int instance) {
95         this.itemRegistry = itemRegistry;
96         this.settings = settings;
97         this.metadataRegistry = metadataRegistry;
98         this.storage = storage;
99         this.instance = instance;
100         this.applyUpdatesDebouncer = new Debouncer("update-homekit-devices-" + instance, scheduler,
101                 Duration.ofMillis(1000), Clock.systemUTC(), this::applyUpdates);
102         metadataChangeListener = new RegistryChangeListener<Metadata>() {
103             @Override
104             public void added(final Metadata metadata) {
105                 final MetadataKey uid = metadata.getUID();
106                 if (HomekitAccessoryFactory.METADATA_KEY.equalsIgnoreCase(uid.getNamespace())) {
107                     try {
108                         markDirty(itemRegistry.getItem(uid.getItemName()));
109                     } catch (ItemNotFoundException e) {
110                         logger.trace("Could not find item for metadata {}", metadata);
111                     }
112                 }
113             }
114
115             @Override
116             public void removed(final Metadata metadata) {
117                 final MetadataKey uid = metadata.getUID();
118                 if (HomekitAccessoryFactory.METADATA_KEY.equalsIgnoreCase(uid.getNamespace())) {
119                     try {
120                         markDirty(itemRegistry.getItem(uid.getItemName()));
121                     } catch (ItemNotFoundException e) {
122                         logger.trace("Could not find item for metadata {}", metadata);
123                     }
124                 }
125             }
126
127             @Override
128             public void updated(final Metadata oldMetadata, final Metadata newMetadata) {
129                 final MetadataKey oldUid = oldMetadata.getUID();
130                 final MetadataKey newUid = newMetadata.getUID();
131                 if (HomekitAccessoryFactory.METADATA_KEY.equalsIgnoreCase(oldUid.getNamespace())
132                         || HomekitAccessoryFactory.METADATA_KEY.equalsIgnoreCase(newUid.getNamespace())) {
133                     try {
134                         // the item name is same in old and new metadata, so we can take any.
135                         markDirty(itemRegistry.getItem(oldUid.getItemName()));
136                     } catch (ItemNotFoundException e) {
137                         logger.debug("Could not find item for metadata {}", oldMetadata);
138                     }
139                 }
140             }
141         };
142         itemRegistry.addRegistryChangeListener(this);
143         metadataRegistry.addRegistryChangeListener(metadataChangeListener);
144         initialiseRevision();
145         boolean changed = false;
146         for (var i : itemRegistry.getItems()) {
147             String oldValue = knownAccessories.get(i.getName());
148             createRootAccessories(i);
149             if (accessoryChanged(i.getName(), oldValue)) {
150                 logger.debug("Accessory {} changed:\n{}\n{}", i.getName(), oldValue, knownAccessories.get(i.getName()));
151                 changed = true;
152             }
153         }
154         // order of this conditional is important - checkMissingAccessories has side effects that need to always happen
155         if (checkMissingAccessories() || changed) {
156             makeNewConfigurationRevision();
157         } else {
158             logger.info("Created {} HomeKit items in instance {} (no change from prior configuration).",
159                     accessoryRegistry.getAllAccessories().size(), instance);
160             if (settings.useDummyAccessories) {
161                 checkForDummyAccessories();
162             }
163         }
164     }
165
166     private void initialiseRevision() {
167         int revision = 1;
168         try {
169             String revisionString = (String) storage.get(REVISION_CONFIG);
170             if (revisionString == null) {
171                 throw new NumberFormatException();
172             }
173             revision = Integer.parseInt(revisionString);
174         } catch (NumberFormatException e) {
175         }
176         accessoryRegistry.setConfigurationRevision(revision);
177
178         lastAccessoryCount = 0;
179         var localKnownAccessories = (Map<String, String>) storage.get(KNOWN_ACCESSORIES);
180         if (localKnownAccessories == null) {
181             knownAccessories = new HashMap<>();
182             // Back-compat
183             try {
184                 String accessoryCountString = (String) storage.get(ACCESSORY_COUNT);
185                 if (accessoryCountString == null) {
186                     throw new NumberFormatException();
187                 }
188                 lastAccessoryCount = Integer.parseInt(accessoryCountString);
189             } catch (NumberFormatException e) {
190             }
191         } else {
192             knownAccessories = localKnownAccessories;
193             lastAccessoryCount = knownAccessories.size();
194         }
195     }
196
197     private boolean hasHomeKitMetadata(Item item) {
198         return metadataRegistry.get(new MetadataKey(HomekitAccessoryFactory.METADATA_KEY, item.getUID())) != null;
199     }
200
201     @Override
202     public synchronized void added(Item item) {
203         if (hasHomeKitMetadata(item)) {
204             markDirty(item);
205         }
206     }
207
208     @Override
209     public void allItemsChanged(Collection<String> oldItemNames) {
210         clearAccessories();
211     }
212
213     /**
214      * Mark an item as dirty, plus any accessory groups to which it pertains, so that after a debounce period the
215      * accessory update can be applied.
216      *
217      * @param item The item that has been changed or removed.
218      */
219     private synchronized void markDirty(Item item) {
220         logger.trace("Mark dirty item {}", item.getName());
221         pendingUpdates.add(item.getName());
222         /*
223          * If findMyAccessoryGroups fails because the accessory group has already been deleted, then we can count on a
224          * later update telling us that the accessory group was removed.
225          */
226         for (Item accessoryGroup : HomekitAccessoryFactory.getAccessoryGroups(item, itemRegistry, metadataRegistry)) {
227             pendingUpdates.add(accessoryGroup.getName());
228         }
229
230         /*
231          * if metadata of a group item was changed, mark all group member as dirty.
232          */
233         if (item instanceof GroupItem) {
234             ((GroupItem) item).getMembers().forEach(groupMember -> pendingUpdates.add(groupMember.getName()));
235         }
236         applyUpdatesDebouncer.call();
237     }
238
239     @Override
240     public synchronized void removed(Item item) {
241         if (hasHomeKitMetadata(item)) {
242             markDirty(item);
243         }
244     }
245
246     private Optional<Item> getItemOptional(String name) {
247         try {
248             return Optional.of(itemRegistry.getItem(name));
249         } catch (ItemNotFoundException e) {
250             return Optional.empty();
251         }
252     }
253
254     public void makeNewConfigurationRevision() {
255         final int newRevision = accessoryRegistry.makeNewConfigurationRevision();
256         lastAccessoryCount = accessoryRegistry.getAllAccessories().size();
257         logger.info("Created {} HomeKit items in instance {}.", accessoryRegistry.getAllAccessories().size(), instance);
258         logger.trace("Making new configuration revision {}", newRevision);
259         storage.put(REVISION_CONFIG, "" + newRevision);
260         storage.put(KNOWN_ACCESSORIES, knownAccessories);
261     }
262
263     public synchronized void pruneDummyAccessories() {
264         boolean removed = false;
265         for (HomekitAccessory accessory : accessoryRegistry.getAllAccessories().values()
266                 .toArray(new HomekitAccessory[0])) {
267             if (accessory instanceof DummyHomekitAccessory) {
268                 try {
269                     String name = accessory.getName().get();
270                     logger.info("Pruning dummy accessory {}.", name);
271                     knownAccessories.remove(name);
272                     accessoryRegistry.remove(name);
273                     removed = true;
274                 } catch (ExecutionException | InterruptedException e) {
275                     // will never happen; it's a always completed future
276                 }
277             }
278         }
279         if (removed) {
280             makeNewConfigurationRevision();
281         }
282     }
283
284     private synchronized void applyUpdates() {
285         logger.trace("Apply updates");
286
287         HomekitRoot bridge = accessoryRegistry.getBridge();
288         if (bridge != null) {
289             bridge.batchUpdate();
290         }
291
292         try {
293             boolean changed = false;
294             for (final String name : pendingUpdates) {
295                 String oldValue = knownAccessories.get(name);
296                 accessoryRegistry.remove(name);
297                 logger.trace(" Add items {}", name);
298                 getItemOptional(name).ifPresent(this::createRootAccessories);
299                 if (accessoryChanged(name, oldValue)) {
300                     changed = true;
301                 }
302             }
303             pendingUpdates.clear();
304             if (checkMissingAccessories() || changed) {
305                 makeNewConfigurationRevision();
306             }
307             checkForDummyAccessories();
308         } finally {
309             if (bridge != null) {
310                 bridge.completeUpdateBatch();
311             }
312         }
313     }
314
315     private boolean accessoryChanged(String name, @Nullable String oldValue) {
316         String newValue = knownAccessories.get(name);
317         if (oldValue == null && newValue == null) {
318             return false;
319         }
320         return oldValue == null && newValue != null || oldValue != null && newValue == null
321                 || !oldValue.equals(newValue);
322     }
323
324     @Override
325     public void updated(Item oldElement, Item element) {
326         markDirty(oldElement);
327         markDirty(element);
328     }
329
330     public int getLastAccessoryCount() {
331         return lastAccessoryCount;
332     }
333
334     public synchronized void clearAccessories() {
335         accessoryRegistry.clear();
336     }
337
338     public synchronized void setBridge(HomekitRoot bridge) {
339         accessoryRegistry.setBridge(bridge);
340     }
341
342     public void setUpdater(HomekitAccessoryUpdater updater) {
343         this.updater = updater;
344     }
345
346     public void updateSettings(HomekitSettings settings) {
347         boolean wasUsingDummyAccessories = this.settings.useDummyAccessories;
348         this.settings = settings;
349         // If they turned off dummy accessories, immediately prune them
350         if (wasUsingDummyAccessories && !settings.useDummyAccessories) {
351             pruneDummyAccessories();
352         }
353     }
354
355     public synchronized void stop() {
356         this.itemRegistry.removeRegistryChangeListener(this);
357         this.metadataRegistry.removeRegistryChangeListener(metadataChangeListener);
358         applyUpdatesDebouncer.stop();
359         accessoryRegistry.unsetBridge();
360     }
361
362     public Map<String, HomekitAccessory> getAccessories() {
363         return this.accessoryRegistry.getAllAccessories();
364     }
365
366     public int getConfigurationRevision() {
367         return this.accessoryRegistry.getConfigurationRevision();
368     }
369
370     /**
371      * select primary accessory type from list of types.
372      * selection logic:
373      * - if accessory has only one type, it is the primary type
374      * - if accessory has no primary type defined per configuration, then the first type on the list is the primary type
375      * - if accessory has primary type defined per configuration and this type is on the list of types, then it is the
376      * primary
377      * - if accessory has primary type defined per configuration and this type is NOT on the list of types, then the
378      * first type on the list is the primary type
379      *
380      * @param item openhab item
381      * @param accessoryTypes list of accessory type attached to the item
382      * @return primary accessory type
383      */
384     private HomekitAccessoryType getPrimaryAccessoryType(Item item,
385             List<Entry<HomekitAccessoryType, HomekitCharacteristicType>> accessoryTypes,
386             @Nullable Map<String, Object> configuration) {
387         if (accessoryTypes.size() > 1 && configuration != null) {
388             final @Nullable Object value = configuration.get(HomekitTaggedItem.PRIMARY_SERVICE);
389             if (value instanceof String) {
390                 return accessoryTypes.stream()
391                         .filter(aType -> ((String) value).equalsIgnoreCase(aType.getKey().getTag())).findAny()
392                         .orElse(accessoryTypes.get(0)).getKey();
393             }
394         }
395         // no primary accessory found or there is only one type, so return the first type from the list
396         return accessoryTypes.get(0).getKey();
397     }
398
399     /**
400      * creates one or more HomeKit items for given openhab item.
401      * one OpenHAB item can be linked to several HomeKit accessories.
402      * OpenHAB item is a good candidate for a HomeKit accessory
403      * IF
404      * - it has HomeKit accessory types defined using HomeKit accessory metadata
405      * - AND is not part of a group with HomeKit metadata
406      * e.g.
407      * Switch light "Light" {homekit="Lighting"}
408      * Group gLight "Light Group" {homekit="Lighting"}
409      *
410      * OR
411      * - it has HomeKit accessory types defined using HomeKit accessory metadata
412      * - AND is part of groups with HomeKit metadata, but all groups have baseItem
413      * e.g.
414      * Group:Switch:OR(ON,OFF) gLight "Light Group " {homekit="Lighting"}
415      * Switch light "Light" (gLight) {homekit="Lighting.OnState"}
416      *
417      *
418      * In contrast, items which are part of groups without BaseItem are additional HomeKit characteristics of the
419      * accessory defined by that group and don't need to be created as accessory here.
420      * e.g.
421      * Group gLight "Light Group " {homekit="Lighting"}
422      * Switch light "Light" (gLight) {homekit="Lighting.OnState"}
423      * is not the root accessory but only a characteristic "OnState"
424      *
425      * Examples:
426      * // Single line HomeKit Accessory
427      * Switch light "Light" {homekit="Lighting"}
428      *
429      * // One HomeKit accessory defined using group
430      * Group gLight "Light Group" {homekit="Lighting"}
431      * Switch light "Light" (gLight) {homekit="Lighting.OnState"}
432      *
433      * // 2 HomeKit accessories: one is switch attached to group, another one a single switch
434      * Group:Switch:OR(ON,OFF) gLight "Light Group " {homekit="Lighting"}
435      * Switch light "Light" (gLight) {homekit="Lighting.OnState"}
436      *
437      * @param item openHAB item
438      */
439     private void createRootAccessories(Item item) {
440         final List<Entry<HomekitAccessoryType, HomekitCharacteristicType>> accessoryTypes = HomekitAccessoryFactory
441                 .getAccessoryTypes(item, metadataRegistry);
442         if (accessoryTypes.isEmpty()) {
443             return;
444         }
445
446         final List<GroupItem> groups = HomekitAccessoryFactory.getAccessoryGroups(item, itemRegistry, metadataRegistry);
447         // Don't create accessories that are sub-accessories of other accessories
448         if (groups.stream().anyMatch(g -> !HomekitAccessoryFactory.getAccessoryTypes(g, metadataRegistry).isEmpty())) {
449             return;
450         }
451
452         final @Nullable Map<String, Object> itemConfiguration = HomekitAccessoryFactory.getItemConfiguration(item,
453                 metadataRegistry);
454         if (!itemIsForThisBridge(item, itemConfiguration)) {
455             return;
456         }
457
458         final HomekitAccessoryType primaryAccessoryType = getPrimaryAccessoryType(item, accessoryTypes,
459                 itemConfiguration);
460         logger.trace("Item {} is a HomeKit accessory of types {}. Primary type is {}", item.getName(), accessoryTypes,
461                 primaryAccessoryType);
462         final HomekitOHItemProxy itemProxy = new HomekitOHItemProxy(item);
463         final HomekitTaggedItem taggedItem = new HomekitTaggedItem(itemProxy, primaryAccessoryType, itemConfiguration);
464         try {
465             final AbstractHomekitAccessoryImpl accessory = HomekitAccessoryFactory.create(taggedItem, metadataRegistry,
466                     updater, settings);
467             if (accessory.isLinkedServiceOnly()) {
468                 logger.warn("Item '{}' is a '{}' which must be nested another another accessory.", taggedItem.getName(),
469                         primaryAccessoryType);
470                 return;
471             }
472
473             accessoryTypes.stream().filter(aType -> !primaryAccessoryType.equals(aType.getKey()))
474                     .forEach(additionalAccessoryType -> {
475                         final HomekitTaggedItem additionalTaggedItem = new HomekitTaggedItem(itemProxy,
476                                 additionalAccessoryType.getKey(), itemConfiguration);
477                         try {
478                             final AbstractHomekitAccessoryImpl additionalAccessory = HomekitAccessoryFactory
479                                     .create(additionalTaggedItem, metadataRegistry, updater, settings);
480                             // Secondary accessories that don't explicitly specify a name will implicitly
481                             // get a name characteristic based on the item's name
482                             if (!additionalAccessory.getCharacteristic(HomekitCharacteristicType.NAME).isPresent()) {
483                                 try {
484                                     additionalAccessory.addCharacteristic(
485                                             new NameCharacteristic(() -> additionalAccessory.getName()));
486                                 } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
487                                     // This should never happen; all services should support NameCharacteristic as an
488                                     // optional Characteristic.
489                                     // If HAP-Java defined a service that doesn't support
490                                     // addOptionalCharacteristic(NameCharacteristic), then it's a bug there, and we're
491                                     // just going to ignore the exception here.
492                                 }
493                             }
494                             accessory.getServices().add(additionalAccessory.getPrimaryService());
495                         } catch (HomekitException e) {
496                             logger.warn("Cannot create additional accessory {}", additionalTaggedItem);
497                         }
498                     });
499             knownAccessories.put(taggedItem.getName(), accessory.toJson());
500             accessoryRegistry.addRootAccessory(taggedItem.getName(), accessory);
501         } catch (HomekitException e) {
502             logger.warn("Cannot create accessory {}", taggedItem);
503         }
504     }
505
506     private boolean itemIsForThisBridge(Item item, @Nullable Map<String, Object> configuration) {
507         // non-tagged accessories belong to the first instance
508         if (configuration == null) {
509             return (instance == 1);
510         }
511
512         final @Nullable Object value = configuration.get(HomekitTaggedItem.INSTANCE);
513         if (value == null) {
514             return (instance == 1);
515         }
516         if (value instanceof Number) {
517             return (instance == ((Number) value).intValue());
518         }
519         logger.warn("Unrecognized instance tag {} ({}) for item {}; assigning to default instance.", value,
520                 value.getClass(), item.getName());
521         return (instance == 1);
522     }
523
524     /**
525      * Check for any missing accessories.
526      *
527      * If there are, return true so we know to increment the config version. UNLESS
528      * we're configured to use dummy accessories, in which case backfill it with a dummy.
529      *
530      * @return if we need to increment the configuration version
531      */
532     private boolean checkMissingAccessories() {
533         List<String> toRemove = new ArrayList<>();
534         for (Map.Entry<String, String> accessory : knownAccessories.entrySet()) {
535             if (!accessoryRegistry.getAllAccessories().containsKey(accessory.getKey())) {
536                 if (settings.useDummyAccessories) {
537                     logger.debug("Creating dummy accessory for missing item {}.", accessory.getKey());
538                     accessoryRegistry.addRootAccessory(accessory.getKey(),
539                             new DummyHomekitAccessory(accessory.getKey(), accessory.getValue()));
540                 } else {
541                     toRemove.add(accessory.getKey());
542                 }
543             }
544         }
545
546         toRemove.forEach(k -> knownAccessories.remove(k));
547         return !toRemove.isEmpty();
548     }
549
550     private void checkForDummyAccessories() {
551         List<String> currentDummies = accessoryRegistry.getAllAccessories().values().stream()
552                 .filter(a -> a instanceof DummyHomekitAccessory).map(a -> {
553                     try {
554                         return a.getSerialNumber().get();
555                     } catch (InterruptedException | ExecutionException e) {
556                         return "<unknown>";
557                     }
558                 }).collect(Collectors.toList());
559
560         List<String> resolvedDummies = new ArrayList(priorDummies);
561         resolvedDummies.removeAll(currentDummies);
562         List<String> newDummies = new ArrayList(currentDummies);
563         newDummies.removeAll(priorDummies);
564
565         if (resolvedDummies.size() <= 5) {
566             for (String item : resolvedDummies) {
567                 logger.info("{} has been resolved to an actual accessory, and is no longer a dummy.", item);
568             }
569         } else if (currentDummies.isEmpty() && !resolvedDummies.isEmpty()) {
570             logger.info("All dummy accessories have been resolved to actual accessories.");
571         } else if (!resolvedDummies.isEmpty()) {
572             logger.info("{} dummy accessories have been resolved to actual accessories.", resolvedDummies.size());
573         }
574
575         if (newDummies.size() <= 5) {
576             for (String item : newDummies) {
577                 logger.warn(
578                         "{} has been replaced with a dummy. See https://www.openhab.org/addons/integrations/homekit/#dummy-accessories for more information.",
579                         item);
580             }
581         } else if (!newDummies.isEmpty()) {
582             logger.warn(
583                     "{} accessories have been replaced with dummies. See https://www.openhab.org/addons/integrations/homekit/#dummy-accessories for more information.",
584                     newDummies.size());
585         } else if (!currentDummies.isEmpty()) {
586             logger.warn(
587                     "{} accessories are still dummies. See https://www.openhab.org/addons/integrations/homekit/#dummy-accessories for more information.",
588                     currentDummies.size());
589         }
590         priorDummies.clear();
591         priorDummies.addAll(currentDummies);
592     }
593 }