[linuxinput] handle keys not known by libevdev (#13632)

* [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>
pull/13642/head
Thomas Weißschuh 2022-11-01 08:06:58 -05:00 committed by GitHub
parent 33de7b426b
commit 894668ffce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View File

@ -81,3 +81,10 @@ The following happens when pressing and releasing a key:
#### Rationale #### Rationale
Channel states are updated first to allow rules triggered by channel triggers to access the new state. 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.

View File

@ -95,9 +95,13 @@ public final class LinuxInputHandler extends DeviceReadingHandler {
EvdevDevice newDevice = new EvdevDevice(config.path); EvdevDevice newDevice = new EvdevDevice(config.path);
for (EvdevDevice.Key o : newDevice.enumerateKeys()) { for (EvdevDevice.Key o : newDevice.enumerateKeys()) {
String name = o.getName(); String name = o.getName();
if (name == null) {
name = Integer.toString(o.getCode());
}
Channel channel = ChannelBuilder Channel channel = ChannelBuilder
.create(new ChannelUID(thing.getUID(), CHANNEL_GROUP_KEYPRESSES_ID, name), CoreItemFactory.CONTACT) .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); channels.put(o.getCode(), channel);
newChannels.add(channel); newChannels.add(channel);
} }