Skip to content

Commit

Permalink
fixed thread call and removed the unused local
Browse files Browse the repository at this point in the history
  • Loading branch information
seojune79 committed Sep 20, 2023
1 parent 54addef commit 85e336e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
16 changes: 6 additions & 10 deletions drivers/SmartThings/zigbee-button/src/aqara/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,38 +35,34 @@ local callback_timer = function(driver, device, cmd)
end
end

local function delete_timer(device)
local function reset_thread(device)
local timer = device:get_field(CUBEACTION_TIMER)
if timer then
device.thread:cancel_timer(timer)
device:set_field(CUBEACTION_TIMER, nil, { persist = true })
end
device:set_field(CUBEACTION_TIMER, device.thread:call_with_delay(CUBEACTION_TIME, callback_timer(driver, device)))
end

local function data_handler(driver, device, value, zb_rx)
local val = value.value
local timer = nil
if val == 0x0000 then -- Shake
device:emit_event(cubeAction.cubeAction("shake"))
delete_timer(device)
device:set_field(CUBEACTION_TIMER, device.thread:call_with_delay(CUBEACTION_TIME, callback_timer(driver, device)))
reset_thread(device)
elseif val == 0x0004 then -- hold
device:emit_event(cubeAction.cubeAction("pickUpAndHold"))
delete_timer(device)
device:set_field(CUBEACTION_TIMER, device.thread:call_with_delay(CUBEACTION_TIME, callback_timer(driver, device)))
reset_thread(device)
elseif val & 0x0400 == 0x0400 then -- Flip to side
local faceNum = val & 0x0007
device:emit_event(cubeAction.cubeAction(cubeFlipToSideVal[faceNum + 0x1]))
delete_timer(device)
device:set_field(CUBEACTION_TIMER, device.thread:call_with_delay(CUBEACTION_TIME, callback_timer(driver, device)))
reset_thread(device)
end
end

local function rotate_handler(driver, device, value, zb_rx)
-- Rotation
device:emit_event(cubeAction.cubeAction("rotate"))
delete_timer(device)
device:set_field(CUBEACTION_TIMER, device.thread:call_with_delay(CUBEACTION_TIME, callback_timer(driver, device)))
reset_thread(device)
end

local function face_handler(driver, device, value, zb_rx)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ local t_utils = require "integration_test.utils"
local zigbee_test_utils = require "integration_test.zigbee_test_utils"
local capabilities = require "st.capabilities"
local data_types = require "st.zigbee.data_types"
local clusters = require "st.zigbee.zcl.clusters"
local PowerConfiguration = clusters.PowerConfiguration

local PRI_CLU = 0xFCC0
local PRI_ATTR = 0x0009
Expand Down

0 comments on commit 85e336e

Please sign in to comment.