WWSTCERT-8745 Add support to frient vibration sensor wiszb 137#2454
Conversation
…ibration-sensor-WISZB-137
…tps://github.com/marcintyminski/SmartThingsEdgeDrivers into Add-support-to-frient-vibration-sensor-WISZB-137
|
Duplicate profile check: Passed - no duplicate profiles detected. |
|
Channel deleted. |
Test Results 71 files 485 suites 0s ⏱️ Results for commit 9ff61c4. ♻️ This comment has been updated with latest results. |
|
Minimum allowed coverage is Generated by 🐒 cobertura-action against 9ff61c4 |
| if attribute_id == 0x0000 then | ||
| measured_x = axis_value | ||
| device:set_field("measured_x", measured_x) | ||
| log.trace("Updated X value: " .. axis_value) |
There was a problem hiding this comment.
if you're satisfied with the behavior, please remove the logging
| ID = 0xFC04, | ||
| ManufacturerSpecificCode = 0x1015, | ||
| attributes = { | ||
| MeasuredValueX = { ID = 0x0000, data_type = data_types.name_to_id_map["Int16"] }, |
There was a problem hiding this comment.
you can just use data_types.Int16
| log.trace "Initializing sensor" | ||
| battery_defaults.build_linear_voltage_init(2.3, 3.0)(driver, device) | ||
| --Add the manufacturer-specific attributes to generate their configure reporting and bind requests | ||
| for _, config in pairs(get_cluster_configurations()) do | ||
| device:add_configured_attribute(config) | ||
| end |
| if device.preferences.garageSensor == "Yes" then | ||
| if device.preferences.contactSensorAxis == "X" then | ||
| local initial_position = device.preferences.sensorInitialPosition or 0 | ||
| if math.abs(initial_position - measured_x) >= device.preferences.contactSensorValue - device.preferences.contactSensorValue * (device.preferences.tolerance / 100) then | ||
| device:emit_event(capabilities.contactSensor.contact.open()) | ||
| else | ||
| device:emit_event(capabilities.contactSensor.contact.closed()) | ||
| end | ||
| elseif device.preferences.contactSensorAxis == "Y" then | ||
| local initial_position = device.preferences.sensorInitialPosition or 0 | ||
| if math.abs(initial_position - measured_y) >= device.preferences.contactSensorValue - device.preferences.contactSensorValue * (device.preferences.tolerance / 100) then | ||
| device:emit_event(capabilities.contactSensor.contact.open()) | ||
| else | ||
| device:emit_event(capabilities.contactSensor.contact.closed()) | ||
| end | ||
| elseif device.preferences.contactSensorAxis == "Z" then | ||
| local initial_position = device.preferences.sensorInitialPosition or 0 | ||
| if math.abs(initial_position - measured_z) >= device.preferences.contactSensorValue - device.preferences.contactSensorValue * (device.preferences.tolerance / 100) then | ||
| device:emit_event(capabilities.contactSensor.contact.open()) | ||
| else | ||
| device:emit_event(capabilities.contactSensor.contact.closed()) | ||
| end | ||
| end | ||
| end |
There was a problem hiding this comment.
| if device.preferences.garageSensor == "Yes" then | |
| if device.preferences.contactSensorAxis == "X" then | |
| local initial_position = device.preferences.sensorInitialPosition or 0 | |
| if math.abs(initial_position - measured_x) >= device.preferences.contactSensorValue - device.preferences.contactSensorValue * (device.preferences.tolerance / 100) then | |
| device:emit_event(capabilities.contactSensor.contact.open()) | |
| else | |
| device:emit_event(capabilities.contactSensor.contact.closed()) | |
| end | |
| elseif device.preferences.contactSensorAxis == "Y" then | |
| local initial_position = device.preferences.sensorInitialPosition or 0 | |
| if math.abs(initial_position - measured_y) >= device.preferences.contactSensorValue - device.preferences.contactSensorValue * (device.preferences.tolerance / 100) then | |
| device:emit_event(capabilities.contactSensor.contact.open()) | |
| else | |
| device:emit_event(capabilities.contactSensor.contact.closed()) | |
| end | |
| elseif device.preferences.contactSensorAxis == "Z" then | |
| local initial_position = device.preferences.sensorInitialPosition or 0 | |
| if math.abs(initial_position - measured_z) >= device.preferences.contactSensorValue - device.preferences.contactSensorValue * (device.preferences.tolerance / 100) then | |
| device:emit_event(capabilities.contactSensor.contact.open()) | |
| else | |
| device:emit_event(capabilities.contactSensor.contact.closed()) | |
| end | |
| end | |
| end | |
| if device.preferences.garageSensor == "Yes" then | |
| local garageAxis = measured_x | |
| if device.preferences.contactSensorAxis == "Y" then | |
| garageAxis = measured_y | |
| elseif device.preferences.contactSensorAxis == "Z" then | |
| garageAxis = measured_z | |
| end | |
| local initial_position = device.preferences.sensorInitialPosition or 0 | |
| if math.abs(initial_position - garageAxis) >= device.preferences.contactSensorValue - device.preferences.contactSensorValue * (device.preferences.tolerance / 100) then | |
| device:emit_event(capabilities.contactSensor.contact.open()) | |
| else | |
| device:emit_event(capabilities.contactSensor.contact.closed()) | |
| end | |
| end |
There was a problem hiding this comment.
I have made a change and pushed the change to pr
…ibration-sensor-WISZB-137
|
|
||
| -- Ensure all values are non-nil before emitting | ||
| if measured_x and measured_y and measured_z then | ||
| device:emit_event(threeAxis.threeAxis({measured_x, measured_y, measured_z})) |
There was a problem hiding this comment.
Don't the measured_{} fields need to be reset after an event is sent so that a new event is only sent when you get three new measurements?
There was a problem hiding this comment.
would be good to have a test case of this.
There was a problem hiding this comment.
@greens Each value shall update whenever any of them changes; therefore, not only when 3 of them change.
There was a problem hiding this comment.
Just to clarify on it, the body will always contains of three values, as these values are never nill or empty. Also, each of values shall update whenever there is a change on them.
There was a problem hiding this comment.
would be good to have a test case of this.
I can see that we have some test cases for X, Y, Z axes cases - can you clarify on which additional test cases you're thinking about? Thanks!
There was a problem hiding this comment.
The device would send bundled report with the changed value, and last cached values for remaining axes.
There was a problem hiding this comment.
Right, so your driver would send three events. 2 of those are likely to get bounced for being duplicates, but it's not an ideal situation to have to rely on that.
Since you can always rely on the device sending all 3 attributes every time, it should be easy to update the driver to only send one event after it's received a report for all three attributes.
There was a problem hiding this comment.
I think you can now omit the usage of device:set_field and get_field.
| if measured_x and measured_y and measured_z then | ||
| device:emit_event(threeAxis.threeAxis({measured_x, measured_y, measured_z})) | ||
|
|
||
| if device.preferences.garageSensor == "Yes" then |
There was a problem hiding this comment.
a better check is probably to see if the device supports the contactSensor capability.
| - id: refresh | ||
| version: 1 | ||
| categories: | ||
| - name: VibrationsSensor |
There was a problem hiding this comment.
I am not certain this category is defined.
There was a problem hiding this comment.
You're right. Changed it to ContactSensor
Check all that apply
Type of Change
Checklist
Description of Change
Summary of Completed Tests