Skip to content

Commit 53138de

Browse files
committed
Zigbee Valve:modify comment language and file name
1 parent d3ca759 commit 53138de

3 files changed

Lines changed: 37 additions & 52 deletions

File tree

drivers/SmartThings/zigbee-valve/profiles/sonoff-irrigation.yml renamed to drivers/SmartThings/zigbee-valve/profiles/valve-battery.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: sonoff-irrigation
1+
name: valve-battery
22
components:
33
- id: main
44
capabilities:

drivers/SmartThings/zigbee-valve/src/sonoff/init.lua

Lines changed: 34 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,28 @@
1-
--[[
2-
Description: SONOFF Water Valve sub-driver for zigbee-valve
3-
Version: 1.2
4-
Author: guoxin.yang
5-
Date: 2026-07-06
6-
--]]
1+
-- Copyright 2026 SmartThings, Inc.
2+
-- Licensed under the Apache License, Version 2.0
73
local capabilities = require "st.capabilities"
84
local zcl_clusters = require "st.zigbee.zcl.clusters"
95
local OnOff = zcl_clusters.OnOff
106
local PowerConfiguration = zcl_clusters.PowerConfiguration
117
local utils = require "st.utils"
128

13-
-- 电池轮询间隔(秒):SWV1C 是电池休眠设备,每 2 小时轮询一次
9+
-- Battery Polling Interval (seconds): SWV1C is a battery sleep device, polling every 2 hours
1410
local BATTERY_POLL_INTERVAL = 7200
1511

16-
-- SWV1C 设备指纹匹配表
12+
-- SWV1C Fingerprint list
1713
local FINGERPRINTS = {
1814
{ mfr = "SONOFF", model = "SWV-ZFU" },
1915
{ mfr = "SONOFF", model = "SWV-ZFE" },
2016
{ mfr = "SONOFF", model = "SWV-ZNU" },
2117
{ mfr = "SONOFF", model = "SWV-ZNE" }
2218
}
2319

24-
--- OnOff 属性上报处理器 → valve 能力点事件
25-
--- 必须显式处理,因为子驱动定义了 capability_handlers 后,
26-
--- 父驱动的默认 OnOff→valve 映射会被跳过(只剩 OnOff→switch
27-
--- @param driver table 驱动实例
28-
--- @param device table 设备实例
29-
--- @param value table Zigbee 属性值
20+
--- OnOff Property Reporting Handler → Valve Capability Point Event
21+
--- It must be handled explicitly because the child driver defines capability_handlers.
22+
--- The default OnOff→valve mapping from the parent driver will be skipped (only OnOff→switch remains)
23+
--- @param driver table Driver instance
24+
--- @param device table Device instance
25+
--- @param value table Zigbee attribute value
3026
local function onoff_attr_handler(driver, device, value)
3127
local is_on = value.value ~= false and value.value ~= 0
3228
if is_on then
@@ -36,21 +32,21 @@ local function onoff_attr_handler(driver, device, value)
3632
end
3733
end
3834

39-
--- 电池百分比属性处理器
40-
--- Zigbee BatteryPercentageRemaining 范围 0-2000%-100%),需除以 2
41-
--- @param driver table 驱动实例
42-
--- @param device table 设备实例
43-
--- @param value table Zigbee 属性值
35+
--- Battery Percentage Attribute Handler
36+
--- Zigbee BatteryPercentageRemaining range 0-200 (0%-100%), needs to be divided by 2
37+
--- @param driver table Driver instance
38+
--- @param device table Device instance
39+
--- @param value table Zigbee attribute value
4440
local function battery_percentage_handler(driver, device, value)
4541
local raw = value.value
4642
local percent = utils.round(raw / 2)
4743
device:emit_event(capabilities.battery.battery(percent))
4844
end
4945

50-
--- 生命周期初始化处理函数
51-
--- 通过周期性主动读取 BatteryPercentageRemaining 来保证电池数据可用
52-
--- @param driver table 驱动实例
53-
--- @param device table 设备实例
46+
--- Lifecycle initialization handler
47+
--- Ensures battery data is available by periodically actively reading BatteryPercentageRemaining
48+
--- @param driver table Driver instance
49+
--- @param device table Device instance
5450
local function device_init(driver, device)
5551
device.thread:call_on_schedule(
5652
BATTERY_POLL_INTERVAL,
@@ -60,29 +56,29 @@ local function device_init(driver, device)
6056
)
6157
end
6258

63-
--- valve.open 能力点处理器
64-
--- @param driver table 驱动实例
65-
--- @param device table 设备实例
66-
--- @param command table 能力点命令
59+
--- valve.open ability handler
60+
--- @param driver table driver instance
61+
--- @param device table device instance
62+
--- @param command table ability command
6763
local function valve_open_handler(driver, device, command)
6864
device:send(OnOff.server.commands.On(device))
6965
device:send(OnOff.attributes.OnOff:read(device))
7066
end
7167

72-
--- valve.close 能力点处理器
73-
--- @param driver table 驱动实例
74-
--- @param device table 设备实例
75-
--- @param command table 能力点命令
68+
--- valve.close capability handler
69+
--- @param driver table driver instance
70+
--- @param device table device instance
71+
--- @param command table capability command
7672
local function valve_close_handler(driver, device, command)
7773
device:send(OnOff.server.commands.Off(device))
7874
device:send(OnOff.attributes.OnOff:read(device))
7975
end
8076

81-
--- 设备匹配检查
82-
--- @param opts table 选项
83-
--- @param driver table 驱动实例
84-
--- @param device table 设备实例
85-
--- @return boolean 是否由此子驱动接管
77+
--- Device Matching Check
78+
--- @param opts table Options
79+
--- @param driver table Driver instance
80+
--- @param device table Device instance
81+
--- @return boolean Whether this sub-driver takes over
8682
local function is_sonoff_valve(opts, driver, device)
8783
for _, fingerprint in ipairs(FINGERPRINTS) do
8884
if device:get_manufacturer() == fingerprint.mfr and device:get_model() == fingerprint.model then
@@ -105,11 +101,11 @@ local sonoff_valve_handler = {
105101
},
106102
zigbee_handlers = {
107103
attr = {
108-
-- OnOff 属性上报 → valve 事件(弥补父驱动默认映射被跳过的缺陷)
104+
-- OnOff property reporting → valve event (to compensate for the defect of the parent driver's default mapping being skipped)
109105
[OnOff.ID] = {
110106
[OnOff.attributes.OnOff.ID] = onoff_attr_handler
111107
},
112-
-- 电池百分比属性上报 → battery 事件
108+
-- Battery percentage attribute reporting → battery event
113109
[PowerConfiguration.ID] = {
114110
[PowerConfiguration.attributes.BatteryPercentageRemaining.ID] = battery_percentage_handler
115111
}

drivers/SmartThings/zigbee-valve/src/test/test_sonoff_valve.lua

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,5 @@
1-
-- Copyright 2022 SmartThings
2-
--
3-
-- Licensed under the Apache License, Version 2.0 (the "License");
4-
-- you may not use this file except in compliance with the License.
5-
-- You may obtain a copy of the License at
6-
--
7-
-- http://www.apache.org/licenses/LICENSE-2.0
8-
--
9-
-- Unless required by applicable law or agreed to in writing, software
10-
-- distributed under the License is distributed on an "AS IS" BASIS,
11-
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12-
-- See the License for the specific language governing permissions and
13-
-- limitations under the License.
1+
-- Copyright 2026 SmartThings, Inc.
2+
-- Licensed under the Apache License, Version 2.0
143

154
-- Mock out globals
165
local test = require "integration_test"

0 commit comments

Comments
 (0)