[linuxinput] fixes to thing properties (#10634)

* Do not discover on ENTRY_MODIFY

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.

* Use proper representation property

* Show event node in label

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 <thomas@t-8ch.de>
This commit is contained in:
Thomas Weißschuh 2021-05-05 22:22:18 +02:00 committed by GitHub
parent 4efccacb10
commit e510244cb6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -100,7 +100,7 @@ public class LinuxInputDiscoveryService extends AbstractDiscoveryService {
return; return;
} }
DiscoveryResultBuilder result = DiscoveryResultBuilder.create(new ThingUID(THING_TYPE_DEVICE, file.getName())) 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) { if (ttl != null) {
result = result.withTTL(ttl.getSeconds()); result = result.withTTL(ttl.getSeconds());
} }
@ -122,7 +122,7 @@ public class LinuxInputDiscoveryService extends AbstractDiscoveryService {
String labelFromDevice = device.getName(); String labelFromDevice = device.getName();
boolean isKeyboard = device.has(EvdevLibrary.Type.KEY); boolean isKeyboard = device.has(EvdevLibrary.Type.KEY);
if (labelFromDevice != null) { if (labelFromDevice != null) {
label = labelFromDevice; label = String.format("%s (%s)", labelFromDevice, inputDevice.getName());
} }
return isKeyboard; return isKeyboard;
} finally { } finally {
@ -168,8 +168,10 @@ public class LinuxInputDiscoveryService extends AbstractDiscoveryService {
private WatchService makeWatcher() throws IOException { private WatchService makeWatcher() throws IOException {
WatchService watchService = FileSystems.getDefault().newWatchService(); 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, DEVICE_DIRECTORY.register(watchService, StandardWatchEventKinds.ENTRY_CREATE,
StandardWatchEventKinds.ENTRY_DELETE, StandardWatchEventKinds.ENTRY_MODIFY); StandardWatchEventKinds.ENTRY_DELETE);
return watchService; return watchService;
} }