Skip to content

Commit

Permalink
Update handle_power_source_attribute_list function
Browse files Browse the repository at this point in the history
Signed-off-by: Hunsup Jung <[email protected]>
  • Loading branch information
HunsupJung committed Dec 24, 2024
1 parent aa47454 commit 4592168
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions drivers/SmartThings/matter-lock/src/new-matter-lock/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

-------------------------------
Expand Down Expand Up @@ -1753,7 +1759,6 @@ local new_matter_lock_handler = {
capabilities.lockUsers,
capabilities.lockCredentials,
capabilities.lockSchedules,
capabilities.remoteControlStatus,
capabilities.battery,
capabilities.batteryLevel
},
Expand Down

0 comments on commit 4592168

Please sign in to comment.