From 88f893e2ce6a149ac80f3c49d9e1246a1e868657 Mon Sep 17 00:00:00 2001 From: Ashok Sidipotu Date: Fri, 8 Mar 2024 12:45:26 +0530 Subject: [PATCH] monitors: use parseBool for boolean properties in rules The boolean values of properties in rules are strings in JSON config files and they will retain the same type when they are translated to Lua. Use cutils.parseBool() function when they have to be interpreted as bools. Fixes: #586 --- src/scripts/monitors/alsa.lua | 8 +++++--- src/scripts/monitors/bluez.lua | 2 +- src/scripts/monitors/libcamera/create-device.lua | 4 ++-- src/scripts/monitors/libcamera/create-node.lua | 4 ++-- src/scripts/monitors/v4l2/create-device.lua | 4 ++-- src/scripts/monitors/v4l2/create-node.lua | 4 ++-- 6 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/scripts/monitors/alsa.lua b/src/scripts/monitors/alsa.lua index 81d56d02..3cfd9fd8 100644 --- a/src/scripts/monitors/alsa.lua +++ b/src/scripts/monitors/alsa.lua @@ -153,7 +153,8 @@ function createNode(parent, id, obj_type, factory, properties) -- apply properties from rules defined in JSON .conf file properties = JsonUtils.match_rules_update_properties (config.rules, properties) - if properties["node.disabled"] then + if cutils.parseBool (properties ["node.disabled"]) then + log:notice ("ALSA node " .. properties["node.name"] .. " disabled") node_names_table [properties ["node.name"]] = nil return end @@ -257,13 +258,14 @@ function prepareDevice(parent, id, obj_type, factory, properties) applyDefaultDeviceProperties (properties) properties = JsonUtils.match_rules_update_properties (config.rules, properties) - if properties ["device.disabled"] then + if cutils.parseBool (properties ["device.disabled"]) then + log:notice ("ALSA card/device " .. properties ["device.name"] .. " disabled") device_names_table [properties ["device.name"]] = nil return end -- override the device factory to use ACP - if properties["api.alsa.use-acp"] then + if cutils.parseBool (properties ["api.alsa.use-acp"]) then log:info("Enabling the use of ACP on " .. properties["device.name"]) factory = "api.alsa.acp.device" end diff --git a/src/scripts/monitors/bluez.lua b/src/scripts/monitors/bluez.lua index 1e1d1d05..76c13640 100644 --- a/src/scripts/monitors/bluez.lua +++ b/src/scripts/monitors/bluez.lua @@ -235,7 +235,7 @@ function createNode(parent, id, type, factory, properties) local dev_props = parent.properties local parent_id = parent["bound-id"] - if config.properties["bluez5.hw-offload-sco"] and factory:find("sco") then + if cutils.parseBool (config.properties ["bluez5.hw-offload-sco"]) and factory:find("sco") then createOffloadScoNode(parent, id, type, factory, properties) return end diff --git a/src/scripts/monitors/libcamera/create-device.lua b/src/scripts/monitors/libcamera/create-device.lua index 4788b388..8842b7fb 100644 --- a/src/scripts/monitors/libcamera/create-device.lua +++ b/src/scripts/monitors/libcamera/create-device.lua @@ -44,8 +44,8 @@ SimpleEventHook { -- apply properties from rules defined in JSON .conf file properties = JsonUtils.match_rules_update_properties (config.rules, properties) - if properties["device.disabled"] then - log:notice ("lib cam device " .. properties["device.name"] .. " disabled") + if cutils.parseBool (properties ["device.disabled"]) then + log:notice ("libcam device " .. properties["device.name"] .. " disabled") return end local device = SpaDevice (factory, properties) diff --git a/src/scripts/monitors/libcamera/create-node.lua b/src/scripts/monitors/libcamera/create-node.lua index f3c568c2..706cb8df 100644 --- a/src/scripts/monitors/libcamera/create-node.lua +++ b/src/scripts/monitors/libcamera/create-node.lua @@ -29,8 +29,8 @@ SimpleEventHook { -- apply properties from rules defined in JSON .conf file properties = JsonUtils.match_rules_update_properties (config.rules, properties) - if properties["node.disabled"] then - log:warning ("lib cam device node" .. properties["device.name"] .. " disabled") + if cutils.parseBool (properties["node.disabled"]) then + log:notice ("libcam node" .. properties ["node.name"] .. " disabled") return end -- create the node diff --git a/src/scripts/monitors/v4l2/create-device.lua b/src/scripts/monitors/v4l2/create-device.lua index 21494d69..167d9623 100644 --- a/src/scripts/monitors/v4l2/create-device.lua +++ b/src/scripts/monitors/v4l2/create-device.lua @@ -44,8 +44,8 @@ SimpleEventHook { -- apply properties from rules defined in JSON .conf file properties = JsonUtils.match_rules_update_properties (config.rules, properties) - if properties["device.disabled"] then - log:warning ("v4l2 device " .. properties["device.name"] .. " disabled") + if cutils.parseBool (properties ["device.disabled"]) then + log:notice ("V4L2 device " .. properties["device.name"] .. " disabled") return end local device = SpaDevice (factory, properties) diff --git a/src/scripts/monitors/v4l2/create-node.lua b/src/scripts/monitors/v4l2/create-node.lua index 20408534..9ba365bb 100644 --- a/src/scripts/monitors/v4l2/create-node.lua +++ b/src/scripts/monitors/v4l2/create-node.lua @@ -30,8 +30,8 @@ SimpleEventHook { -- apply properties from rules defined in JSON .conf file properties = JsonUtils.match_rules_update_properties (config.rules, properties) - if properties["node.disabled"] then - log:warning ("v4l2 device node" .. properties["device.name"] .. " disabled") + if cutils.parseBool (properties ["node.disabled"]) then + log:notice ("V4L2 node" .. properties ["node.name"] .. " disabled") return end -- create the node