Skip to content

Commit 02b07c5

Browse files
committed
cleanup in response to comments
1 parent 3484135 commit 02b07c5

2 files changed

Lines changed: 11 additions & 30 deletions

File tree

‎drivers/SmartThings/zwave-lock/src/test/test_lock_credentials_commands.lua‎

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,6 @@ local access_control_event = Notification.event.access_control
1717

1818
test.disable_startup_messages()
1919

20-
21-
if table_utils.find_all_entries_by == nil then
22-
function table_utils.find_all_entries_by(device, table_name, key, value)
23-
local entries = table_utils.get_state(device, table_name) or {}
24-
local matches = {}
25-
for _, entry in ipairs(entries) do
26-
if entry[key] == value then table.insert(matches, entry) end
27-
end
28-
return matches
29-
end
30-
end
31-
32-
3320
local zwave_lock_endpoints = {
3421
{
3522
command_classes = {
@@ -57,7 +44,10 @@ local function install_state_mocks()
5744
rawset(mock_device, "log", {
5845
debug = function() end, info = function() end, warn = function() end, error = function() end,
5946
})
60-
rawset(mock_device, "supports_capability", function() return true end)
47+
rawset(mock_device, "supports_capability", function(_, capability)
48+
local id = type(capability) == "table" and capability.ID or capability
49+
return id == capabilities.lockUsers.ID or id == capabilities.lockCredentials.ID
50+
end)
6151
mock_device.get_latest_state = function(_, component_id, capability_id, attribute_name, default_value)
6252
local value = mock_latest_state[mock_state_key(component_id, capability_id, attribute_name)]
6353
if value == nil then
@@ -447,10 +437,11 @@ test.register_coroutine_test(
447437
{ capability = capabilities.lockCredentials.ID, command = "deleteAllCredentials", args = {} },
448438
})
449439

440+
-- Per-credential clears fire at 2 * (i - 1) s; final cleanup at 2 * #credentials + 4 s.
450441
test.timer.__create_and_queue_test_time_advance_timer(0, "oneshot")
451442
test.timer.__create_and_queue_test_time_advance_timer(6, "oneshot")
452-
test.mock_time.advance_time(0)
453443
expect_clear_pin_code(1)
444+
test.mock_time.advance_time(0)
454445
test.wait_for_events()
455446

456447
test.mock_time.advance_time(6)
@@ -500,8 +491,6 @@ test.register_coroutine_test(
500491
test.register_coroutine_test(
501492
"deleteAllCredentials: returns busy when another operation is already in progress",
502493
function()
503-
seed_credentials({ { userIndex = 1, credentialIndex = 1, credentialType = "pin" } })
504-
505494
-- First deleteAllCredentials starts the z-wave flow (device is now busy)
506495
test.socket.capability:__queue_receive({
507496
mock_device.id,

‎drivers/SmartThings/zwave-lock/src/test/test_lock_pre_configured.lua‎

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,6 @@ local json = require "st.json"
1919

2020

2121
test.disable_startup_messages()
22-
if table_utils.find_all_entries_by == nil then
23-
function table_utils.find_all_entries_by(device, table_name, key, value)
24-
local entries = table_utils.get_state(device, table_name) or {}
25-
local matches = {}
26-
for _, entry in ipairs(entries) do
27-
if entry[key] == value then table.insert(matches, entry) end
28-
end
29-
return matches
30-
end
31-
end
32-
3322

3423
-- ── Shared device ──────────────────────────────────────────────────────────
3524

@@ -70,8 +59,11 @@ local function install_state_mocks()
7059
error = function() end,
7160
})
7261

73-
-- get_state guards with device:supports_capability; always return true here.
74-
rawset(mock_device, "supports_capability", function() return true end)
62+
-- get_state guards with device:supports_capability; only the seeded capabilities are supported.
63+
rawset(mock_device, "supports_capability", function(_, capability)
64+
local id = type(capability) == "table" and capability.ID or capability
65+
return id == capabilities.lockUsers.ID or id == capabilities.lockCredentials.ID
66+
end)
7567

7668
-- get_state / get_max_entries use device:get_latest_state to read
7769
-- capability attribute values from the state cache.

0 commit comments

Comments
 (0)