Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions drivers/SmartThings/matter-lock/src/new-matter-lock/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ local PowerSource = clusters.PowerSource

local INITIAL_CREDENTIAL_INDEX = 1
local ALL_INDEX = 0xFFFE
local NAME_MAX_L = 10
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
local NAME_MAX_L = 10
-- maximum as defined by the Matter specification
local MAX_USER_NAME_LENGTH = 10

local MIN_EPOCH_S = 0
local MAX_EPOCH_S = 0xffffffff
local THIRTY_YEARS_S = 946684800 -- 1970-01-01T00:00:00 ~ 2000-01-01T00:00:00
Expand Down Expand Up @@ -1273,6 +1274,10 @@ local function handle_update_user(driver, device, command)
local cmdName = "updateUser"
local userIdx = command.args.userIndex
local userName = command.args.userName
local userNameMatter = userName
if #userNameMatter > NAME_MAX_L then
userNameMatter = string.sub(userNameMatter, 1, NAME_MAX_L)
end
Comment on lines +1277 to +1280
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
local userNameMatter = userName
if #userNameMatter > NAME_MAX_L then
userNameMatter = string.sub(userNameMatter, 1, NAME_MAX_L)
end
local userName = string.sub(command.args.userName, 1, NAME_MAX_L)

the sub will only limit the userName input if it is too long, so no need for the extra check, or the extra variable

local userType = command.args.userType
local userTypeMatter = DoorLock.types.UserTypeEnum.UNRESTRICTED_USER
if userType == "guest" then
Expand Down Expand Up @@ -1303,12 +1308,12 @@ local function handle_update_user(driver, device, command)
DoorLock.server.commands.SetUser(
device, ep,
DoorLock.types.DataOperationTypeEnum.MODIFY, -- Operation Type: Add(0), Modify(2)
userIdx, -- User Index
userName, -- User Name
nil, -- Unique ID
nil, -- User Status
userTypeMatter, -- User Type
nil -- Credential Rule
userIdx,
userNameMatter,
nil, -- Unique ID
nil, -- User Status
userTypeMatter,
nil -- Credential Rule
)
)
end
Expand Down Expand Up @@ -1530,14 +1535,16 @@ local function handle_add_credential(driver, device, command)
-- Get parameters
local cmdName = "addCredential"
local userIdx = command.args.userIndex
if userIdx == 0 then
userIdx = nil
end
local userType = command.args.userType
local userTypeMatter = DoorLock.types.UserTypeEnum.UNRESTRICTED_USER
if userType == "guest" then
userTypeMatter = DoorLock.types.UserTypeEnum.SCHEDULE_RESTRICTED_USER
end
if userIdx == 0 then
userIdx = nil
else
userTypeMatter = nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

curious, why should this be nil if userIdx > 0?

end
local credential = {
credential_type = DoorLock.types.CredentialTypeEnum.PIN,
credential_index = INITIAL_CREDENTIAL_INDEX
Expand Down
Loading