Skip to content

Commit ade9916

Browse files
committed
feat(devices): attach aliases in device_info
1 parent 48bde64 commit ade9916

2 files changed

Lines changed: 30 additions & 3 deletions

File tree

‎src/evdev/devices.lua‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ local list_aliases = core.list_aliases
88
local list_devices = core.list_devices
99

1010
---@type evdev.devices
11-
local M = {
12-
device_info = core.device_info,
13-
}
11+
local M = {}
1412

1513
---@type fun(devs:evdev.deviceInfo[], paths:table<string,evdev.deviceInfo>, field:"id_aliases"|"path_aliases")
1614
local function attach_alias(devs, paths, field)
@@ -84,6 +82,17 @@ function M.list_devices()
8482
return devs
8583
end
8684

85+
function M.device_info(path)
86+
local info, err = core.device_info(path)
87+
if not info then
88+
return nil, err
89+
end
90+
91+
attach_aliases({ info })
92+
93+
return info
94+
end
95+
8796
function M.find(query)
8897
validate("query", query, "string")
8998
local matches, err = M.find_all(query)

‎tests/devices.test.lua‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,5 +214,23 @@ describe("evdev.devices", function()
214214
device_info(false) ---@diagnostic disable-line
215215
end)
216216
end)
217+
218+
it("attaches alias lists when present", function()
219+
local dev_with_id = find_by_id(devs)
220+
if dev_with_id then
221+
local info = assert(device_info(dev_with_id.path))
222+
assert.Table(info.id_aliases)
223+
assert.True(#info.id_aliases > 0)
224+
assert.Same(dev_with_id.id_aliases, info.id_aliases)
225+
end
226+
227+
local dev_with_path = find_by_path(devs)
228+
if dev_with_path then
229+
local info = assert(device_info(dev_with_path.path))
230+
assert.Table(info.path_aliases)
231+
assert.True(#info.path_aliases > 0)
232+
assert.Same(dev_with_path.path_aliases, info.path_aliases)
233+
end
234+
end)
217235
end)
218236
end)

0 commit comments

Comments
 (0)