Skip to content

Commit

Permalink
add thirdreality vibration sensor (#781)
Browse files Browse the repository at this point in the history
* 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
weihuan1111 authored Oct 11, 2023
1 parent 38c1a61 commit e672912
Show file tree
Hide file tree
Showing 5 changed files with 166 additions and 3 deletions.
7 changes: 6 additions & 1 deletion drivers/SmartThings/zigbee-contact/fingerprints.yml
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,11 @@ zigbeeManufacturer:
manufacturer: SmartThings
model: PGC313EU
deviceProfileName: multi-sensor
- id: "Third Reality/3RVS01031Z"
deviceLabel: ThirdReality Vibration Sensor
manufacturer: Third Reality, Inc
model: 3RVS01031Z
deviceProfileName: thirdreality-multi-sensor
zigbeeGeneric:
- id: "contact-generic"
deviceLabel: "Zigbee Contact Sensor"
Expand All @@ -207,4 +212,4 @@ zigbeeGeneric:
- 0xFC01
deviceIdentifiers:
- 0x0139
deviceProfileName: multi-sensor
deviceProfileName: multi-sensor
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
6 changes: 4 additions & 2 deletions drivers/SmartThings/zigbee-contact/src/multi-sensor/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ local MULTI_SENSOR_FINGERPRINTS = {
{ mfr = "CentraLite", model = "3321" },
{ mfr = "CentraLite", model = "3321-S" },
{ mfr = "SmartThings", model = "multiv4" },
{ mfr = "Samjin", model = "multi" }
{ mfr = "Samjin", model = "multi" },
{ mfr = "Third Reality, Inc", model = "3RVS01031Z" }
}

local function can_handle_zigbee_multi_sensor(opts, driver, device, ...)
Expand Down Expand Up @@ -94,7 +95,8 @@ local multi_sensor = {
sub_drivers = {
require("multi-sensor/smartthings-multi"),
require("multi-sensor/samjin-multi"),
require("multi-sensor/centralite-multi")
require("multi-sensor/centralite-multi"),
require("multi-sensor/thirdreality-multi")
},
can_handle = can_handle_zigbee_multi_sensor
}
Expand Down
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
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()

0 comments on commit e672912

Please sign in to comment.