-
Notifications
You must be signed in to change notification settings - Fork 524
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
Open
JerryYang01
wants to merge
2
commits into
SmartThingsCommunity:main
Choose a base branch
from
JerryYang01:add-pad19-dimmer-driver
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| name: 'Philio Zwave PAD19' | ||
| packageKey: 'Philio-Zwave-PAD19' | ||
| author: "Philio" | ||
| permissions: | ||
| zwave: {} | ||
| description: "Philio Z-Wave dimmer switch driver" | ||
| vendorSupportInformation: "https://www.zwavetaiwan.com.tw/" |
7 changes: 7 additions & 0 deletions
7
drivers/SmartThings/zwave-switch/pad19-dimmer/fingerprints.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| zwaveManufacturer: | ||
| - id: "Philio/PAD19" | ||
| manufacturerId: 0x013C | ||
| productType: 0x0005 | ||
| productId: 0x008A | ||
| deviceLabel: PAD19 | ||
| deviceProfileName: pad19-dimmer-switch |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,138 @@ | ||
| 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: PAD19/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 | ||
| } | ||
| } | ||
|
|
||
| local dimmer_switch = ZwaveDriver("Philio-Zwave-PAD19", pad19_driver_template) | ||
| dimmer_switch:run() |
12 changes: 12 additions & 0 deletions
12
drivers/SmartThings/zwave-switch/profiles/pad19-dimmer-switch.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| name: pad19-dimmer-switch | ||
| components: | ||
| - id: main | ||
| capabilities: | ||
| - id: switch | ||
| version: 1 | ||
| - id: switchLevel | ||
| version: 1 | ||
| - id: refresh | ||
| version: 1 | ||
| categories: | ||
| - name: Switch |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
+1 to Steven's feedback regarding the driver structure. Also be sure to remove the
print()statements from this file.