From 4592168179a5f7d67eac6958324797929a3165b2 Mon Sep 17 00:00:00 2001 From: Hunsup Jung Date: Tue, 24 Dec 2024 14:02:20 +0900 Subject: [PATCH] Update handle_power_source_attribute_list function Signed-off-by: Hunsup Jung --- .../matter-lock/src/new-matter-lock/init.lua | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/drivers/SmartThings/matter-lock/src/new-matter-lock/init.lua b/drivers/SmartThings/matter-lock/src/new-matter-lock/init.lua index ed9e7ed90f..9a6a5bc2de 100644 --- a/drivers/SmartThings/matter-lock/src/new-matter-lock/init.lua +++ b/drivers/SmartThings/matter-lock/src/new-matter-lock/init.lua @@ -364,20 +364,26 @@ end --------------------------------- local function handle_power_source_attribute_list(driver, device, ib, response) local support_battery_percentage = false + local support_battery_level = false for _, attr in ipairs(ib.data.elements) do -- Re-profile the device if BatPercentRemaining (Attribute ID 0x0C) is present. if attr.value == 0x0C then support_battery_percentage = true end + if attr.value == 0x0E then + support_battery_level = true + end end local profile_name = device:get_field(PROFILE_BASE_NAME) - if support_battery_percentage then - profile_name = profile_name .. "-battery" - else - profile_name = profile_name .. "-batteryLevel" + if profile_name ~= nil then + if support_battery_percentage then + profile_name = profile_name .. "-battery" + elseif support_battery_level then + profile_name = profile_name .. "-batteryLevel" + end + device.log.info(string.format("Updating device profile to %s.", profile_name)) + device:try_update_metadata({profile = profile_name}) end - device.log.info(string.format("Updating device profile to %s.", profile_name)) - device:try_update_metadata({profile = profile_name}) end ------------------------------- @@ -1753,7 +1759,6 @@ local new_matter_lock_handler = { capabilities.lockUsers, capabilities.lockCredentials, capabilities.lockSchedules, - capabilities.remoteControlStatus, capabilities.battery, capabilities.batteryLevel },