]> git.basschouten.com Git - openhab-addons.git/commitdiff
[linuxinput] handle keys not known by libevdev (#13632)
authorThomas Weißschuh <thomas@t-8ch.de>
Tue, 1 Nov 2022 13:06:58 +0000 (08:06 -0500)
committerGitHub <noreply@github.com>
Tue, 1 Nov 2022 13:06:58 +0000 (14:06 +0100)
* [linuxinput] handle keys not known by libevdev

Previously if libevdev could not resolve a numeric event code to a
symbolic name the name "null" was used.
This is useless for the user and may lead to duplicate-channel errors if
multiple unknown keys are encountered.

Instead use the numeric code itself as channel name if no symbolic code
could be determined.

Reported-in: https://community.openhab.org/t/linuxinput-binding-and-mouse-capture/122612/8
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
* [linuxinput] add channel description

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
bundles/org.openhab.binding.linuxinput/README.md
bundles/org.openhab.binding.linuxinput/src/main/java/org/openhab/binding/linuxinput/internal/LinuxInputHandler.java

index 5430a2c18d4a83a73f454ed2e55604ae9090520c..5723bab8527661a578ff1decc2b62a5952b047d3 100644 (file)
@@ -81,3 +81,10 @@ The following happens when pressing and releasing a key:
 #### Rationale
 
 Channel states are updated first to allow rules triggered by channel triggers to access the new state.
+
+#### Channel names
+
+The binding tries to translate the numeric event codes to their symbolic names; `KEY_1`, `KEY_A`, `KEY_BACKSPACE` etc.
+
+If the currently installed version of libevdev does not know the symbolic name of a key, the numeric value is used.
+Please note that future versions of libevdev may start translating the symbolic names.
index 7b4e74b8bf218a2ed8a72cbc919f6ba4b1c15162..7f8e40c893fb4220a587197059b352934039c97b 100644 (file)
@@ -95,9 +95,13 @@ public final class LinuxInputHandler extends DeviceReadingHandler {
         EvdevDevice newDevice = new EvdevDevice(config.path);
         for (EvdevDevice.Key o : newDevice.enumerateKeys()) {
             String name = o.getName();
+            if (name == null) {
+                name = Integer.toString(o.getCode());
+            }
             Channel channel = ChannelBuilder
                     .create(new ChannelUID(thing.getUID(), CHANNEL_GROUP_KEYPRESSES_ID, name), CoreItemFactory.CONTACT)
-                    .withLabel(name).withType(CHANNEL_TYPE_KEY_PRESS).build();
+                    .withLabel(name).withType(CHANNEL_TYPE_KEY_PRESS).withDescription("Event Code " + o.getCode())
+                    .build();
             channels.put(o.getCode(), channel);
             newChannels.add(channel);
         }