From 894668ffce41bacbf95b9f0f2beb1431711d0380 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= Date: Tue, 1 Nov 2022 08:06:58 -0500 Subject: [PATCH] [linuxinput] handle keys not known by libevdev (#13632) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [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 * [linuxinput] add channel description Signed-off-by: Thomas Weißschuh --- bundles/org.openhab.binding.linuxinput/README.md | 7 +++++++ .../binding/linuxinput/internal/LinuxInputHandler.java | 6 +++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/bundles/org.openhab.binding.linuxinput/README.md b/bundles/org.openhab.binding.linuxinput/README.md index 5430a2c18..5723bab85 100644 --- a/bundles/org.openhab.binding.linuxinput/README.md +++ b/bundles/org.openhab.binding.linuxinput/README.md @@ -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. diff --git a/bundles/org.openhab.binding.linuxinput/src/main/java/org/openhab/binding/linuxinput/internal/LinuxInputHandler.java b/bundles/org.openhab.binding.linuxinput/src/main/java/org/openhab/binding/linuxinput/internal/LinuxInputHandler.java index 7b4e74b8b..7f8e40c89 100644 --- a/bundles/org.openhab.binding.linuxinput/src/main/java/org/openhab/binding/linuxinput/internal/LinuxInputHandler.java +++ b/bundles/org.openhab.binding.linuxinput/src/main/java/org/openhab/binding/linuxinput/internal/LinuxInputHandler.java @@ -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); }