Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Map doorlock that doesn't support Power source cluster to lock-lockalarm-nobattery #1446

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
21 changes: 13 additions & 8 deletions drivers/SmartThings/matter-lock/src/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -526,8 +526,13 @@ local function device_added(driver, device)
--Note: May want to write RequirePINForRemoteOperation, to avoid cota cases if possible.
device:emit_event(capabilities.tamperAlert.tamper.clear())
device:emit_event(capabilities.lockAlarm.alarm.clear())
local eps = device:get_endpoints(DoorLock.ID, {feature_bitmap = DoorLock.types.DoorLockFeature.PIN_CREDENTIALS})
if #eps == 0 then
local pin_eps = device:get_endpoints(DoorLock.ID, {feature_bitmap = DoorLock.types.DoorLockFeature.PIN_CREDENTIALS})
local battery_eps = device:get_endpoints(clusters.PowerSource.ID, {feature_bitmap = clusters.PowerSource.types.PowerSourceFeature.BATTERY})
if #battery_eps == 0 then
device.log.debug("Device does not support battery. Switching profile.")
device:try_update_metadata({profile = "lock-lockalarm-nobattery"})
Copy link
Contributor

Choose a reason for hiding this comment

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

The profile will get changed again if #pins_eps == 0 due to the code just below

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, that is correct. In fact, because of the PR I pushed, there is no possibility of executing the code below at this time. so.. I think below code can be removed from the device_added function.

end
if #pin_eps == 0 then
if device:supports_capability_by_id(capabilities.tamperAlert.ID) then
device.log.debug("Device does not support lockCodes. Switching profile.")
device:try_update_metadata({profile = "lock-without-codes"})
Expand All @@ -538,22 +543,22 @@ local function device_added(driver, device)
-- intentionally, so only run this if device supports lockCodes in profile.
elseif device:supports_capability(capabilities.lockCodes) then
local req = im.InteractionRequest(im.InteractionRequest.RequestType.READ, {})
req:merge(DoorLock.attributes.MaxPINCodeLength:read(device, eps[1]))
req:merge(DoorLock.attributes.MinPINCodeLength:read(device, eps[1]))
req:merge(DoorLock.attributes.NumberOfPINUsersSupported:read(device, eps[1]))
req:merge(DoorLock.attributes.MaxPINCodeLength:read(device, pin_eps[1]))
req:merge(DoorLock.attributes.MinPINCodeLength:read(device, pin_eps[1]))
req:merge(DoorLock.attributes.NumberOfPINUsersSupported:read(device, pin_eps[1]))
driver:inject_capability_command(device, {
capability = capabilities.lockCodes.ID,
command = capabilities.lockCodes.commands.reloadAllCodes.NAME,
args = {}
})

--Device may require pin for remote operation if it supports COTA and PIN features.
eps = device:get_endpoints(DoorLock.ID, {feature_bitmap = DoorLock.types.DoorLockFeature.CREDENTIALSOTA | DoorLock.types.DoorLockFeature.PIN_CREDENTIALS})
if #eps == 0 then
pin_eps = device:get_endpoints(DoorLock.ID, {feature_bitmap = DoorLock.types.DoorLockFeature.CREDENTIALSOTA | DoorLock.types.DoorLockFeature.PIN_CREDENTIALS})
if #pin_eps == 0 then
device.log.debug("Device will not require PIN for remote operation")
device:set_field(lock_utils.COTA_CRED, false, {persist = true})
else
req:merge(DoorLock.attributes.RequirePINforRemoteOperation:read(device, eps[1]))
req:merge(DoorLock.attributes.RequirePINforRemoteOperation:read(device, pin_eps[1]))
end
device:send(req)
end
Expand Down
Loading