From 7a70b042376ffbb5dff0672104fe22aba7e804ef Mon Sep 17 00:00:00 2001 From: Julian Bouzas Date: Sun, 31 Jul 2022 10:09:32 -0400 Subject: [PATCH] policy-device-profile: set best profile even if it has not changed We want to set the best profile even if it has not changed, because it can be different than the active profile. Fixes #329 --- src/scripts/policy-device-profile.lua | 30 +++------------------------ 1 file changed, 3 insertions(+), 27 deletions(-) diff --git a/src/scripts/policy-device-profile.lua b/src/scripts/policy-device-profile.lua index 871f0ca9..b591cb7d 100644 --- a/src/scripts/policy-device-profile.lua +++ b/src/scripts/policy-device-profile.lua @@ -9,7 +9,6 @@ local self = {} self.config = ... or {} self.config.persistent = self.config.persistent or {} self.active_profiles = {} -self.best_profiles = {} self.default_profile_plugin = Plugin.find("default-profile") -- Preprocess persisten profiles and create Interest objects @@ -123,25 +122,6 @@ function findBestProfile (device) return nil end -function handleBestProfile (device, dev_id, dev_name) - -- Find best profile - local profile = findBestProfile (device) - if profile == nil then - Log.info ("Cannot find best profile for device " .. dev_name) - return false - end - - -- Update if it has changed - if self.best_profiles[dev_id] == nil or - self.best_profiles[dev_id].index ~= profile.index then - self.best_profiles[dev_id] = profile - Log.info ("Best profile changed to " .. profile.name .. " in " .. dev_name) - return true - end - - return false -end - function handleProfiles (device, new_device) local dev_id = device["bound-id"] local dev_name = device.properties["device.name"] @@ -172,13 +152,10 @@ function handleProfiles (device, new_device) Log.info ("Default profile not found for " .. dev_name) end - -- Otherwise just set the best profile if changed - local best_changed = handleBestProfile (device, dev_id, dev_name) - local best_profile = self.best_profiles[dev_id] - if best_changed and best_profile ~= nil then + local best_profile = findBestProfile (device) + if best_profile ~= nil then + Log.info ("Found best profile " .. best_profile.name .. " for " .. dev_name) setDeviceProfile (device, dev_id, dev_name, best_profile) - elseif best_profile ~= nil then - Log.info ("Best profile " .. best_profile.name .. " did not change on " .. dev_name) else Log.info ("Best profile not found on " .. dev_name) end @@ -205,7 +182,6 @@ end) self.om:connect("object-removed", function (_, device) local dev_id = device["bound-id"] self.active_profiles[dev_id] = nil - self.best_profiles[dev_id] = nil end) self.om:activate()