From 112a45a230c71044df123e26e907bb2eebe5b8de Mon Sep 17 00:00:00 2001 From: Ashok Sidipotu Date: Thu, 8 Feb 2024 13:19:26 +0530 Subject: [PATCH] device-profile-hooks: move the selected profile check move the check to the beginning of the hook. --- src/scripts/device/find-best-profile.lua | 10 ++++++---- src/scripts/device/state-profile.lua | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/scripts/device/find-best-profile.lua b/src/scripts/device/find-best-profile.lua index 815b3d60..1518d09c 100644 --- a/src/scripts/device/find-best-profile.lua +++ b/src/scripts/device/find-best-profile.lua @@ -21,6 +21,12 @@ SimpleEventHook { }, execute = function (event) local selected_profile = event:get_data ("selected-profile") + + -- skip hook if profile is already selected + if selected_profile then + return + end + local device = event:get_subject () local dev_name = device.properties["device.name"] local off_profile = nil @@ -29,10 +35,6 @@ SimpleEventHook { -- Takes absolute priority if available or unknown local profile_prop = device.properties["device.profile"] - -- skip hook if profile is already selected - if selected_profile then - return - end for p in device:iterate_params ("EnumProfile") do profile = cutils.parseParam (p, "EnumProfile") diff --git a/src/scripts/device/state-profile.lua b/src/scripts/device/state-profile.lua index 0da99465..eca69f3a 100644 --- a/src/scripts/device/state-profile.lua +++ b/src/scripts/device/state-profile.lua @@ -28,14 +28,14 @@ find_stored_profile_hook = SimpleEventHook { }, execute = function (event) local selected_profile = event:get_data ("selected-profile") - local device = event:get_subject () - local dev_name = device.properties["device.name"] -- skip hook if profile is already selected if selected_profile then return end + local device = event:get_subject () + local dev_name = device.properties["device.name"] if not dev_name then log:critical (device, "invalid device.name") return