Skip to content

Commit

Permalink
Merge pull request #1595 from SmartThingsCommunity/feature/lock-notfu…
Browse files Browse the repository at this point in the history
…llylocked

matter-lock: Expose 'not fully locked' when reported by the lock
  • Loading branch information
tpmanley authored Aug 26, 2024
2 parents cc00516 + 1caa657 commit 5bd9bbd
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 5 deletions.
5 changes: 3 additions & 2 deletions drivers/SmartThings/matter-lock/src/aqara-lock/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ local function lock_state_handler(driver, device, ib, response)
local LockState = DoorLock.attributes.LockState
local attr = capabilities.lock.lock
local LOCK_STATE = {
[LockState.NOT_FULLY_LOCKED] = attr.unknown(),
[LockState.NOT_FULLY_LOCKED] = attr.not_fully_locked(),
[LockState.LOCKED] = attr.locked(),
[LockState.UNLOCKED] = attr.unlocked(),
}
Expand Down Expand Up @@ -142,4 +142,5 @@ local aqara_lock_handler = {
can_handle = is_aqara_products
}

return aqara_lock_handler
return aqara_lock_handler

2 changes: 1 addition & 1 deletion drivers/SmartThings/matter-lock/src/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ local function lock_state_handler(driver, device, ib, response)
local LockState = DoorLock.attributes.LockState
local attr = capabilities.lock.lock
local LOCK_STATE = {
[LockState.NOT_FULLY_LOCKED] = attr.unknown(),
[LockState.NOT_FULLY_LOCKED] = attr.not_fully_locked(),
[LockState.LOCKED] = attr.locked(),
[LockState.UNLOCKED] = attr.unlocked(),
[UNLATCHED_STATE] = attr.unlocked(), -- Fully unlocked with latch pulled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ test.register_message_test(
)

test.register_message_test(
"Handle received Lock State from Matter device.", {
"Handle received LockState.LOCKED from Matter device.", {
{
channel = "matter",
direction = "receive",
Expand All @@ -119,6 +119,46 @@ test.register_message_test(
}
)

test.register_message_test(
"Handle received LockState.UNLOCKED from Matter device.", {
{
channel = "matter",
direction = "receive",
message = {
mock_device.id,
clusters.DoorLock.attributes.LockState:build_test_report_data(
mock_device, 1, clusters.DoorLock.attributes.LockState.UNLOCKED
),
},
},
{
channel = "capability",
direction = "send",
message = mock_device:generate_test_message("main", capabilities.lock.lock.unlocked()),
},
}
)

test.register_message_test(
"Handle received LockState.NOT_FULLY_LOCKED from Matter device.", {
{
channel = "matter",
direction = "receive",
message = {
mock_device.id,
clusters.DoorLock.attributes.LockState:build_test_report_data(
mock_device, 1, clusters.DoorLock.attributes.LockState.NOT_FULLY_LOCKED
),
},
},
{
channel = "capability",
direction = "send",
message = mock_device:generate_test_message("main", capabilities.lock.lock.not_fully_locked()),
},
}
)

local function refresh_commands(dev)
local req = clusters.DoorLock.attributes.LockState:read(dev)
return req
Expand Down
62 changes: 61 additions & 1 deletion drivers/SmartThings/matter-lock/src/test/test_matter_lock.lua
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ test.register_message_test(
)

test.register_message_test(
"Handle received Lock State from Matter device.", {
"Handle received LockState.LOCKED from Matter device.", {
{
channel = "matter",
direction = "receive",
Expand All @@ -115,6 +115,66 @@ test.register_message_test(
}
)

test.register_message_test(
"Handle received LockState.UNLOCKED from Matter device.", {
{
channel = "matter",
direction = "receive",
message = {
mock_device.id,
clusters.DoorLock.attributes.LockState:build_test_report_data(
mock_device, 10, clusters.DoorLock.attributes.LockState.UNLOCKED
),
},
},
{
channel = "capability",
direction = "send",
message = mock_device:generate_test_message("main", capabilities.lock.lock.unlocked()),
},
}
)

test.register_message_test(
"Handle received LockState.NOT_FULLY_LOCKED from Matter device.", {
{
channel = "matter",
direction = "receive",
message = {
mock_device.id,
clusters.DoorLock.attributes.LockState:build_test_report_data(
mock_device, 10, clusters.DoorLock.attributes.LockState.NOT_FULLY_LOCKED
),
},
},
{
channel = "capability",
direction = "send",
message = mock_device:generate_test_message("main", capabilities.lock.lock.not_fully_locked()),
},
}
)

test.register_message_test(
"Handle received LockState.UNLATCHED from Matter device.", {
{
channel = "matter",
direction = "receive",
message = {
mock_device.id,
clusters.DoorLock.attributes.LockState:build_test_report_data(
mock_device, 10, clusters.DoorLock.attributes.LockState.UNLATCHED
),
},
},
{
channel = "capability",
direction = "send",
message = mock_device:generate_test_message("main", capabilities.lock.lock.unlocked()),
},
}
)

test.register_message_test(
"Handle received BatPercentRemaining from device.", {
{
Expand Down

0 comments on commit 5bd9bbd

Please sign in to comment.