Skip to content

Commit 9e1a625

Browse files
committed
refactor(devices): rename alias fields
1 parent 2d25010 commit 9e1a625

3 files changed

Lines changed: 19 additions & 19 deletions

File tree

src/evdev/devices.lua

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ local M = {
1212
device_info = core.device_info,
1313
}
1414

15-
---@type fun(devs:evdev.deviceInfo[], paths:table<string,evdev.deviceInfo>, field:"by_id"|"by_path")
15+
---@type fun(devs:evdev.deviceInfo[], paths:table<string,evdev.deviceInfo>, field:"id_aliases"|"path_aliases")
1616
local function attach_alias(devs, paths, field)
17-
local dir = "/dev/input/" .. (field == "by_path" and "by-path" or "by-id")
17+
local dir = "/dev/input/" .. (field == "path_aliases" and "by-path" or "by-id")
1818
local aliases = list_aliases(dir)
1919
if not aliases then
2020
return
@@ -46,8 +46,8 @@ local function attach_aliases(devs)
4646
paths[info.path] = info
4747
end
4848

49-
attach_alias(devs, paths, "by_id")
50-
attach_alias(devs, paths, "by_path")
49+
attach_alias(devs, paths, "id_aliases")
50+
attach_alias(devs, paths, "path_aliases")
5151
end
5252

5353
local function has_value(ls, query)
@@ -64,7 +64,7 @@ end
6464
---@param dev evdev.deviceInfo
6565
local function matches_query(dev, query, is_path)
6666
if is_path then
67-
return dev.path == query or has_value(dev.by_id, query) or has_value(dev.by_path, query)
67+
return dev.path == query or has_value(dev.id_aliases, query) or has_value(dev.path_aliases, query)
6868
end
6969
return dev.name == query
7070
end

tests/devices.test.lua

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ local sleep = system.sleep
66

77
local function find_by_id(devs)
88
for _, dev in ipairs(devs) do
9-
if dev.by_id and next(dev.by_id) then
9+
if dev.id_aliases and next(dev.id_aliases) then
1010
return dev
1111
end
1212
end
1313
end
1414

1515
local function find_by_path(devs)
1616
for _, dev in ipairs(devs) do
17-
if dev.by_path and next(dev.by_path) then
17+
if dev.path_aliases and next(dev.path_aliases) then
1818
return dev
1919
end
2020
end
@@ -79,16 +79,16 @@ describe("evdev.devices", function()
7979

8080
it("attaches alias lists when present", function()
8181
for _, info in ipairs(devs) do
82-
if info.by_id then
83-
assert.Table(info.by_id)
84-
for _, alias in ipairs(info.by_id) do
82+
if info.id_aliases then
83+
assert.Table(info.id_aliases)
84+
for _, alias in ipairs(info.id_aliases) do
8585
assert.String(alias)
8686
end
8787
end
8888

89-
if info.by_path then
90-
assert.Table(info.by_path)
91-
for _, alias in ipairs(info.by_path) do
89+
if info.path_aliases then
90+
assert.Table(info.path_aliases)
91+
for _, alias in ipairs(info.path_aliases) do
9292
assert.String(alias)
9393
end
9494
end
@@ -127,7 +127,7 @@ describe("evdev.devices", function()
127127
pending("no discovered device with a by-id alias")
128128
end
129129

130-
local dev = find(dev_with_alias.by_id[1])
130+
local dev = find(dev_with_alias.id_aliases[1])
131131
assert.Table(dev) ---@cast dev -?
132132
assert.Equal(dev_with_alias.path, dev.path)
133133
end)
@@ -138,7 +138,7 @@ describe("evdev.devices", function()
138138
pending("no discovered device with a by-path alias")
139139
end
140140

141-
local dev = find(dev_with_alias.by_path[1])
141+
local dev = find(dev_with_alias.path_aliases[1])
142142
assert.Table(dev) ---@cast dev -?
143143
assert.Equal(dev_with_alias.path, dev.path)
144144
end)
@@ -180,7 +180,7 @@ describe("evdev.devices", function()
180180
pending("no discovered device with a by-id alias")
181181
end
182182

183-
local dev = find_all(dev_with_alias.by_id[1])
183+
local dev = find_all(dev_with_alias.id_aliases[1])
184184
assert.Table(dev) ---@cast dev -?
185185
assert.Equal(1, #dev)
186186
assert.Equal(dev_with_alias.path, dev[1].path)
@@ -192,7 +192,7 @@ describe("evdev.devices", function()
192192
pending("no discovered device with a by-path alias")
193193
end
194194

195-
local dev = find_all(dev_with_alias.by_path[1])
195+
local dev = find_all(dev_with_alias.path_aliases[1])
196196
assert.Table(dev) ---@cast dev -?
197197
assert.Equal(1, #dev)
198198
assert.Equal(dev_with_alias.path, dev[1].path)

types/device.d.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
---
1717
---@class evdev.deviceInfo
1818
---@field bustype integer Bus type from the kernel input ID.
19-
---@field by_id? string[] Symlink aliases under `/dev/input/by-id`, when available.
20-
---@field by_path? string[] Symlink aliases under `/dev/input/by-path`, when available.
19+
---@field id_aliases? string[] Symlink aliases under `/dev/input/by-id`, when available.
20+
---@field path_aliases? string[] Symlink aliases under `/dev/input/by-path`, when available.
2121
---@field name? string Device name reported by the kernel.
2222
---@field path string Device node path.
2323
---@field phys? string Physical device path, when available.

0 commit comments

Comments
 (0)