diff --git a/drivers/SmartThings/zigbee-switch/src/aqara-light/init.lua b/drivers/SmartThings/zigbee-switch/src/aqara-light/init.lua index 7225246299..3009cb6d0c 100644 --- a/drivers/SmartThings/zigbee-switch/src/aqara-light/init.lua +++ b/drivers/SmartThings/zigbee-switch/src/aqara-light/init.lua @@ -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 @@ -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) @@ -54,6 +57,7 @@ end local aqara_light_handler = { NAME = "Aqara Light Handler", lifecycle_handlers = { + added = device_added, doConfigure = do_configure }, capability_handlers = { diff --git a/drivers/SmartThings/zigbee-switch/src/preferences.lua b/drivers/SmartThings/zigbee-switch/src/preferences.lua index 64c003eb56..928163fef1 100644 --- a/drivers/SmartThings/zigbee-switch/src/preferences.lua +++ b/drivers/SmartThings/zigbee-switch/src/preferences.lua @@ -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 diff --git a/drivers/SmartThings/zigbee-switch/src/test/test_aqara_led_bulb.lua b/drivers/SmartThings/zigbee-switch/src/test/test_aqara_led_bulb.lua index f3b86453dd..45bc9f3242 100644 --- a/drivers/SmartThings/zigbee-switch/src/test/test_aqara_led_bulb.lua +++ b/drivers/SmartThings/zigbee-switch/src/test/test_aqara_led_bulb.lua @@ -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, diff --git a/drivers/SmartThings/zigbee-switch/src/test/test_aqara_light.lua b/drivers/SmartThings/zigbee-switch/src/test/test_aqara_light.lua index a9517ab626..6bd83a7afa 100644 --- a/drivers/SmartThings/zigbee-switch/src/test/test_aqara_light.lua +++ b/drivers/SmartThings/zigbee-switch/src/test/test_aqara_light.lua @@ -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] = { @@ -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,