-
Notifications
You must be signed in to change notification settings - Fork 556
[WWSTCERT-13446, WWSTCERT-13450, WWSTCERT-13454, WWSTCERT-13458] SONOFF/SWV1C #3157
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
d3ca759
244e0ee
539f602
caee9a2
b938a79
3270a93
30cf526
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,14 @@ | ||
| name: sonoff-irrigation | ||
| components: | ||
| - id: main | ||
| capabilities: | ||
| - id: valve | ||
| version: 1 | ||
| - id: battery | ||
| version: 1 | ||
| - id: firmwareUpdate | ||
| version: 1 | ||
| - id: refresh | ||
| version: 1 | ||
| categories : | ||
| - name: WaterValve | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,24 @@ | ||
| -- Copyright 2022 SmartThings, Inc. | ||
| -- Licensed under the Apache License, Version 2.0 | ||
|
|
||
| -- Copyright 2022 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. | ||
|
Comment on lines
+1
to
+13
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. @yanggx24 no need to change it. Please keep it as it was. |
||
|
|
||
| local ZigbeeDriver = require "st.zigbee" | ||
| local defaults = require "st.zigbee.defaults" | ||
|
|
||
| --ZCL | ||
| local zcl_clusters = require "st.zigbee.zcl.clusters" | ||
| local Basic = zcl_clusters.Basic | ||
| local PowerConfiguration = zcl_clusters.PowerConfiguration | ||
| --Capability | ||
| local capabilities = require "st.capabilities" | ||
| local battery = capabilities.battery | ||
|
|
@@ -27,6 +38,17 @@ local zigbee_valve_driver_template = { | |
| refresh | ||
| }, | ||
| cluster_configurations = { | ||
| [battery.ID] = { | ||
| { | ||
| cluster = PowerConfiguration.ID, | ||
| attribute = PowerConfiguration.attributes.BatteryPercentageRemaining.ID, | ||
| minimum_interval = 300, | ||
| maximum_interval = 900, | ||
| data_type = PowerConfiguration.attributes.BatteryPercentageRemaining.base_type, | ||
| reportable_change = 2, | ||
| configurable = true | ||
| } | ||
| }, | ||
| [powerSource.ID] = { | ||
| { | ||
| cluster = Basic.ID, | ||
|
|
@@ -41,9 +63,10 @@ local zigbee_valve_driver_template = { | |
| lifecycle_handlers = { | ||
| added = device_added | ||
| }, | ||
| sub_drivers = require("sub_drivers"), | ||
| health_check = false, | ||
| shared_device_thread_enabled = true, | ||
|
Comment on lines
-44
to
-46
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. Add the new sonoff subdriver to the sub_drivers.lua file in this driver and use lazy loading.
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. @yanggx24 please change it according to @aleclorimer's remarks
Comment on lines
-45
to
-46
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. These should be kept
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. @yanggx24 please change it according to @aleclorimer's remarks |
||
| sub_drivers = { | ||
| require("sinope"), | ||
| require("sonoff") | ||
| } | ||
| } | ||
|
|
||
| defaults.register_for_default_handlers(zigbee_valve_driver_template, zigbee_valve_driver_template.supported_capabilities) | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
| @@ -0,0 +1,121 @@ | ||||
| --[[ | ||||
| Description: SONOFF Water Valve sub-driver for zigbee-valve | ||||
| Version: 1.2 | ||||
| Author: guoxin.yang | ||||
| Date: 2026-07-06 | ||||
| --]] | ||||
|
KKlimczukS marked this conversation as resolved.
Outdated
|
||||
| local capabilities = require "st.capabilities" | ||||
| local zcl_clusters = require "st.zigbee.zcl.clusters" | ||||
| local OnOff = zcl_clusters.OnOff | ||||
| local PowerConfiguration = zcl_clusters.PowerConfiguration | ||||
| local utils = require "st.utils" | ||||
|
|
||||
| -- 电池轮询间隔(秒):SWV1C 是电池休眠设备,每 2 小时轮询一次 | ||||
|
KKlimczukS marked this conversation as resolved.
Outdated
|
||||
| local BATTERY_POLL_INTERVAL = 7200 | ||||
|
|
||||
| -- SWV1C 设备指纹匹配表 | ||||
|
KKlimczukS marked this conversation as resolved.
Outdated
|
||||
| local FINGERPRINTS = { | ||||
| { mfr = "SONOFF", model = "SWV-ZFU" }, | ||||
| { mfr = "SONOFF", model = "SWV-ZFE" }, | ||||
| { mfr = "SONOFF", model = "SWV-ZNU" }, | ||||
| { mfr = "SONOFF", model = "SWV-ZNE" } | ||||
| } | ||||
|
|
||||
| --- OnOff 属性上报处理器 → valve 能力点事件 | ||||
| --- 必须显式处理,因为子驱动定义了 capability_handlers 后, | ||||
| --- 父驱动的默认 OnOff→valve 映射会被跳过(只剩 OnOff→switch) | ||||
|
KKlimczukS marked this conversation as resolved.
Outdated
|
||||
| --- @param driver table 驱动实例 | ||||
| --- @param device table 设备实例 | ||||
| --- @param value table Zigbee 属性值 | ||||
| local function onoff_attr_handler(driver, device, value) | ||||
| local is_on = value.value ~= false and value.value ~= 0 | ||||
| if is_on then | ||||
| device:emit_event(capabilities.valve.valve.open()) | ||||
| else | ||||
| device:emit_event(capabilities.valve.valve.closed()) | ||||
| end | ||||
| end | ||||
|
|
||||
| --- 电池百分比属性处理器 | ||||
|
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. Please use english language in You comments (remark applies to all files) |
||||
| --- Zigbee BatteryPercentageRemaining 范围 0-200(0%-100%),需除以 2 | ||||
| --- @param driver table 驱动实例 | ||||
| --- @param device table 设备实例 | ||||
| --- @param value table Zigbee 属性值 | ||||
| local function battery_percentage_handler(driver, device, value) | ||||
| local raw = value.value | ||||
| local percent = utils.round(raw / 2) | ||||
| device:emit_event(capabilities.battery.battery(percent)) | ||||
| end | ||||
|
|
||||
| --- 生命周期初始化处理函数 | ||||
| --- 通过周期性主动读取 BatteryPercentageRemaining 来保证电池数据可用 | ||||
|
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. Please use english language in You comments (remark applies to all files) |
||||
| --- @param driver table 驱动实例 | ||||
| --- @param device table 设备实例 | ||||
| local function device_init(driver, device) | ||||
| device.thread:call_on_schedule( | ||||
| BATTERY_POLL_INTERVAL, | ||||
| function() | ||||
| device:send(PowerConfiguration.attributes.BatteryPercentageRemaining:read(device)) | ||||
| end | ||||
| ) | ||||
| end | ||||
|
Comment on lines
+43
to
+50
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. @yanggx24 Don't You want to configure PowerConfiguration (instead of polling) and other clusters (for reporting) ? Here is the example of how to do it in the subdriver: SmartThingsEdgeDrivers/drivers/SmartThings/zigbee-power-meter/src/frient/EMIZB-151/init.lua Line 98 in 71bbd3d
|
||||
|
|
||||
| --- valve.open 能力点处理器 | ||||
|
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. Please use english language in You comments (remark applies to all files) |
||||
| --- @param driver table 驱动实例 | ||||
| --- @param device table 设备实例 | ||||
| --- @param command table 能力点命令 | ||||
| local function valve_open_handler(driver, device, command) | ||||
| device:send(OnOff.server.commands.On(device)) | ||||
| device:send(OnOff.attributes.OnOff:read(device)) | ||||
| end | ||||
|
|
||||
| --- valve.close 能力点处理器 | ||||
|
KKlimczukS marked this conversation as resolved.
Outdated
|
||||
| --- @param driver table 驱动实例 | ||||
| --- @param device table 设备实例 | ||||
| --- @param command table 能力点命令 | ||||
| local function valve_close_handler(driver, device, command) | ||||
| device:send(OnOff.server.commands.Off(device)) | ||||
| device:send(OnOff.attributes.OnOff:read(device)) | ||||
| end | ||||
|
|
||||
| --- 设备匹配检查 | ||||
|
KKlimczukS marked this conversation as resolved.
Outdated
|
||||
| --- @param opts table 选项 | ||||
| --- @param driver table 驱动实例 | ||||
| --- @param device table 设备实例 | ||||
| --- @return boolean 是否由此子驱动接管 | ||||
| local function is_sonoff_valve(opts, driver, device) | ||||
| for _, fingerprint in ipairs(FINGERPRINTS) do | ||||
| if device:get_manufacturer() == fingerprint.mfr and device:get_model() == fingerprint.model then | ||||
| return true | ||||
| end | ||||
| end | ||||
| return false | ||||
| end | ||||
|
|
||||
| local sonoff_valve_handler = { | ||||
| NAME = "SONOFF Water Valve Handler", | ||||
| lifecycle_handlers = { | ||||
| init = device_init | ||||
| }, | ||||
| capability_handlers = { | ||||
| [capabilities.valve.ID] = { | ||||
| [capabilities.valve.commands.open.NAME] = valve_open_handler, | ||||
| [capabilities.valve.commands.close.NAME] = valve_close_handler, | ||||
| } | ||||
| }, | ||||
|
KKlimczukS marked this conversation as resolved.
|
||||
| zigbee_handlers = { | ||||
| attr = { | ||||
| -- OnOff 属性上报 → valve 事件(弥补父驱动默认映射被跳过的缺陷) | ||||
|
KKlimczukS marked this conversation as resolved.
Outdated
|
||||
| [OnOff.ID] = { | ||||
| [OnOff.attributes.OnOff.ID] = onoff_attr_handler | ||||
| }, | ||||
|
KKlimczukS marked this conversation as resolved.
|
||||
| -- 电池百分比属性上报 → battery 事件 | ||||
|
KKlimczukS marked this conversation as resolved.
Outdated
|
||||
| [PowerConfiguration.ID] = { | ||||
| [PowerConfiguration.attributes.BatteryPercentageRemaining.ID] = battery_percentage_handler | ||||
| } | ||||
| } | ||||
| }, | ||||
| can_handle = is_sonoff_valve | ||||
| } | ||||
|
|
||||
| return sonoff_valve_handler | ||||
Uh oh!
There was an error while loading. Please reload this page.