Skip to content

Commit

Permalink
Merge branch 'matter-switch-add-profile-for-button-plug-device' of gi…
Browse files Browse the repository at this point in the history
…thub.com:SmartThingsCommunity/SmartThingsEdgeDrivers into matter-switch-add-profile-for-button-plug-device
  • Loading branch information
nickolas-deboom committed Dec 9, 2024
2 parents 6a16137 + 859acba commit c1ce7d3
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 22 deletions.
6 changes: 4 additions & 2 deletions drivers/SmartThings/virtual-switch/src/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ local capabilities = require "st.capabilities"
local Driver = require "st.driver"

local function force_state_change(device)
if device.preferences["certifiedpreferences.forceStateChange"] then
if device.preferences == nil or device.preferences["certifiedpreferences.forceStateChange"] == nil then
return {state_change = true}
else
elseif not device.preferences["certifiedpreferences.forceStateChange"] then
return nil
else
return {state_change = true}
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,15 @@ local mock_simple_device = test.mock_device.build_test_generic_device(
}
)

local mock_device_no_prefs = test.mock_device.build_test_generic_device(
{
profile = t_utils.get_profile_definition("virtual-dimmer-switch.yml"),
}
)

local function test_init()
test.mock_device.add_test_device(mock_simple_device)
test.mock_device.add_test_device(mock_device_no_prefs)
end

test.set_test_init_function(test_init)
Expand Down Expand Up @@ -53,6 +60,22 @@ test.register_message_test(
}
)

test.register_message_test(
"Reported on off status should be handled: on",
{
{
channel = "capability",
direction = "receive",
message = { mock_device_no_prefs.id, { capability = "switch", component = "main", command = "on", args = {}}}
},
{
channel = "capability",
direction = "send",
message = mock_device_no_prefs:generate_test_message("main", capabilities.switch.switch.on({state_change=true}))
}
}
)

test.register_message_test(
"Reported on off status should be handled: off",
{
Expand Down
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 c1ce7d3

Please sign in to comment.