Skip to content

Commit

Permalink
STSE-3372: fix Aqara dimmer blinking (#1774)
Browse files Browse the repository at this point in the history
* STSE-3372: Fix Aqara Dimmer Controller T1 Pro blinking issue

* STSE-3372 update test case

* update test case for doConfigure

fix missing On/OffTransitionTime test
  • Loading branch information
Kwang-Hui authored Dec 5, 2024
1 parent 22590e2 commit 802a03a
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 20 deletions.
12 changes: 8 additions & 4 deletions drivers/SmartThings/zigbee-switch/src/aqara-light/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ local clusters = require "st.zigbee.zcl.clusters"
local cluster_base = require "st.zigbee.cluster_base"
local data_types = require "st.zigbee.data_types"
local capabilities = require "st.capabilities"
local preferences = require "preferences"

local OnOff = clusters.OnOff
local Level = clusters.Level
Expand Down Expand Up @@ -32,13 +33,15 @@ local function do_refresh(self, device)
device:send(ColorControl.attributes.ColorTemperatureMireds:read(device))
end

local function do_configure(self, device)
device:configure()
local function device_added(driver, device, event)
device:send(cluster_base.write_manufacturer_specific_attribute(device,
PRIVATE_CLUSTER_ID, PRIVATE_ATTRIBUTE_ID, MFG_CODE, data_types.Uint8, 1)) -- private
end

local function do_configure(self, device)
device:configure()

device:send(Level.attributes.OnTransitionTime:write(device, 0))
device:send(Level.attributes.OffTransitionTime:write(device, 0))
preferences.sync_preferences(self, device)
device:send(ColorControl.commands.MoveToColorTemperature(device, 200, 0x0000))

do_refresh(self, device)
Expand All @@ -54,6 +57,7 @@ end
local aqara_light_handler = {
NAME = "Aqara Light Handler",
lifecycle_handlers = {
added = device_added,
doConfigure = do_configure
},
capability_handlers = {
Expand Down
12 changes: 12 additions & 0 deletions drivers/SmartThings/zigbee-switch/src/preferences.lua
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,18 @@ preferences.update_preferences = function(driver, device, args)
end
end

preferences.sync_preferences = function(driver, device)
local prefs = preferences.get_device_parameters(device)
if prefs ~= nil then
for id, value in pairs(device.preferences) do
if prefs and prefs[id] then
local message = prefs[id](device, value)
device:send(message)
end
end
end
end

preferences.get_device_parameters = function(zigbee_device)
for _, device in pairs(devices) do
if zigbee_device:get_manufacturer() == device.MATCHING_MATRIX.mfr and
Expand Down
21 changes: 12 additions & 9 deletions drivers/SmartThings/zigbee-switch/src/test/test_aqara_led_bulb.lua
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,24 @@ end

test.set_test_init_function(test_init)

test.register_coroutine_test(
"Handle added lifecycle",
function()
test.socket.zigbee:__set_channel_ordering("relaxed")
test.socket.device_lifecycle:__queue_receive({ mock_device.id, "added" })

test.socket.zigbee:__expect_send({
mock_device.id, cluster_base.write_manufacturer_specific_attribute(mock_device, PRIVATE_CLUSTER_ID,
PRIVATE_ATTRIBUTE_ID, MFG_CODE, data_types.Uint8, 1) })
end
)

test.register_coroutine_test(
"Configure should configure all necessary attributes and refresh device",
function()
test.socket.device_lifecycle:__queue_receive({ mock_device.id, "doConfigure" })
test.socket.zigbee:__set_channel_ordering("relaxed")

test.socket.zigbee:__expect_send(
{
mock_device.id,
cluster_base.write_manufacturer_specific_attribute(mock_device, PRIVATE_CLUSTER_ID, PRIVATE_ATTRIBUTE_ID
, MFG_CODE, data_types.Uint8, 1)
}
)
test.socket.zigbee:__expect_send({ mock_device.id, Level.attributes.OnTransitionTime:write(mock_device, 0) })
test.socket.zigbee:__expect_send({ mock_device.id, Level.attributes.OffTransitionTime:write(mock_device, 0) })
test.socket.zigbee:__expect_send(
{
mock_device.id,
Expand Down
21 changes: 14 additions & 7 deletions drivers/SmartThings/zigbee-switch/src/test/test_aqara_light.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ local TURN_OFF_INDICATOR_ATTRIBUTE_ID = 0x0203
local mock_device = test.mock_device.build_test_zigbee_device(
{
profile = t_utils.get_profile_definition("aqara-light.yml"),
preferences = { ["stse.lightFadeInTimeInSec"] = 0, ["stse.lightFadeOutTimeInSec"] = 0 },
fingerprinted_endpoint_id = 0x01,
zigbee_endpoints = {
[1] = {
Expand All @@ -53,21 +54,27 @@ end

test.set_test_init_function(test_init)

test.register_coroutine_test(
"Handle added lifecycle",
function()
test.socket.zigbee:__set_channel_ordering("relaxed")
test.socket.device_lifecycle:__queue_receive({ mock_device.id, "added" })

test.socket.zigbee:__expect_send({
mock_device.id, cluster_base.write_manufacturer_specific_attribute(mock_device, PRIVATE_CLUSTER_ID,
PRIVATE_ATTRIBUTE_ID, MFG_CODE, data_types.Uint8, 1) })
end
)

test.register_coroutine_test(
"Configure should configure all necessary attributes and refresh device",
function()
test.socket.device_lifecycle:__queue_receive({ mock_device.id, "doConfigure" })
test.socket.zigbee:__set_channel_ordering("relaxed")

test.socket.zigbee:__expect_send(
{
mock_device.id,
cluster_base.write_manufacturer_specific_attribute(mock_device, PRIVATE_CLUSTER_ID, PRIVATE_ATTRIBUTE_ID
, MFG_CODE, data_types.Uint8, 1)
}
)
test.socket.zigbee:__expect_send({ mock_device.id, Level.attributes.OnTransitionTime:write(mock_device, 0) })
test.socket.zigbee:__expect_send({ mock_device.id, Level.attributes.OffTransitionTime:write(mock_device, 0) })

test.socket.zigbee:__expect_send(
{
mock_device.id,
Expand Down

0 comments on commit 802a03a

Please sign in to comment.