-
Notifications
You must be signed in to change notification settings - Fork 523
WWSTCERT-10247 Add pad19 dimmer driver #2762
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 all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
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. this is a duplicate of the existing |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| name: philio-dimmer-switch | ||
| components: | ||
| - id: main | ||
| capabilities: | ||
| - id: switch | ||
| version: 1 | ||
| - id: switchLevel | ||
| version: 1 | ||
| - id: refresh | ||
| version: 1 | ||
| categories: | ||
| - name: Switch |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| -- can_handle.lua | ||
| -- 判斷是否為 Philio PAD19 裝置 | ||
|
|
||
| local subdriver = require("philio-dimmer-switch") | ||
|
|
||
| local function can_handle_pad19(opts, driver, device, ...) | ||
| local fingerprint_list = { | ||
| {mfr = 0x013C, prod_type = 0x0005, prod_id = 0x008A}, -- Philio PAD19 | ||
| } | ||
|
|
||
| for _, fingerprint in ipairs(fingerprint_list) do | ||
| if device:id_match(fingerprint.mfr, fingerprint.prod_type, fingerprint.prod_id) then | ||
| return true, subdriver | ||
| end | ||
| end | ||
|
|
||
| return false | ||
| end | ||
|
|
||
| return can_handle_pad19 |
|
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. +1 to Steven's feedback regarding the driver structure. Also be sure to remove the |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,145 @@ | ||
| local capabilities = require "st.capabilities" | ||
| --- @type st.zwave.Driver | ||
| local ZwaveDriver = require "st.zwave.driver" | ||
| --- @type st.zwave.CommandClass | ||
| local cc = require "st.zwave.CommandClass" | ||
| --- @type st.utils | ||
| local utils = require "st.utils" | ||
| --- @type st.zwave.constants | ||
| local constants = require "st.zwave.constants" | ||
| --- @type st.zwave.CommandClass.Basic | ||
| local Basic = (require "st.zwave.CommandClass.Basic")({ version = 1 }) | ||
| --- @type st.zwave.CommandClass.SwitchMultilevel | ||
| local SwitchMultilevel = (require "st.zwave.CommandClass.SwitchMultilevel")({ version = 4 }) | ||
|
|
||
|
|
||
| -- print("DEBUG: philio-dimmer-switch/init.lua loaded") | ||
|
|
||
| local function dimmer_event(driver, device, cmd) | ||
| local value = cmd.args.value or cmd.args.target_value or 0 | ||
| local level = utils.clamp_value(value, 0, 100) | ||
|
|
||
| device:emit_event(level > 0 and capabilities.switch.switch.on() or capabilities.switch.switch.off()) | ||
| device:emit_event(capabilities.switchLevel.level(level)) | ||
| end | ||
|
|
||
| local function basic_report_handler(driver, device, cmd) | ||
| local basic_level = cmd.args.value or 0 | ||
| local level = utils.clamp_value(basic_level, 0, 100) | ||
|
|
||
| device:emit_event(basic_level > 0 and capabilities.switch.switch.on() or capabilities.switch.switch.off()) | ||
| device:emit_event(capabilities.switchLevel.level(level)) | ||
| end | ||
|
|
||
| local function switch_on_handler(driver, device) | ||
| device:send(Basic:Set({value = 0xff})) | ||
| device.thread:call_with_delay(4, function(d) | ||
| device:send(SwitchMultilevel:Get({})) | ||
| end) | ||
| end | ||
|
|
||
| local function switch_off_handler(driver, device) | ||
| device:send(Basic:Set({value = 0x00})) | ||
| device.thread:call_with_delay(4, function(d) | ||
| device:send(SwitchMultilevel:Get({})) | ||
| end) | ||
| end | ||
|
|
||
| local function switch_level_set(driver, device, cmd) | ||
| local level = utils.round(cmd.args.level) | ||
| level = utils.clamp_value(level, 0, 99) | ||
|
|
||
| device:emit_event(level > 0 and capabilities.switch.switch.on() or capabilities.switch.switch.off()) | ||
| device:emit_event(capabilities.switchLevel.level(level)) | ||
|
|
||
| ------------------------------------------------------------------ | ||
| -- 修正:SmartThings 可能送出 rate="default",不是數字 → 會造成崩潰 | ||
| ------------------------------------------------------------------ | ||
| local raw_rate = cmd.args.rate | ||
| local dimmingDuration = tonumber(raw_rate) -- dimming duration in seconds | ||
| if dimmingDuration == nil then | ||
| dimmingDuration = 0 -- Z-Wave duration=0 = 快速/立即 | ||
| end | ||
|
|
||
| device:send(SwitchMultilevel:Set({ value=level, duration=dimmingDuration })) | ||
| local function query_level() | ||
| device:send(SwitchMultilevel:Get({})) | ||
| end | ||
| -- delay shall be at least 5 sec. | ||
| local delay = math.max(dimmingDuration + constants.DEFAULT_POST_DIMMING_DELAY , constants.MIN_DIMMING_GET_STATUS_DELAY) --delay in seconds | ||
| device.thread:call_with_delay(delay, query_level) | ||
| end | ||
|
|
||
| ---- Refresh 指令函式(SmartThings Test Suite 必要) | ||
| local function refresh_cmd(driver, device, command) | ||
| -- print("DEBUG: PAD19 refresh_cmd called") | ||
|
|
||
| -- 取得目前開關狀態 | ||
| local switch_get = Basic:Get({}) | ||
| device:send(switch_get) | ||
|
|
||
| -- 取得目前dimmer的level | ||
| local switchlevel_get = SwitchMultilevel:Get({}) | ||
| device:send(switchlevel_get) | ||
| end | ||
|
|
||
| ------------------------------------------------------------------- | ||
| -- Lifecycle | ||
| ------------------------------------------------------------------- | ||
| local function device_init(driver, device) | ||
| -- print("DEBUG: PAD19 device_init called") | ||
| end | ||
|
|
||
| local function device_added(driver, device) | ||
| -- print("DEBUG: PAD19 device_added - init state off") | ||
| device:emit_event(capabilities.switch.switch.off()) | ||
| device:emit_event(capabilities.switchLevel.level(0)) | ||
| -- print("DEBUG: PAD19 Initial switchlevel = 0") | ||
| end | ||
|
|
||
| -- NEW: 修正 driverSwitched 崩潰 | ||
| local function device_driver_switched(driver, device, event, args) | ||
| -- print("DEBUG: PAD19 driverSwitched - ignored") | ||
| end | ||
|
|
||
| local pad19_driver_template = { | ||
| NAME = "Philio PAD19 Dimmer Switch", | ||
| zwave_handlers = { | ||
| [cc.BASIC] = { | ||
| [Basic.SET] = dimmer_event, | ||
| [Basic.REPORT] = basic_report_handler | ||
| }, | ||
| [cc.SWITCH_MULTILEVEL] = { | ||
| [SwitchMultilevel.SET] = dimmer_event, | ||
| [SwitchMultilevel.REPORT] = dimmer_event | ||
| } | ||
| }, | ||
| capability_handlers = { | ||
| [capabilities.switch.ID] = { | ||
| [capabilities.switch.commands.on.NAME] = switch_on_handler, | ||
| [capabilities.switch.commands.off.NAME] = switch_off_handler | ||
| }, | ||
| [capabilities.switchLevel.ID] = { | ||
| [capabilities.switchLevel.commands.setLevel.NAME] = switch_level_set | ||
| }, | ||
| [capabilities.refresh.ID] = { | ||
| [capabilities.refresh.commands.refresh.NAME] = refresh_cmd | ||
| } | ||
| }, | ||
|
|
||
| lifecycle_handlers = { | ||
| init = device_init, | ||
| added = device_added, | ||
| driverSwitched = device_driver_switched | ||
| }, | ||
|
|
||
| -- 設置 Z-Wave 設備配置 | ||
| zwave_config = {} | ||
| -- zwave_config = {}, | ||
|
|
||
| -- 指定can_handle腳本, 讓上層可以先檢查這台Device是否能用這個子驅動控制,可以才載入 | ||
| -- can_handle = require("philio-dimmer-switch.can_handle") | ||
| } | ||
|
|
||
| -- 回傳驅動範本 | ||
| return pad19_driver_template |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -430,6 +430,21 @@ local devices = { | |
| PARAMETERS = { | ||
| statusLEDmode = {parameter_number = 7, size = 4} | ||
| } | ||
| }, | ||
| PHILIO_PAD19 = { | ||
| MATCHING_MATRIX = { | ||
| mfrs = 0x013C, | ||
| product_types = 0x0005, | ||
| product_ids = 0x008A | ||
| }, | ||
| PARAMETERS = { | ||
| parameter1 = {parameter_number = 1, size = 1}, | ||
| parameter2 = {parameter_number = 2, size = 1}, | ||
| parameter3 = {parameter_number = 3, size = 1}, | ||
| parameter4 = {parameter_number = 4, size = 1}, | ||
| parameter5 = {parameter_number = 5, size = 1}, | ||
| parameter6 = {parameter_number = 6, size = 1} | ||
| } | ||
|
Comment on lines
+440
to
+447
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 are intended to match up to preferences on the device profile, but your profile has none |
||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
|
|
||
| -- Copyright 2026 SmartThings, Inc. | ||
| -- Licensed under the Apache License, Version 2.0 | ||
|
|
||
| local lazy_load_if_possible = require "lazy_load_subdriver" | ||
|
|
||
| return { | ||
| lazy_load_if_possible("eaton-accessory-dimmer"), | ||
| lazy_load_if_possible("inovelli"), | ||
| lazy_load_if_possible("dawon-smart-plug"), | ||
| lazy_load_if_possible("inovelli-2-channel-smart-plug"), | ||
| lazy_load_if_possible("zwave-dual-switch"), | ||
| lazy_load_if_possible("eaton-anyplace-switch"), | ||
| lazy_load_if_possible("fibaro-wall-plug-us"), | ||
| lazy_load_if_possible("dawon-wall-smart-switch"), | ||
| lazy_load_if_possible("zooz-power-strip"), | ||
| lazy_load_if_possible("aeon-smart-strip"), | ||
| lazy_load_if_possible("qubino-switches"), | ||
| lazy_load_if_possible("fibaro-double-switch"), | ||
| lazy_load_if_possible("fibaro-single-switch"), | ||
| lazy_load_if_possible("eaton-5-scene-keypad"), | ||
| lazy_load_if_possible("ecolink-switch"), | ||
| lazy_load_if_possible("multi-metering-switch"), | ||
| lazy_load_if_possible("zooz-zen-30-dimmer-relay"), | ||
| lazy_load_if_possible("multichannel-device"), | ||
| lazy_load_if_possible("aeotec-smart-switch"), | ||
| lazy_load_if_possible("aeotec-heavy-duty"), | ||
| lazy_load_if_possible("philio-dimmer-switch") | ||
| } |
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.
again, I think this fingerprint is the only change you actually need to include.