diff --git a/bundles/org.openhab.core.semantics/src/main/java/org/openhab/core/semantics/model/yaml/YamlModelRepository.java b/bundles/org.openhab.core.semantics/src/main/java/org/openhab/core/semantics/model/yaml/YamlModelRepository.java index fa3408be2d9..b9d0e6cee2e 100644 --- a/bundles/org.openhab.core.semantics/src/main/java/org/openhab/core/semantics/model/yaml/YamlModelRepository.java +++ b/bundles/org.openhab.core.semantics/src/main/java/org/openhab/core/semantics/model/yaml/YamlModelRepository.java @@ -56,7 +56,7 @@ public class YamlModelRepository implements WatchService.WatchEventListener { private final ObjectMapper yamlReader; private final Map>> listeners = new ConcurrentHashMap<>(); - private final Map> objects = new ConcurrentHashMap<>(); + private final Map> objects = new ConcurrentHashMap<>(); @Activate public YamlModelRepository(@Reference(target = WatchService.CONFIG_WATCHER_FILTER) WatchService watchService) { @@ -87,12 +87,14 @@ public synchronized void processWatchEvent(Kind kind, Path path) { } private void processWatchEvent(String dirName, Kind kind, Path fullPath, YamlModelListener listener) { + logger.debug("processWatchEvent dirName={} kind={} fullPath={} listener={}", dirName, kind, fullPath, + listener.getClass().getSimpleName()); Map oldObjects; Map newObjects; if (kind == WatchService.Kind.DELETE) { newObjects = Map.of(); - List oldListObjects = objects.remove(dirName); + List oldListObjects = objects.remove(fullPath); if (oldListObjects == null) { oldListObjects = List.of(); } @@ -109,13 +111,13 @@ private void processWatchEvent(String dirName, Kind kind, Path fullPath, YamlMod List newListObjects = yamlData.getElements(); newObjects = newListObjects.stream().collect(Collectors.toMap(YamlElement::getId, obj -> obj)); - List oldListObjects = objects.get(dirName); + List oldListObjects = objects.get(fullPath); if (oldListObjects == null) { oldListObjects = List.of(); } oldObjects = oldListObjects.stream().collect(Collectors.toMap(YamlElement::getId, obj -> obj)); - objects.put(dirName, newListObjects); + objects.put(fullPath, newListObjects); } String modelName = fullPath.toFile().getName(); @@ -167,7 +169,11 @@ protected void addYamlModelListener(YamlModelListener listener) { // Load all existing YAML files try (Stream stream = Files.walk(watchPath.resolve(dirName))) { - stream.forEach(path -> processWatchEvent(dirName, Kind.CREATE, path, listener)); + stream.forEach(path -> { + if (!Files.isDirectory(path) && !path.toFile().isHidden() && path.toString().endsWith(".yaml")) { + processWatchEvent(dirName, Kind.CREATE, path, listener); + } + }); } catch (IOException ignored) { } }