-
Notifications
You must be signed in to change notification settings - Fork 523
WWSTCERT-9861 Add Zooz ZSE42 to zwave-sensor (for WWST Cert) #2683
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| name: zooz-zse42-water | ||
| components: | ||
| - id: main | ||
| capabilities: | ||
| - id: waterSensor | ||
| version: 1 | ||
| - id: battery | ||
| version: 1 | ||
| - id: refresh | ||
| version: 1 | ||
| - id: firmwareUpdate | ||
| version: 1 | ||
| categories: | ||
| - name: LeakSensor | ||
| preferences: | ||
| #param 1 | ||
| - name: "ledIndicator" | ||
| title: "LED Indicator" | ||
| description: "When enabled the LED indicator will blink continuously when water is detected." | ||
| required: false | ||
| preferenceType: enumeration | ||
| definition: | ||
| options: | ||
| 1: "Enabled *" | ||
| 0: "Disabled" | ||
| default: 1 | ||
| #param 2 | ||
| - name: "leakAlertClearDelay" | ||
| title: "Leak Alert Clear Delay" | ||
| description: "Default = 0; How long the sensor will wait before sending a 'dry' report to your hub after water is no longer detected." | ||
| required: false | ||
| preferenceType: integer | ||
| definition: | ||
| minimum: 0 | ||
| maximum: 3600 | ||
| default: 0 | ||
| #param 4 | ||
| - name: "lowBatteryAlert" | ||
| title: "Low Battery Alert" | ||
| description: "Battery level threshold for low battery reports." | ||
| required: false | ||
| preferenceType: enumeration | ||
| definition: | ||
| options: | ||
| 10: "10%" | ||
| 15: "15%" | ||
| 20: "20% *" | ||
| 25: "25%" | ||
| 30: "30%" | ||
| 40: "40%" | ||
| 50: "50%" | ||
| default: 20 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| -- Copyright 2025 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 capabilities = require "st.capabilities" | ||
| --- @type st.zwave.CommandClass | ||
| local cc = require "st.zwave.CommandClass" | ||
| --- @type st.zwave.CommandClass.Version | ||
| local Version = (require "st.zwave.CommandClass.Version")({ version = 1 }) | ||
| --- @type st.zwave.CommandClass.WakeUp | ||
| local WakeUp = (require "st.zwave.CommandClass.WakeUp")({ version = 1 }) | ||
|
|
||
| --This sub_driver will populate the currentVersion (firmware) when the firmwareUpdate capability is enabled | ||
| local FINGERPRINTS = { | ||
| { manufacturerId = 0x027A, productType = 0x7000, productId = 0xE002 } -- Zooz ZSE42 Water Sensor | ||
| } | ||
|
|
||
| local function can_handle_fw(opts, driver, device, ...) | ||
| if device:supports_capability_by_id(capabilities.firmwareUpdate.ID) then | ||
| for _, fingerprint in ipairs(FINGERPRINTS) do | ||
| if device:id_match(fingerprint.manufacturerId, fingerprint.productType, fingerprint.productId) then | ||
| local subDriver = require("firmware-version") | ||
| return true, subDriver | ||
| end | ||
| end | ||
| end | ||
| return false | ||
| end | ||
|
|
||
| --Runs upstream handlers (ex zwave_handlers) | ||
| local function call_parent_handler(handlers, self, device, event, args) | ||
| for _, func in ipairs(handlers or {}) do | ||
| func(self, device, event, args) | ||
| end | ||
| end | ||
|
|
||
| --Request version if not populated yet | ||
| local function send_version_get(driver, device) | ||
| if device:get_latest_state("main", capabilities.firmwareUpdate.ID, capabilities.firmwareUpdate.currentVersion.NAME) == nil then | ||
| device:send(Version:Get({})) | ||
| end | ||
| end | ||
|
|
||
| local function version_report(driver, device, cmd) | ||
| local major = cmd.args.application_version | ||
| local minor = cmd.args.application_sub_version | ||
| local fmtFirmwareVersion = string.format("%d.%02d", major, minor) | ||
| device:emit_event(capabilities.firmwareUpdate.currentVersion({ value = fmtFirmwareVersion })) | ||
| end | ||
|
|
||
| local function wakeup_notification(driver, device, cmd) | ||
| send_version_get(driver, device) | ||
| --Call parent WakeUp functions | ||
| call_parent_handler(driver.zwave_handlers[cc.WAKE_UP][WakeUp.NOTIFICATION], driver, device, cmd) | ||
| end | ||
|
|
||
| local function device_init(driver, device) | ||
| --Call main init function | ||
| driver.lifecycle_handlers.init(driver, device) | ||
| --Extras for this sub_driver | ||
| send_version_get(driver, device) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It often happens that, on hub restart, the
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or just leaving it exclusive to the wakeup handler. It may not get populated immediately, but will be eventually.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved to added handler and tested a fresh include, it picked up the version. |
||
| end | ||
|
|
||
| local firmware_version = { | ||
| NAME = "firmware_version", | ||
| can_handle = can_handle_fw, | ||
|
|
||
| lifecycle_handlers = { | ||
| init = device_init, | ||
| }, | ||
| zwave_handlers = { | ||
| [cc.VERSION] = { | ||
| [Version.REPORT] = version_report | ||
| }, | ||
| [cc.WAKE_UP] = { | ||
| [WakeUp.NOTIFICATION] = wakeup_notification | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return firmware_version | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to see a unit test to verify this works
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added unit test with commit b36c150
It checks that both the commands in the sub-driver and the main driver are sent. Ran test myself and it passed.