Skip to content

Commit

Permalink
Fix the code
Browse files Browse the repository at this point in the history
  • Loading branch information
inasail committed Aug 25, 2023
1 parent d0e5ecc commit 2a412bd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
12 changes: 11 additions & 1 deletion drivers/SmartThings/zigbee-lock/src/samsungsds/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ local clusters = require "st.zigbee.zcl.clusters"
local battery_defaults = require "st.zigbee.defaults.battery_defaults"
local capabilities = require "st.capabilities"
local cluster_base = require "st.zigbee.cluster_base"
local PowerConfiguration = clusters.PowerConfiguration
local DoorLock = clusters.DoorLock
local Lock = capabilities.lock
local lock_utils = require "lock_utils"
Expand Down Expand Up @@ -50,22 +51,28 @@ local function unlock_cmd_handler(driver, device, command)
"\x10\x04\x31\x32\x33\x35"))
end

local refresh = function(driver, device, cmd)
-- do nothing in refresh capability handler
end

local device_added = function(self, device)
lock_utils.populate_state_from_data(device)
device:emit_event(capabilities.lock.lock.unlocked())
device:emit_event(capabilities.battery.battery(100))
end

local do_configure = function(self, device)
device:configure()
device:send(device_management.build_bind_request(device, DoorLock.ID, self.environment_info.hub_zigbee_eui))
device:send(device_management.build_bind_request(device, PowerConfiguration.ID, self.environment_info.hub_zigbee_eui))
device:send(DoorLock.attributes.LockState:configure_reporting(device, 0, 3600, 0))
end

local battery_init = battery_defaults.build_linear_voltage_init(4.0, 6.0)

local device_init = function(driver, device, event)
battery_init(driver, device, event)
device:remove_monitored_attribute(clusters.PowerConfiguration.ID, clusters.PowerConfiguration.attributes.BatteryVoltage.ID)
device:remove_configured_attribute(clusters.PowerConfiguration.ID, clusters.PowerConfiguration.attributes.BatteryVoltage.ID)
lock_utils.populate_state_from_data(device)
end

Expand All @@ -84,6 +91,9 @@ local samsung_sds_driver = {
}
},
capability_handlers = {
[capabilities.refresh.ID] = {
[capabilities.refresh.commands.refresh.NAME] = refresh
},
[capabilities.lock.ID] = {
[capabilities.lock.commands.unlock.NAME] = unlock_cmd_handler
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,24 +53,18 @@ test.register_coroutine_test(
"Configure should configure all necessary attributes",
function()
test.socket.device_lifecycle:__queue_receive({ mock_device.id, "added" })
test.socket.capability:__expect_send(mock_device:generate_test_message("main", capabilities.lock.lock.unlocked()))
test.socket.capability:__expect_send(mock_device:generate_test_message("main", capabilities.battery.battery(100)))
test.wait_for_events()

test.socket.zigbee:__set_channel_ordering("relaxed")
test.socket.device_lifecycle:__queue_receive({ mock_device.id, "doConfigure" })

test.socket.zigbee:__expect_send({
mock_device.id,
zigbee_test_utils.build_bind_request(mock_device, zigbee_test_utils.mock_hub_eui, PowerConfiguration.ID)
zigbee_test_utils.build_bind_request(mock_device, zigbee_test_utils.mock_hub_eui, DoorLock.ID)
})
test.socket.zigbee:__expect_send(
{
mock_device.id,
PowerConfiguration.attributes.BatteryVoltage:configure_reporting(mock_device, 0x001E, 0x5460, 1)
}
)
test.socket.zigbee:__expect_send({
mock_device.id,
zigbee_test_utils.build_bind_request(mock_device, zigbee_test_utils.mock_hub_eui, DoorLock.ID)
zigbee_test_utils.build_bind_request(mock_device, zigbee_test_utils.mock_hub_eui, PowerConfiguration.ID)
})
test.socket.zigbee:__expect_send(
{
Expand Down

0 comments on commit 2a412bd

Please sign in to comment.