Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG-8648: PGC sensors have different open/closed handling on garages #1038

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion drivers/SmartThings/zigbee-contact/src/smartsense-multi/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,34 @@ local function status_report_handler(driver, device, zb_rx)
temperature_handler(device, temperature)
end

local handle_garage_event = function(device, value)
local event
if value > 825 then
event = capabilities.contactSensor.contact.open()
elseif value < 100 then
event = capabilities.contactSensor.contact.closed()
end
if event ~= nil then
device:emit_event(event)
end
end

local handle_three_axis_report = function(device, x, y, z)
if x ~= nil and y ~= nil and z ~= nil then
device:emit_event(capabilities.threeAxis.threeAxis({value = {x, y, z}}))
end
if z ~= nil and device.preferences["certifiedpreferences.garageSensor"] then
handle_garage_event(device, math.abs(z))
end
end

local function xyz_handler(driver, device, zb_rx)
-- This is a custom cluster command for the kickstarter multi.
-- It contains 3 2 byte signed integers which are X,Y,Z acceleration values that are used to define orientation.
local x = multi_utils.convert_to_signedInt16(zb_rx.body.zcl_body.body_bytes:byte(1), zb_rx.body.zcl_body.body_bytes:byte(2))
local y = multi_utils.convert_to_signedInt16(zb_rx.body.zcl_body.body_bytes:byte(3), zb_rx.body.zcl_body.body_bytes:byte(4))
local z = multi_utils.convert_to_signedInt16(zb_rx.body.zcl_body.body_bytes:byte(5), zb_rx.body.zcl_body.body_bytes:byte(6))
multi_utils.handle_three_axis_report(device, x, y, z)
handle_three_axis_report(device, x, y, z)
end

local smartsense_multi = {
Expand Down
148 changes: 94 additions & 54 deletions drivers/SmartThings/zigbee-contact/src/test/test_smartsense_multi.lua
Original file line number Diff line number Diff line change
Expand Up @@ -246,72 +246,112 @@ test.register_coroutine_test(
)

test.register_coroutine_test(
"KK - Report from cluster 0xFC03, command 0x09 should be handled as: Temperature (25.5 C), Acceleration - active, Contact - closed, battery(97%)",
function()
test.socket.zigbee:__queue_receive({
mock_device.id,
build_multi_status_report_message(mock_device, "\x88\x00\x00\x74")
})
test.socket.capability:__set_channel_ordering("relaxed")
test.socket.capability:__expect_send(mock_device:generate_test_message("main", capabilities.temperatureMeasurement.temperature({ value = 13.60, unit = "C" })))
test.socket.capability:__expect_send(mock_device:generate_test_message("main", capabilities.accelerationSensor.acceleration.inactive()))
test.socket.capability:__expect_send(mock_device:generate_test_message("main", capabilities.contactSensor.contact.closed()))
test.socket.capability:__expect_send(mock_device:generate_test_message("main", capabilities.battery.battery(97)))
end
"KK - Report from cluster 0xFC03, command 0x09 should be handled as: Temperature (25.5 C), Acceleration - active, Contact - closed, battery(97%)",
function()
test.socket.zigbee:__queue_receive({
mock_device.id,
build_multi_status_report_message(mock_device, "\x88\x00\x00\x74")
})
test.socket.capability:__set_channel_ordering("relaxed")
test.socket.capability:__expect_send(mock_device:generate_test_message("main", capabilities.temperatureMeasurement.temperature({ value = 13.60, unit = "C" })))
test.socket.capability:__expect_send(mock_device:generate_test_message("main", capabilities.accelerationSensor.acceleration.inactive()))
test.socket.capability:__expect_send(mock_device:generate_test_message("main", capabilities.contactSensor.contact.closed()))
test.socket.capability:__expect_send(mock_device:generate_test_message("main", capabilities.battery.battery(97)))
end
)

test.register_coroutine_test(
"Report from cluster 0xFC03, command 0x09 should be handled as: Temperature (25.5 C), Acceleration - active, Contact - closed, battery(60%)",
function()
test.socket.zigbee:__queue_receive({
mock_device.id,
build_multi_status_report_message(mock_device, "\xFF\x00\x00\x48")
})
test.socket.capability:__set_channel_ordering("relaxed")
test.socket.capability:__expect_send(mock_device:generate_test_message("main", capabilities.temperatureMeasurement.temperature({ value = 25.5, unit = "C" })))
test.socket.capability:__expect_send(mock_device:generate_test_message("main", capabilities.accelerationSensor.acceleration.inactive()))
test.socket.capability:__expect_send(mock_device:generate_test_message("main", capabilities.contactSensor.contact.closed()))
test.socket.capability:__expect_send(mock_device:generate_test_message("main", capabilities.battery.battery(60)))
end
"Report from cluster 0xFC03, command 0x09 should be handled as: Temperature (25.5 C), Acceleration - active, Contact - closed, battery(60%)",
function()
test.socket.zigbee:__queue_receive({
mock_device.id,
build_multi_status_report_message(mock_device, "\xFF\x00\x00\x48")
})
test.socket.capability:__set_channel_ordering("relaxed")
test.socket.capability:__expect_send(mock_device:generate_test_message("main", capabilities.temperatureMeasurement.temperature({ value = 25.5, unit = "C" })))
test.socket.capability:__expect_send(mock_device:generate_test_message("main", capabilities.accelerationSensor.acceleration.inactive()))
test.socket.capability:__expect_send(mock_device:generate_test_message("main", capabilities.contactSensor.contact.closed()))
test.socket.capability:__expect_send(mock_device:generate_test_message("main", capabilities.battery.battery(60)))
end
)

test.register_coroutine_test(
"Report from cluster 0xFC03, command 0x09 should be handled as: Temperature (26.0 C), Acceleration - active, Contact - closed, battery(60%)",
function()
test.socket.zigbee:__queue_receive({
mock_device.id,
build_multi_status_report_message(mock_device, "\x04\x01\x00\x48")
})
test.socket.capability:__set_channel_ordering("relaxed")
test.socket.capability:__expect_send(mock_device:generate_test_message("main", capabilities.temperatureMeasurement.temperature({ value = 26.0, unit = "C" })))
test.socket.capability:__expect_send(mock_device:generate_test_message("main", capabilities.accelerationSensor.acceleration.inactive()))
test.socket.capability:__expect_send(mock_device:generate_test_message("main", capabilities.contactSensor.contact.closed()))
test.socket.capability:__expect_send(mock_device:generate_test_message("main", capabilities.battery.battery(60)))
end
"Report from cluster 0xFC03, command 0x09 should be handled as: Temperature (26.0 C), Acceleration - active, Contact - closed, battery(60%)",
function()
test.socket.zigbee:__queue_receive({
mock_device.id,
build_multi_status_report_message(mock_device, "\x04\x01\x00\x48")
})
test.socket.capability:__set_channel_ordering("relaxed")
test.socket.capability:__expect_send(mock_device:generate_test_message("main", capabilities.temperatureMeasurement.temperature({ value = 26.0, unit = "C" })))
test.socket.capability:__expect_send(mock_device:generate_test_message("main", capabilities.accelerationSensor.acceleration.inactive()))
test.socket.capability:__expect_send(mock_device:generate_test_message("main", capabilities.contactSensor.contact.closed()))
test.socket.capability:__expect_send(mock_device:generate_test_message("main", capabilities.battery.battery(60)))
end
)

test.register_coroutine_test(
"Report from cluster 0xFC03, command 0x05 should be handled as: threeAxis(1050, -3, 9)",
function()
test.socket.zigbee:__queue_receive({
mock_device.id,
build_three_axis_report_message(mock_device, "\x1A\x04\xFD\xFF\x09\x00")
})
test.socket.capability:__set_channel_ordering("relaxed")
test.socket.capability:__expect_send(mock_device:generate_test_message("main", capabilities.threeAxis.threeAxis({1050, -3, 9})) )
end
"Report from cluster 0xFC03, command 0x05 should be handled as: threeAxis(1050, -3, 9)",
function()
test.socket.zigbee:__queue_receive({
mock_device.id,
build_three_axis_report_message(mock_device, "\x1A\x04\xFD\xFF\x09\x00")
})
test.socket.capability:__set_channel_ordering("relaxed")
test.socket.capability:__expect_send(mock_device:generate_test_message("main", capabilities.threeAxis.threeAxis({1050, -3, 9})) )
end
)

test.register_coroutine_test(
"Report from cluster 0xFC03, command 0x05 should be handled as: threeAxis(1123,-130,-24)",
function()
test.socket.zigbee:__queue_receive({
mock_device.id,
build_three_axis_report_message(mock_device, "\x63\x04\x7E\xFF\xE8\xFF")
})
test.socket.capability:__set_channel_ordering("relaxed")
test.socket.capability:__expect_send(mock_device:generate_test_message("main", capabilities.threeAxis.threeAxis({1123, -130, -24})) )
end
"Report from cluster 0xFC03, command 0x05 should be handled as: threeAxis(1123,-130,-24)",
function()
test.socket.zigbee:__queue_receive({
mock_device.id,
build_three_axis_report_message(mock_device, "\x63\x04\x7E\xFF\xE8\xFF")
})
test.socket.capability:__set_channel_ordering("relaxed")
test.socket.capability:__expect_send(mock_device:generate_test_message("main", capabilities.threeAxis.threeAxis({1123, -130, -24})) )
end
)

test.register_coroutine_test(
"Report from cluster 0xFC03, command 0x05 should be handled as: threeAxis(1123,-130,-24) and closed",
function()
test.socket.device_lifecycle():__queue_receive(mock_device:generate_info_changed(
{
preferences = {
["certifiedpreferences.garageSensor"] = true
}
}
))
test.wait_for_events()
test.socket.zigbee:__queue_receive({
mock_device.id,
build_three_axis_report_message(mock_device, "\x63\x04\x7E\xFF\xE8\xFF")
})
test.socket.capability:__expect_send(mock_device:generate_test_message("main", capabilities.threeAxis.threeAxis({1123, -130, -24})) )
test.socket.capability:__expect_send(mock_device:generate_test_message("main", capabilities.contactSensor.contact.closed()))
end
)

test.register_coroutine_test(
"Report from cluster 0xFC03, command 0x05 should be handled as: threeAxis(-130,-24,1123) and open",
function()
test.socket.device_lifecycle():__queue_receive(mock_device:generate_info_changed(
{
preferences = {
["certifiedpreferences.garageSensor"] = true
}
}
))
test.wait_for_events()
test.socket.zigbee:__queue_receive({
mock_device.id,
build_three_axis_report_message(mock_device, "\x7E\xFF\xE8\xFF\x63\x04")
})
test.socket.capability:__expect_send(mock_device:generate_test_message("main", capabilities.threeAxis.threeAxis({-130, -24, 1123})) )
test.socket.capability:__expect_send(mock_device:generate_test_message("main", capabilities.contactSensor.contact.open()))
end
)

test.run_registered_tests()
Loading