-
Notifications
You must be signed in to change notification settings - Fork 475
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add thirdreality vibration sensor (#781)
* add thirdreality vibration sensor Change-Id: Idc4f20f4041dfa416b3cccd4063e52669e078740 * Update init.lua * Update init.lua * Create test_thirdreality_multi_sensor.lua * Update test_thirdreality_multi_sensor.lua * Update test_thirdreality_multi_sensor.lua * Update test_thirdreality_multi_sensor.lua * Update test_thirdreality_multi_sensor.lua * Update init.lua * Update fingerprints.yml
- Loading branch information
1 parent
38c1a61
commit e672912
Showing
5 changed files
with
166 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
drivers/SmartThings/zigbee-contact/profiles/thirdreality-multi-sensor.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
name: thirdreality-multi-sensor | ||
components: | ||
- id: main | ||
capabilities: | ||
- id: accelerationSensor | ||
version: 1 | ||
- id: threeAxis | ||
version: 1 | ||
- id: battery | ||
version: 1 | ||
- id: firmwareUpdate | ||
version: 1 | ||
- id: refresh | ||
version: 1 | ||
categories: | ||
- name: MultiFunctionalSensor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
drivers/SmartThings/zigbee-contact/src/multi-sensor/thirdreality-multi/init.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
-- Copyright 2023 SmartThings | ||
-- | ||
-- Licensed under the Apache License, Version 2.0 (the "License"); | ||
-- you may not use this file except in compliance with the License. | ||
-- You may obtain a copy of the License at | ||
-- | ||
-- http://www.apache.org/licenses/LICENSE-2.0 | ||
-- | ||
-- Unless required by applicable law or agreed to in writing, software | ||
-- distributed under the License is distributed on an "AS IS" BASIS, | ||
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
-- See the License for the specific language governing permissions and | ||
-- limitations under the License. | ||
|
||
local zcl_commands = require "st.zigbee.zcl.global_commands" | ||
local multi_utils = require "multi-sensor/multi_utils" | ||
|
||
local THIRDREALITY_ACCELERATION_CLUSTER = 0xFFF1 | ||
local X_ATTR = 0x0001 | ||
local Y_ATTR = 0x0002 | ||
local Z_ATTR = 0x0003 | ||
local ACCEL_ATTR = 0x0000 | ||
|
||
local function multi_sensor_report_handler(driver, device, zb_rx) | ||
local x, y, z | ||
for i,v in ipairs(zb_rx.body.zcl_body.attr_records) do | ||
if (v.attr_id.value == X_ATTR) then | ||
x = v.data.value | ||
elseif (v.attr_id.value == Y_ATTR) then | ||
y = v.data.value | ||
elseif (v.attr_id.value == Z_ATTR) then | ||
z = v.data.value | ||
elseif (v.attr_id.value == ACCEL_ATTR) then | ||
multi_utils.handle_acceleration_report(device, v.data.value) | ||
end | ||
end | ||
multi_utils.handle_three_axis_report(device, x, y, z) | ||
end | ||
|
||
local thirdreality_multi = { | ||
NAME = "ThirdReality Vibration Sensor", | ||
zigbee_handlers = { | ||
global = { | ||
[THIRDREALITY_ACCELERATION_CLUSTER] = { | ||
[zcl_commands.ReportAttribute.ID] = multi_sensor_report_handler, | ||
[zcl_commands.ReadAttributeResponse.ID] = multi_sensor_report_handler | ||
} | ||
} | ||
}, | ||
can_handle = function(opts, driver, device, ...) | ||
return device:get_manufacturer() == "Third Reality, Inc" | ||
end | ||
} | ||
|
||
return thirdreality_multi |
85 changes: 85 additions & 0 deletions
85
drivers/SmartThings/zigbee-contact/src/test/test_thirdreality_multi_sensor.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
local test = require "integration_test" | ||
local capabilities = require "st.capabilities" | ||
local t_utils = require "integration_test.utils" | ||
local zigbee_test_utils = require "integration_test.zigbee_test_utils" | ||
|
||
local cluster_base = require "st.zigbee.cluster_base" | ||
local data_types = require "st.zigbee.data_types" | ||
|
||
local mock_device = test.mock_device.build_test_zigbee_device( | ||
{ | ||
profile = t_utils.get_profile_definition("thirdreality-multi-sensor.yml"), | ||
zigbee_endpoints = { | ||
[1] = { | ||
id = 1, | ||
manufacturer = "Third Reality, Inc", | ||
model = "3RVS01031Z", | ||
server_clusters = { 0x0000, 0x0001, 0xFFF1 } | ||
} | ||
} | ||
} | ||
) | ||
|
||
zigbee_test_utils.prepare_zigbee_env_info() | ||
|
||
local function test_init() | ||
test.mock_device.add_test_device(mock_device) | ||
end | ||
|
||
test.set_test_init_function(test_init) | ||
|
||
|
||
test.register_coroutine_test( | ||
"Acceleration report should be correctly handled", | ||
function() | ||
local acceleration_report_active = { | ||
{ 0x0000, data_types.Bitmap8.ID, 1} | ||
} | ||
local acceleration_report_inactive = { | ||
{ 0x0000, data_types.Bitmap8.ID, 0} | ||
} | ||
test.socket.zigbee:__queue_receive({ | ||
mock_device.id, | ||
zigbee_test_utils.build_attribute_report(mock_device, 0xFFF1, acceleration_report_active, 0x110A) | ||
}) | ||
test.socket.capability:__expect_send( mock_device:generate_test_message("main", capabilities.accelerationSensor.acceleration.active()) ) | ||
test.wait_for_events() | ||
test.socket.zigbee:__queue_receive({ | ||
mock_device.id, | ||
zigbee_test_utils.build_attribute_report(mock_device, 0xFFF1, acceleration_report_inactive, 0x110A) | ||
}) | ||
test.socket.capability:__expect_send( mock_device:generate_test_message("main", capabilities.accelerationSensor.acceleration.inactive()) ) | ||
end | ||
) | ||
|
||
test.register_coroutine_test( | ||
"Acceleration report should be correctly handled", | ||
function() | ||
local attribute_def = {ID = 0x0000,base_type = {ID = data_types.Bitmap8.ID}, _cluster = {ID = 0xFFF1}} | ||
local utils = require "st.utils" | ||
print(utils.stringify_table(attribute_def)) | ||
test.socket.zigbee:__queue_receive({ | ||
mock_device.id, | ||
cluster_base.build_test_read_attr_response(attribute_def, mock_device, 1) | ||
}) | ||
test.socket.capability:__expect_send( mock_device:generate_test_message("main", capabilities.accelerationSensor.acceleration.active()) ) | ||
end | ||
) | ||
|
||
test.register_coroutine_test( | ||
"Three Axis report should be correctly handled", | ||
function() | ||
local attr_report_data = { | ||
{ 0x0001, data_types.Int16.ID, 200}, | ||
{ 0x0002, data_types.Int16.ID, 100}, | ||
{ 0x0003, data_types.Int16.ID, 300}, | ||
} | ||
test.socket.zigbee:__queue_receive({ | ||
mock_device.id, | ||
zigbee_test_utils.build_attribute_report(mock_device, 0xFFF1, attr_report_data, 0x110A) | ||
}) | ||
test.socket.capability:__expect_send( mock_device:generate_test_message("main", capabilities.threeAxis.threeAxis({200, 100, 300})) ) | ||
end | ||
) | ||
|
||
test.run_registered_tests() |