From fddffdad71648dd325a8e1f83701547ba276fe04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= Date: Sun, 2 May 2021 10:59:36 +0200 Subject: [PATCH 1/3] [linuxinput] do not discover on ENTRY_MODIFY MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ENTRY_MODIFY is triggered on each keypress multiple times, so we should not trigger on it. The usecase for ENTRY_MODIFY triggers where detecting permission changes of the event nodes. Inotify does have a dedicate event ("ATTRIB") for that but Java WatchService normalizes this to a ENTRY_MODIFY event (See LinuxWatchService.java) After permission changes users now have to trigger a scan manually. Signed-off-by: Thomas Weißschuh --- .../linuxinput/internal/LinuxInputDiscoveryService.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bundles/org.openhab.binding.linuxinput/src/main/java/org/openhab/binding/linuxinput/internal/LinuxInputDiscoveryService.java b/bundles/org.openhab.binding.linuxinput/src/main/java/org/openhab/binding/linuxinput/internal/LinuxInputDiscoveryService.java index 2d0da6dad04fa..76fb6e2feddec 100644 --- a/bundles/org.openhab.binding.linuxinput/src/main/java/org/openhab/binding/linuxinput/internal/LinuxInputDiscoveryService.java +++ b/bundles/org.openhab.binding.linuxinput/src/main/java/org/openhab/binding/linuxinput/internal/LinuxInputDiscoveryService.java @@ -168,8 +168,10 @@ protected void startBackgroundDiscovery() { private WatchService makeWatcher() throws IOException { WatchService watchService = FileSystems.getDefault().newWatchService(); + // FIXME also trigger on inotify "ATTRIB" events when WatchService supports this. + // Triggering on ENTRY_MODIFY will trigger multiple times on each keypress for *any* input device. DEVICE_DIRECTORY.register(watchService, StandardWatchEventKinds.ENTRY_CREATE, - StandardWatchEventKinds.ENTRY_DELETE, StandardWatchEventKinds.ENTRY_MODIFY); + StandardWatchEventKinds.ENTRY_DELETE); return watchService; } From dc4081d4bae51438d6eaf892e43da64c85e60643 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= Date: Sun, 2 May 2021 11:02:42 +0200 Subject: [PATCH 2/3] [linuxinput] Use proper representationproperty MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Thomas Weißschuh --- .../binding/linuxinput/internal/LinuxInputDiscoveryService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundles/org.openhab.binding.linuxinput/src/main/java/org/openhab/binding/linuxinput/internal/LinuxInputDiscoveryService.java b/bundles/org.openhab.binding.linuxinput/src/main/java/org/openhab/binding/linuxinput/internal/LinuxInputDiscoveryService.java index 76fb6e2feddec..fb400cc3babea 100644 --- a/bundles/org.openhab.binding.linuxinput/src/main/java/org/openhab/binding/linuxinput/internal/LinuxInputDiscoveryService.java +++ b/bundles/org.openhab.binding.linuxinput/src/main/java/org/openhab/binding/linuxinput/internal/LinuxInputDiscoveryService.java @@ -100,7 +100,7 @@ private void handleFile(File file, @Nullable Duration ttl) { return; } DiscoveryResultBuilder result = DiscoveryResultBuilder.create(new ThingUID(THING_TYPE_DEVICE, file.getName())) - .withProperty("path", file.getAbsolutePath()).withRepresentationProperty(file.getName()); + .withProperty("path", file.getAbsolutePath()).withRepresentationProperty("path"); if (ttl != null) { result = result.withTTL(ttl.getSeconds()); } From b1d513db32342238301aebbd9e6520c7cca6d931 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= Date: Sun, 2 May 2021 11:10:41 +0200 Subject: [PATCH 3/3] [linuxinput] show event node in label MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This makes it easier to figure out which thing is which device in the presence of symlinks or multiple identical devices. Signed-off-by: Thomas Weißschuh --- .../binding/linuxinput/internal/LinuxInputDiscoveryService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundles/org.openhab.binding.linuxinput/src/main/java/org/openhab/binding/linuxinput/internal/LinuxInputDiscoveryService.java b/bundles/org.openhab.binding.linuxinput/src/main/java/org/openhab/binding/linuxinput/internal/LinuxInputDiscoveryService.java index fb400cc3babea..365c39bb9647a 100644 --- a/bundles/org.openhab.binding.linuxinput/src/main/java/org/openhab/binding/linuxinput/internal/LinuxInputDiscoveryService.java +++ b/bundles/org.openhab.binding.linuxinput/src/main/java/org/openhab/binding/linuxinput/internal/LinuxInputDiscoveryService.java @@ -122,7 +122,7 @@ private boolean enrichDevice(DiscoveryResultBuilder builder, File inputDevice) { String labelFromDevice = device.getName(); boolean isKeyboard = device.has(EvdevLibrary.Type.KEY); if (labelFromDevice != null) { - label = labelFromDevice; + label = String.format("%s (%s)", labelFromDevice, inputDevice.getName()); } return isKeyboard; } finally {