From 85e336ee7ea228eb27c29e77c8e27b30e163c133 Mon Sep 17 00:00:00 2001 From: seojune Date: Thu, 21 Sep 2023 08:18:20 +0900 Subject: [PATCH] fixed thread call and removed the unused local --- .../SmartThings/zigbee-button/src/aqara/init.lua | 16 ++++++---------- .../src/test/test_aqara_cube_t1_pro.lua | 2 -- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/drivers/SmartThings/zigbee-button/src/aqara/init.lua b/drivers/SmartThings/zigbee-button/src/aqara/init.lua index 488886c1a6..1471d8336a 100644 --- a/drivers/SmartThings/zigbee-button/src/aqara/init.lua +++ b/drivers/SmartThings/zigbee-button/src/aqara/init.lua @@ -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) diff --git a/drivers/SmartThings/zigbee-button/src/test/test_aqara_cube_t1_pro.lua b/drivers/SmartThings/zigbee-button/src/test/test_aqara_cube_t1_pro.lua index 30790575c1..0ba8c38a9c 100644 --- a/drivers/SmartThings/zigbee-button/src/test/test_aqara_cube_t1_pro.lua +++ b/drivers/SmartThings/zigbee-button/src/test/test_aqara_cube_t1_pro.lua @@ -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