Skip to content

Commit

Permalink
Merge pull request #1826 from SmartThingsCommunity/beta
Browse files Browse the repository at this point in the history
  • Loading branch information
dljsjr authored Dec 16, 2024
2 parents 3f9dd75 + 0d92800 commit f83728d
Show file tree
Hide file tree
Showing 21 changed files with 121 additions and 72 deletions.
11 changes: 11 additions & 0 deletions drivers/SmartThings/matter-sensor/fingerprints.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,17 @@ matterManufacturer:
vendorId: 0x1021
productId: 0x0001
deviceProfileName: motion-contact-battery
# Neo
- id: "4991/1122"
deviceLabel: Door Sensor
vendorId: 0x137F
productId: 0x0462
deviceProfileName: contact-battery
- id: "4991/1123"
deviceLabel: Motion Sensor
vendorId: 0x137F
productId: 0x0463
deviceProfileName: motion-battery
#Tuo
- id: "5150/3"
deviceLabel: "TUO Temperature Sensor"
Expand Down
11 changes: 11 additions & 0 deletions drivers/SmartThings/matter-switch/fingerprints.yml
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,12 @@ matterManufacturer:
vendorId: 0x115A
productId: 0x004B
deviceProfileName: light-color-level-2700K-6500K
#Neo
- id: "4991/635"
deviceLabel: Power Plug
vendorId: 0x137F
productId: 0x027B
deviceProfileName: plug-binary
#SONOFF
- id: "SONOFF MINIR4M"
deviceLabel: Smart Plug-in Unit
Expand Down Expand Up @@ -578,6 +584,11 @@ matterManufacturer:
vendorId: 0x147F
productId: 0x0004
deviceProfileName: switch-binary
- id: "5247/2"
deviceLabel: UTEC Smart Matter Light Bulb
vendorId: 0x147F
productId: 0x0002
deviceProfileName: light-color-level-2700K-6500K
#WiZ
- id: "WiZ A19"
deviceLabel: WiZ A19
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,14 +256,6 @@ test.register_message_test(
{ capability = "switch", component = "main", command = "on", args = { } }
}
},
{
channel = "devices",
direction = "send",
message = {
"register_native_capability_cmd_handler",
{ device_uuid = mock_device.id, capability_id = "switch", capability_cmd_id = "on" }
}
},
{
channel = "matter",
direction = "send",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,9 @@ end

local function test_init_water_valve()
test.mock_device.add_test_device(mock_device_water_valve)
test.socket.device_lifecycle:__queue_receive({ mock_device_water_valve.id, "doConfigure" })
mock_device_water_valve:expect_metadata_update({ profile = "water-valve-level" })
mock_device_water_valve:expect_metadata_update({ provisioning_state = "PROVISIONED" })
end

local function test_init_parent_child_different_types()
Expand Down Expand Up @@ -394,6 +396,7 @@ local function test_init_parent_child_unsupported_device_type()
})
end


test.register_coroutine_test(
"Test profile change on init for onoff parent cluster as server",
function()
Expand Down
3 changes: 3 additions & 0 deletions drivers/SmartThings/matter-thermostat/src/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,9 @@ end

local function temp_event_handler(attribute)
return function(driver, device, ib, response)
if ib.data.value == nil then
return
end
local unit = "C"

-- Only emit the capability for RPC version >= 5, since unit conversion for
Expand Down
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
4 changes: 2 additions & 2 deletions drivers/SmartThings/zigbee-lock/src/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -322,11 +322,11 @@ local lock_state_handler = function(driver, device, value, zb_rx)
local delay = device:get_field(DELAY_LOCK_EVENT) or 100
if (delay < MAX_DELAY) then
device.thread:call_with_delay(delay+.5, function ()
device:emit_event_for_endpoint(zb_rx.address_header.src_endpoint.value, LOCK_STATE[value.value])
device:emit_event_for_endpoint(zb_rx.address_header.src_endpoint.value, LOCK_STATE[value.value] or attr.unknown())
end)
else
device:set_field(DELAY_LOCK_EVENT, socket.gettime())
device:emit_event_for_endpoint(zb_rx.address_header.src_endpoint.value, LOCK_STATE[value.value])
device:emit_event_for_endpoint(zb_rx.address_header.src_endpoint.value, LOCK_STATE[value.value] or attr.unknown())
end
end

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
14 changes: 13 additions & 1 deletion drivers/SmartThings/zigbee-switch/src/preferences.lua
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,19 @@ preferences.update_preferences = function(driver, device, args)
local prefs = preferences.get_device_parameters(device)
if prefs ~= nil then
for id, value in pairs(device.preferences) do
if not (args and args.old_st_store) or (args.old_st_store.preferences[id] ~= value and prefs and prefs[id]) then
if not (args and args.old_st_store and args.old_st_store.preferences) or (args.old_st_store.preferences[id] ~= value and prefs and prefs[id]) then
local message = prefs[id](device, value)
device:send(message)
end
end
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ test.register_coroutine_test(
function()
test.timer.__create_and_queue_test_time_advance_timer(2, "oneshot")
test.socket.capability:__queue_receive({mock_device.id, { capability = "colorControl", component = "main", command = "setColor", args = { { hue = 50, saturation = 50 } } } })
mock_device:expect_native_cmd_handler_registration("colorControl", "setColor")
test.socket.zigbee:__expect_send(
{
mock_device.id,
Expand Down Expand Up @@ -382,6 +383,7 @@ test.register_coroutine_test(
function()
test.socket.zigbee:__set_channel_ordering("relaxed")
test.socket.capability:__queue_receive({mock_device.id, { capability = "colorTemperature", component = "main", command = "setColorTemperature", args = {1800}}})
mock_device:expect_native_cmd_handler_registration("colorTemperature", "setColorTemperature")
test.socket.zigbee:__expect_send({mock_device.id, ColorControl.server.commands.MoveToColorTemperature(mock_device, 556, 0x0000)})
test.socket.zigbee:__expect_send({mock_device.id, OnOff.server.commands.On(mock_device)})
test.wait_for_events()
Expand Down
22 changes: 13 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 Expand Up @@ -120,6 +123,7 @@ test.register_coroutine_test(
test.socket.capability:__queue_receive({ mock_device.id,
{ capability = "colorTemperature", component = "main", command = "setColorTemperature", args = { 200 } } })

mock_device:expect_native_cmd_handler_registration("colorTemperature", "setColorTemperature")
local temp_in_mired = math.floor(1000000 / 200)
test.socket.zigbee:__expect_send(
{
Expand Down
22 changes: 15 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 Expand Up @@ -121,6 +128,7 @@ test.register_coroutine_test(
test.socket.capability:__queue_receive({ mock_device.id,
{ capability = "colorTemperature", component = "main", command = "setColorTemperature", args = { 200 } } })

mock_device:expect_native_cmd_handler_registration("colorTemperature", "setColorTemperature")
local temp_in_mired = math.floor(1000000 / 200)
test.socket.zigbee:__expect_send(
{
Expand Down
3 changes: 3 additions & 0 deletions drivers/SmartThings/zigbee-switch/src/test/test_rgb_bulb.lua
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ test.register_coroutine_test(
test.timer.__create_and_queue_test_time_advance_timer(2, "oneshot")
test.socket.capability:__queue_receive({mock_device.id, { capability = "colorControl", component = "main", command = "setHue", args = { 50 } } })

mock_device:expect_native_cmd_handler_registration("colorControl", "setHue")
test.socket.zigbee:__expect_send({ mock_device.id, OnOff.commands.On(mock_device) })

local hue = math.floor((50 * 0xFE) / 100.0 + 0.5)
Expand All @@ -154,6 +155,7 @@ test.register_coroutine_test(
test.timer.__create_and_queue_test_time_advance_timer(2, "oneshot")
test.socket.capability:__queue_receive({mock_device.id, { capability = "colorControl", component = "main", command = "setSaturation", args = { 50 } } })

mock_device:expect_native_cmd_handler_registration("colorControl", "setSaturation")
test.socket.zigbee:__expect_send({ mock_device.id, OnOff.commands.On(mock_device) })

local saturation = math.floor((50 * 0xFE) / 100.0 + 0.5)
Expand All @@ -176,6 +178,7 @@ test.register_coroutine_test(
function()
test.timer.__create_and_queue_test_time_advance_timer(2, "oneshot")
test.socket.capability:__queue_receive({mock_device.id, { capability = "colorControl", component = "main", command = "setColor", args = { { hue = 50, saturation = 50 } } } })
mock_device:expect_native_cmd_handler_registration("colorControl", "setColor")
test.socket.zigbee:__expect_send(
{
mock_device.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ test.register_coroutine_test(
test.timer.__create_and_queue_test_time_advance_timer(2, "oneshot")
test.socket.capability:__queue_receive({mock_device.id, { capability = "colorControl", component = "main", command = "setHue", args = { 50 } } })

mock_device:expect_native_cmd_handler_registration("colorControl", "setHue")
test.socket.zigbee:__expect_send({ mock_device.id, OnOff.commands.On(mock_device) })

local hue = math.floor((50 * 0xFE) / 100.0 + 0.5)
Expand All @@ -185,6 +186,7 @@ test.register_coroutine_test(
test.timer.__create_and_queue_test_time_advance_timer(2, "oneshot")
test.socket.capability:__queue_receive({mock_device.id, { capability = "colorControl", component = "main", command = "setSaturation", args = { 50 } } })

mock_device:expect_native_cmd_handler_registration("colorControl", "setSaturation")
test.socket.zigbee:__expect_send({ mock_device.id, OnOff.commands.On(mock_device) })

local saturation = math.floor((50 * 0xFE) / 100.0 + 0.5)
Expand All @@ -208,6 +210,7 @@ test.register_coroutine_test(
test.timer.__create_and_queue_test_time_advance_timer(2, "oneshot")
test.socket.capability:__queue_receive({mock_device.id, { capability = "colorControl", component = "main", command = "setColor", args = { { hue = 50, saturation = 50 } } } })

mock_device:expect_native_cmd_handler_registration("colorControl", "setColor")
test.socket.zigbee:__expect_send({ mock_device.id, OnOff.server.commands.On(mock_device) })

local hue = math.floor((50 * 0xFE) / 100.0 + 0.5)
Expand All @@ -228,7 +231,7 @@ test.register_coroutine_test(
)

test.register_coroutine_test(
"Set Saturation command test",
"Set ColorTemperature command test",
function()
test.timer.__create_and_queue_test_time_advance_timer(1, "oneshot")
test.socket.capability:__queue_receive({mock_device.id, { capability = "colorTemperature", component = "main", command = "setColorTemperature", args = { 200 } } })
Expand Down
Loading

0 comments on commit f83728d

Please sign in to comment.