monitors: sanitize device names like media-session does

This commit is contained in:
George Kiagiadakis 2021-06-03 18:58:07 +03:00
parent d28f1241cc
commit 47ed9bb527
3 changed files with 14 additions and 2 deletions

View file

@ -188,7 +188,7 @@ function prepareDevice(parent, id, type, factory, properties)
(properties["device.name"] or
properties["device.bus-id"] or
properties["device.bus-path"] or
tostring(id))
tostring(id)):gsub("([^%w_%-%.])", "_")
properties["device.name"] = name

View file

@ -92,6 +92,18 @@ end
function createDevice(parent, id, type, factory, properties)
local device = parent:get_managed_object(id)
if not device then
-- ensure a proper device name
local name =
(properties["device.name"] or
properties["api.bluez5.address"] or
properties["device.description"] or
tostring(id)):gsub("([^%w_%-%.])", "_")
if not name:find("^bluez_card%.", 1) then
name = "bluez_card." .. name
end
properties["device.name"] = name
-- apply properties from config.rules
rulesApplyProperties(properties)

View file

@ -101,7 +101,7 @@ function createDevice(parent, id, type, factory, properties)
(properties["device.name"] or
properties["device.bus-id"] or
properties["device.bus-path"] or
tostring(id))
tostring(id)):gsub("([^%w_%-%.])", "_")
properties["device.name"] = name