From 102bd0257f82f678239f95cf50bbeebe8e9421cc Mon Sep 17 00:00:00 2001 From: Alec Lorimer Date: Tue, 24 Mar 2026 16:23:48 -0500 Subject: [PATCH 1/2] Setting up driver tests to run against previous versions of lua libs through jenkins pipeline --- .github/workflows/publish-test-results.yml | 30 ----- .github/workflows/run-tests.yml | 127 +++++---------------- 2 files changed, 30 insertions(+), 127 deletions(-) delete mode 100644 .github/workflows/publish-test-results.yml diff --git a/.github/workflows/publish-test-results.yml b/.github/workflows/publish-test-results.yml deleted file mode 100644 index 57c8812913..0000000000 --- a/.github/workflows/publish-test-results.yml +++ /dev/null @@ -1,30 +0,0 @@ -name: Publish test results -on: - workflow_run: - workflows: [Run driver tests] - types: - - completed - -jobs: - publish-test-results: - runs-on: ubuntu-latest - steps: - - name: Download artifacts - uses: dawidd6/action-download-artifact@v6 - with: - workflow: run-tests.yml - run_id: ${{ github.event.workflow_run.id }} - - run: echo "pr_number=$(cat pr_number/pr_number.txt)" >> $GITHUB_ENV - - name: Publish test results - uses: EnricoMi/publish-unit-test-result-action@v2 - with: - commit: ${{ github.event.workflow_run.head_sha }} - event_file: event-file/event.json - event_name: ${{ github.event.workflow_run.event }} - files: "tests/*.xml" - - name: Publish coverage results - uses: 5monkeys/cobertura-action@master - with: - pull_request_number: ${{ env.pr_number }} - path: "coverage/*.xml" - minimum_coverage: 90 diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index f6a03154cb..45ec4be73a 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -6,110 +6,43 @@ on: - 'drivers/**' jobs: - # Two separate jobs for finding the right artifact to run tests with - get-latest-release-artifact: - runs-on: ubuntu-latest - if: ${{ !contains(join(github.event.pull_request.labels.*.name), 'release') }} - outputs: - cache_key: ${{ steps.cache_key.outputs.CACHE_KEY }} - steps: - - name: Find the lua lib release version - id: lib-version - run: | - curl "https://github.com/SmartThingsCommunity/SmartThingsEdgeDrivers/releases/latest" -s -L -I -o /dev/null -w '%{url_effective}' > test.log - echo "url=$(cat test.log)" >> $GITHUB_OUTPUT - - name: Try to retrieve cache - id: cached-libs - uses: actions/cache@v3 - with: - path: '/home/runner/work/lua_libs' - key: ${{ steps.lib-version.outputs.url }}-v1 - - name: Get the latest release artifact - if: steps.cached-libs.outputs.cache-hit != 'true' - uses: dsaltares/fetch-gh-release-asset@master - with: - file: 'lua_libs.*' - regex: true - target: '/home/runner/work/lua_libs/' - - name: Extract the lua libraries - if: steps.cached-libs.outputs.cache-hit != 'true' - working-directory: '/home/runner/work/lua_libs' - run: tar -xf *.tar.gz --wildcards -C . --strip-components=1 '*.lua' - - name: Set output - id: cache_key - run: echo "CACHE_KEY=${{ steps.lib-version.outputs.url }}-v1" >> $GITHUB_OUTPUT + trigger-driver-test: + strategy: + matrix: + version: + [ 60 ] - run-driver-tests: runs-on: ubuntu-latest - needs: - [ get-latest-release-artifact ] - if: ${{ always() && contains(needs.*.result, 'success') && !contains(needs.*.result, 'failure') }} steps: - - name: Set cache key - id: cache_key - run: echo "CACHE_KEY=${{ join(needs.*.outputs.cache_key) }}" >> $GITHUB_OUTPUT - - name: Try to retrieve cache - id: cached_libs - uses: actions/cache@v3 - with: - path: '/home/runner/work/lua_libs' - key: ${{ steps.cache_key.outputs.CACHE_KEY }} - - name: Fail if cache missed - if: steps.cached_libs.outputs.cache-hit != 'true' - uses: actions/github-script@v3 + + - name: Create Commit Status (Pending) + id: status + uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd with: script: | - core.setFailed('Library cache missed. ${{steps.cached_libs.outputs.cache-hit}} ') - - name: Install lua - run: | - sudo apt-get update - sudo apt-get install lua5.3 liblua5.3-dev luarocks - - name: Install lua rocks - run: | - wget https://luarocks.org/manifests/hisham/luacov-0.15.0-1.rockspec - wget https://raw.githubusercontent.com/britzl/luacov-cobertura/refs/tags/1.1.0/rockspec -O luacov-cobertura-1.1.0-0.rockspec - sed -i 's/master/1\.1\.0/g' luacov-cobertura-1.1.0-0.rockspec - sed -i 's/1\.0-0/1\.1\.0-0/g' luacov-cobertura-1.1.0-0.rockspec - sudo luarocks install luacov-0.15.0-1.rockspec - sudo luarocks install luacov-cobertura-1.1.0-0.rockspec - - name: Set LUA_PATH - id: lua_path + core.setOutput('status_url', (await github.rest.repos.createCommitStatus({ + owner: context.repo.owner, + repo: context.repo.repo, + sha: context.sha, + state: 'pending', + description: 'Jenkins job triggered...', + context: 'Driver Tests (${{ matrix.version }})' + })).data.url); + - name: Trigger Jenkins Generic Webhook env: - LUA_PATH_APPEND: /home/runner/work/lua_libs/?.lua;./?.lua;/home/runner/work/lua_libs/?/init.lua;./?/init.lua + JENKINS_WEBHOOK_TOKEN: ${{ secrets.JENKINS_WEBHOOK_TOKEN }} + JENKINS_WEBHOOK_URL: ${{ secrets.JENKINS_WEBHOOK_URL }} + STATUS_URL: ${{ steps.status.outputs.status_url }} run: | - eval "$(luarocks path --bin)" - echo "lua_path=$LUA_PATH_APPEND;$LUA_PATH" >> $GITHUB_OUTPUT - - uses: actions/checkout@v3 - - name: get changed drivers - id: changed-drivers - uses: tj-actions/changed-files@v41 - with: - dir_names: true - dir_names_max_depth: 3 - files: "drivers/**" - safe_output: false - - run: echo ${{ steps.changed-drivers.outputs.all_modified_files }} - - name: Install Python requirements - run: pip install -r tools/requirements.txt - - name: Run the tests - id: run-tests - run: python tools/run_driver_tests_p.py ${{ steps.changed-drivers.outputs.all_modified_files }} - env: - LUA_PATH: ${{ steps.lua_path.outputs.lua_path }} - - name: Upload test artifact - if: always() - uses: actions/upload-artifact@v4 - with: - name: tests - path: | - tools/test_output/*.xml - - name: Upload coverage artifact - if: always() - uses: actions/upload-artifact@v4 - with: - name: coverage - path: | - tools/coverage_output/*_coverage.xml + set +x + curl -s -o /dev/null -X POST \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer ${JENKINS_WEBHOOK_TOKEN}" \ + -d "{\"status_url\": \"$STATUS_URL\", + \"version\": ${{ matrix.version }}, + \"commit\": ${{ github.event.pull_request.head.sha }} }" \ + "${JENKINS_WEBHOOK_URL}" + set -x event-file: runs-on: ubuntu-latest From cdf458f55c6b624a83186fb8fc083d6641daf66d Mon Sep 17 00:00:00 2001 From: Alec Lorimer Date: Mon, 17 Nov 2025 15:25:30 -0600 Subject: [PATCH 2/2] CHAD-17087: zwave-fan lazy lading of sub-drivers --- .github/workflows/publish-test-results.yml | 30 +++++ .github/workflows/run-tests.yml | 127 +++++++++++++----- drivers/SmartThings/zwave-fan/src/init.lua | 21 +-- .../zwave-fan/src/lazy_load_subdriver.lua | 18 +++ .../SmartThings/zwave-fan/src/sub_drivers.lua | 9 ++ .../src/test/test_zwave_fan_3_speed.lua | 16 +-- .../src/test/test_zwave_fan_4_speed.lua | 16 +-- .../src/zwave-fan-3-speed/can_handle.lua | 14 ++ .../src/zwave-fan-3-speed/fingerprints.lua | 12 ++ .../zwave-fan/src/zwave-fan-3-speed/init.lua | 33 +---- .../src/zwave-fan-4-speed/can_handle.lua | 14 ++ .../src/zwave-fan-4-speed/fingerprints.lua | 8 ++ .../zwave-fan/src/zwave-fan-4-speed/init.lua | 29 +--- .../zwave-fan/src/zwave_fan_helpers.lua | 16 +-- 14 files changed, 223 insertions(+), 140 deletions(-) create mode 100644 .github/workflows/publish-test-results.yml create mode 100644 drivers/SmartThings/zwave-fan/src/lazy_load_subdriver.lua create mode 100644 drivers/SmartThings/zwave-fan/src/sub_drivers.lua create mode 100644 drivers/SmartThings/zwave-fan/src/zwave-fan-3-speed/can_handle.lua create mode 100644 drivers/SmartThings/zwave-fan/src/zwave-fan-3-speed/fingerprints.lua create mode 100644 drivers/SmartThings/zwave-fan/src/zwave-fan-4-speed/can_handle.lua create mode 100644 drivers/SmartThings/zwave-fan/src/zwave-fan-4-speed/fingerprints.lua diff --git a/.github/workflows/publish-test-results.yml b/.github/workflows/publish-test-results.yml new file mode 100644 index 0000000000..57c8812913 --- /dev/null +++ b/.github/workflows/publish-test-results.yml @@ -0,0 +1,30 @@ +name: Publish test results +on: + workflow_run: + workflows: [Run driver tests] + types: + - completed + +jobs: + publish-test-results: + runs-on: ubuntu-latest + steps: + - name: Download artifacts + uses: dawidd6/action-download-artifact@v6 + with: + workflow: run-tests.yml + run_id: ${{ github.event.workflow_run.id }} + - run: echo "pr_number=$(cat pr_number/pr_number.txt)" >> $GITHUB_ENV + - name: Publish test results + uses: EnricoMi/publish-unit-test-result-action@v2 + with: + commit: ${{ github.event.workflow_run.head_sha }} + event_file: event-file/event.json + event_name: ${{ github.event.workflow_run.event }} + files: "tests/*.xml" + - name: Publish coverage results + uses: 5monkeys/cobertura-action@master + with: + pull_request_number: ${{ env.pr_number }} + path: "coverage/*.xml" + minimum_coverage: 90 diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 45ec4be73a..f6a03154cb 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -6,43 +6,110 @@ on: - 'drivers/**' jobs: - trigger-driver-test: - strategy: - matrix: - version: - [ 60 ] + # Two separate jobs for finding the right artifact to run tests with + get-latest-release-artifact: + runs-on: ubuntu-latest + if: ${{ !contains(join(github.event.pull_request.labels.*.name), 'release') }} + outputs: + cache_key: ${{ steps.cache_key.outputs.CACHE_KEY }} + steps: + - name: Find the lua lib release version + id: lib-version + run: | + curl "https://github.com/SmartThingsCommunity/SmartThingsEdgeDrivers/releases/latest" -s -L -I -o /dev/null -w '%{url_effective}' > test.log + echo "url=$(cat test.log)" >> $GITHUB_OUTPUT + - name: Try to retrieve cache + id: cached-libs + uses: actions/cache@v3 + with: + path: '/home/runner/work/lua_libs' + key: ${{ steps.lib-version.outputs.url }}-v1 + - name: Get the latest release artifact + if: steps.cached-libs.outputs.cache-hit != 'true' + uses: dsaltares/fetch-gh-release-asset@master + with: + file: 'lua_libs.*' + regex: true + target: '/home/runner/work/lua_libs/' + - name: Extract the lua libraries + if: steps.cached-libs.outputs.cache-hit != 'true' + working-directory: '/home/runner/work/lua_libs' + run: tar -xf *.tar.gz --wildcards -C . --strip-components=1 '*.lua' + - name: Set output + id: cache_key + run: echo "CACHE_KEY=${{ steps.lib-version.outputs.url }}-v1" >> $GITHUB_OUTPUT + run-driver-tests: runs-on: ubuntu-latest + needs: + [ get-latest-release-artifact ] + if: ${{ always() && contains(needs.*.result, 'success') && !contains(needs.*.result, 'failure') }} steps: - - - name: Create Commit Status (Pending) - id: status - uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd + - name: Set cache key + id: cache_key + run: echo "CACHE_KEY=${{ join(needs.*.outputs.cache_key) }}" >> $GITHUB_OUTPUT + - name: Try to retrieve cache + id: cached_libs + uses: actions/cache@v3 + with: + path: '/home/runner/work/lua_libs' + key: ${{ steps.cache_key.outputs.CACHE_KEY }} + - name: Fail if cache missed + if: steps.cached_libs.outputs.cache-hit != 'true' + uses: actions/github-script@v3 with: script: | - core.setOutput('status_url', (await github.rest.repos.createCommitStatus({ - owner: context.repo.owner, - repo: context.repo.repo, - sha: context.sha, - state: 'pending', - description: 'Jenkins job triggered...', - context: 'Driver Tests (${{ matrix.version }})' - })).data.url); - - name: Trigger Jenkins Generic Webhook + core.setFailed('Library cache missed. ${{steps.cached_libs.outputs.cache-hit}} ') + - name: Install lua + run: | + sudo apt-get update + sudo apt-get install lua5.3 liblua5.3-dev luarocks + - name: Install lua rocks + run: | + wget https://luarocks.org/manifests/hisham/luacov-0.15.0-1.rockspec + wget https://raw.githubusercontent.com/britzl/luacov-cobertura/refs/tags/1.1.0/rockspec -O luacov-cobertura-1.1.0-0.rockspec + sed -i 's/master/1\.1\.0/g' luacov-cobertura-1.1.0-0.rockspec + sed -i 's/1\.0-0/1\.1\.0-0/g' luacov-cobertura-1.1.0-0.rockspec + sudo luarocks install luacov-0.15.0-1.rockspec + sudo luarocks install luacov-cobertura-1.1.0-0.rockspec + - name: Set LUA_PATH + id: lua_path env: - JENKINS_WEBHOOK_TOKEN: ${{ secrets.JENKINS_WEBHOOK_TOKEN }} - JENKINS_WEBHOOK_URL: ${{ secrets.JENKINS_WEBHOOK_URL }} - STATUS_URL: ${{ steps.status.outputs.status_url }} + LUA_PATH_APPEND: /home/runner/work/lua_libs/?.lua;./?.lua;/home/runner/work/lua_libs/?/init.lua;./?/init.lua run: | - set +x - curl -s -o /dev/null -X POST \ - -H "Content-Type: application/json" \ - -H "Authorization: Bearer ${JENKINS_WEBHOOK_TOKEN}" \ - -d "{\"status_url\": \"$STATUS_URL\", - \"version\": ${{ matrix.version }}, - \"commit\": ${{ github.event.pull_request.head.sha }} }" \ - "${JENKINS_WEBHOOK_URL}" - set -x + eval "$(luarocks path --bin)" + echo "lua_path=$LUA_PATH_APPEND;$LUA_PATH" >> $GITHUB_OUTPUT + - uses: actions/checkout@v3 + - name: get changed drivers + id: changed-drivers + uses: tj-actions/changed-files@v41 + with: + dir_names: true + dir_names_max_depth: 3 + files: "drivers/**" + safe_output: false + - run: echo ${{ steps.changed-drivers.outputs.all_modified_files }} + - name: Install Python requirements + run: pip install -r tools/requirements.txt + - name: Run the tests + id: run-tests + run: python tools/run_driver_tests_p.py ${{ steps.changed-drivers.outputs.all_modified_files }} + env: + LUA_PATH: ${{ steps.lua_path.outputs.lua_path }} + - name: Upload test artifact + if: always() + uses: actions/upload-artifact@v4 + with: + name: tests + path: | + tools/test_output/*.xml + - name: Upload coverage artifact + if: always() + uses: actions/upload-artifact@v4 + with: + name: coverage + path: | + tools/coverage_output/*_coverage.xml event-file: runs-on: ubuntu-latest diff --git a/drivers/SmartThings/zwave-fan/src/init.lua b/drivers/SmartThings/zwave-fan/src/init.lua index acdb34ae76..8b3a7d0cea 100644 --- a/drivers/SmartThings/zwave-fan/src/init.lua +++ b/drivers/SmartThings/zwave-fan/src/init.lua @@ -1,16 +1,6 @@ --- 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. +-- Copyright 2022 SmartThings, Inc. +-- Licensed under the Apache License, Version 2.0 + local capabilities = require "st.capabilities" --- @type st.zwave.defaults @@ -27,10 +17,7 @@ local driver_template = { capabilities.switch, capabilities.fanSpeed, }, - sub_drivers = { - require("zwave-fan-3-speed"), - require("zwave-fan-4-speed") - }, + sub_drivers = require("sub_drivers"), } defaults.register_for_default_handlers(driver_template, driver_template.supported_capabilities) diff --git a/drivers/SmartThings/zwave-fan/src/lazy_load_subdriver.lua b/drivers/SmartThings/zwave-fan/src/lazy_load_subdriver.lua new file mode 100644 index 0000000000..45115081e4 --- /dev/null +++ b/drivers/SmartThings/zwave-fan/src/lazy_load_subdriver.lua @@ -0,0 +1,18 @@ +-- Copyright 2025 SmartThings, Inc. +-- Licensed under the Apache License, Version 2.0 + + +return function(sub_driver_name) + -- gets the current lua libs api version + local ZwaveDriver = require "st.zwave.driver" + local version = require "version" + + if version.api >= 16 then + return ZwaveDriver.lazy_load_sub_driver_v2(sub_driver_name) + elseif version.api >= 9 then + return ZwaveDriver.lazy_load_sub_driver(require(sub_driver_name)) + else + return require(sub_driver_name) + end + +end diff --git a/drivers/SmartThings/zwave-fan/src/sub_drivers.lua b/drivers/SmartThings/zwave-fan/src/sub_drivers.lua new file mode 100644 index 0000000000..373e4daf52 --- /dev/null +++ b/drivers/SmartThings/zwave-fan/src/sub_drivers.lua @@ -0,0 +1,9 @@ +-- Copyright 2025 SmartThings, Inc. +-- Licensed under the Apache License, Version 2.0 + +local lazy_load_if_possible = require "lazy_load_subdriver" +local sub_drivers = { + lazy_load_if_possible("zwave-fan-3-speed"), + lazy_load_if_possible("zwave-fan-4-speed"), +} +return sub_drivers diff --git a/drivers/SmartThings/zwave-fan/src/test/test_zwave_fan_3_speed.lua b/drivers/SmartThings/zwave-fan/src/test/test_zwave_fan_3_speed.lua index ca46560f36..2e797e3dd3 100644 --- a/drivers/SmartThings/zwave-fan/src/test/test_zwave_fan_3_speed.lua +++ b/drivers/SmartThings/zwave-fan/src/test/test_zwave_fan_3_speed.lua @@ -1,16 +1,6 @@ --- 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. +-- Copyright 2022 SmartThings, Inc. +-- Licensed under the Apache License, Version 2.0 + local test = require "integration_test" local capabilities = require "st.capabilities" diff --git a/drivers/SmartThings/zwave-fan/src/test/test_zwave_fan_4_speed.lua b/drivers/SmartThings/zwave-fan/src/test/test_zwave_fan_4_speed.lua index d41c45d6c5..e5f806741a 100644 --- a/drivers/SmartThings/zwave-fan/src/test/test_zwave_fan_4_speed.lua +++ b/drivers/SmartThings/zwave-fan/src/test/test_zwave_fan_4_speed.lua @@ -1,16 +1,6 @@ --- 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. +-- Copyright 2022 SmartThings, Inc. +-- Licensed under the Apache License, Version 2.0 + local test = require "integration_test" local capabilities = require "st.capabilities" diff --git a/drivers/SmartThings/zwave-fan/src/zwave-fan-3-speed/can_handle.lua b/drivers/SmartThings/zwave-fan/src/zwave-fan-3-speed/can_handle.lua new file mode 100644 index 0000000000..66a04b41a9 --- /dev/null +++ b/drivers/SmartThings/zwave-fan/src/zwave-fan-3-speed/can_handle.lua @@ -0,0 +1,14 @@ +-- Copyright 2025 SmartThings, Inc. +-- Licensed under the Apache License, Version 2.0 + +local function is_fan_3_speed(opts, driver, device, ...) + local FINGERPRINTS = require("zwave-fan-3-speed.fingerprints") + for _, fingerprint in ipairs(FINGERPRINTS) do + if device:id_match(fingerprint.mfr, fingerprint.prod, fingerprint.model) then + return true, require("zwave-fan-3-speed") + end + end + return false +end + +return is_fan_3_speed diff --git a/drivers/SmartThings/zwave-fan/src/zwave-fan-3-speed/fingerprints.lua b/drivers/SmartThings/zwave-fan/src/zwave-fan-3-speed/fingerprints.lua new file mode 100644 index 0000000000..7241769dcd --- /dev/null +++ b/drivers/SmartThings/zwave-fan/src/zwave-fan-3-speed/fingerprints.lua @@ -0,0 +1,12 @@ +-- Copyright 2025 SmartThings, Inc. +-- Licensed under the Apache License, Version 2.0 + +local FAN_3_SPEED_FINGERPRINTS = { + {mfr = 0x001D, prod = 0x1001, model = 0x0334}, -- Leviton 3-Speed Fan Controller + {mfr = 0x0063, prod = 0x4944, model = 0x3034}, -- GE In-Wall Smart Fan Control + {mfr = 0x0063, prod = 0x4944, model = 0x3131}, -- GE In-Wall Smart Fan Control + {mfr = 0x0039, prod = 0x4944, model = 0x3131}, -- Honeywell Z-Wave Plus In-Wall Fan Speed Control + {mfr = 0x0063, prod = 0x4944, model = 0x3337}, -- GE In-Wall Smart Fan Control +} + +return FAN_3_SPEED_FINGERPRINTS diff --git a/drivers/SmartThings/zwave-fan/src/zwave-fan-3-speed/init.lua b/drivers/SmartThings/zwave-fan/src/zwave-fan-3-speed/init.lua index 282f2e35db..c58ab97684 100644 --- a/drivers/SmartThings/zwave-fan/src/zwave-fan-3-speed/init.lua +++ b/drivers/SmartThings/zwave-fan/src/zwave-fan-3-speed/init.lua @@ -1,16 +1,6 @@ --- 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. +-- Copyright 2022 SmartThings, Inc. +-- Licensed under the Apache License, Version 2.0 + local log = require "log" local capabilities = require "st.capabilities" @@ -22,13 +12,6 @@ local Basic = (require "st.zwave.CommandClass.Basic")({ version=1 }) local SwitchMultilevel = (require "st.zwave.CommandClass.SwitchMultilevel")({ version=4 }) local fan_speed_helper = (require "zwave_fan_helpers") -local FAN_3_SPEED_FINGERPRINTS = { - {mfr = 0x001D, prod = 0x1001, model = 0x0334}, -- Leviton 3-Speed Fan Controller - {mfr = 0x0063, prod = 0x4944, model = 0x3034}, -- GE In-Wall Smart Fan Control - {mfr = 0x0063, prod = 0x4944, model = 0x3131}, -- GE In-Wall Smart Fan Control - {mfr = 0x0039, prod = 0x4944, model = 0x3131}, -- Honeywell Z-Wave Plus In-Wall Fan Speed Control - {mfr = 0x0063, prod = 0x4944, model = 0x3337}, -- GE In-Wall Smart Fan Control -} local function map_fan_3_speed_to_switch_level (speed) if speed == fan_speed_helper.fan_speed.OFF then @@ -63,14 +46,6 @@ end --- @param driver st.zwave.Driver --- @param device st.zwave.Device --- @return boolean true if the device is an 3-speed fan, else false -local function is_fan_3_speed(opts, driver, device, ...) - for _, fingerprint in ipairs(FAN_3_SPEED_FINGERPRINTS) do - if device:id_match(fingerprint.mfr, fingerprint.prod, fingerprint.model) then - return true - end - end - return false -end local capability_handlers = {} @@ -110,7 +85,7 @@ local zwave_fan_3_speed = { } }, NAME = "Z-Wave fan 3 speed", - can_handle = is_fan_3_speed, + can_handle = require("zwave-fan-3-speed.can_handle"), } return zwave_fan_3_speed diff --git a/drivers/SmartThings/zwave-fan/src/zwave-fan-4-speed/can_handle.lua b/drivers/SmartThings/zwave-fan/src/zwave-fan-4-speed/can_handle.lua new file mode 100644 index 0000000000..b67f3c2ec7 --- /dev/null +++ b/drivers/SmartThings/zwave-fan/src/zwave-fan-4-speed/can_handle.lua @@ -0,0 +1,14 @@ +-- Copyright 2025 SmartThings, Inc. +-- Licensed under the Apache License, Version 2.0 + +local function can_handle_fan_4_speed(opts, driver, device, ...) + local FINGERPRINTS = require("zwave-fan-4-speed.fingerprints") + for _, fingerprint in ipairs(FINGERPRINTS) do + if device:id_match(fingerprint.mfr, fingerprint.prod, fingerprint.model) then + return true, require("zwave-fan-4-speed") + end + end + return false +end + +return can_handle_fan_4_speed diff --git a/drivers/SmartThings/zwave-fan/src/zwave-fan-4-speed/fingerprints.lua b/drivers/SmartThings/zwave-fan/src/zwave-fan-4-speed/fingerprints.lua new file mode 100644 index 0000000000..2e2f2b13fb --- /dev/null +++ b/drivers/SmartThings/zwave-fan/src/zwave-fan-4-speed/fingerprints.lua @@ -0,0 +1,8 @@ +-- Copyright 2025 SmartThings, Inc. +-- Licensed under the Apache License, Version 2.0 + +local FAN_4_SPEED_FINGERPRINTS = { + {mfr = 0x001D, prod = 0x0038, model = 0x0002}, -- Leviton 4-Speed Fan Controller +} + +return FAN_4_SPEED_FINGERPRINTS diff --git a/drivers/SmartThings/zwave-fan/src/zwave-fan-4-speed/init.lua b/drivers/SmartThings/zwave-fan/src/zwave-fan-4-speed/init.lua index f714a56b1b..a6a9e4efb6 100644 --- a/drivers/SmartThings/zwave-fan/src/zwave-fan-4-speed/init.lua +++ b/drivers/SmartThings/zwave-fan/src/zwave-fan-4-speed/init.lua @@ -1,16 +1,6 @@ --- 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. +-- Copyright 2022 SmartThings, Inc. +-- Licensed under the Apache License, Version 2.0 + local log = require "log" local capabilities = require "st.capabilities" @@ -22,9 +12,6 @@ local Basic = (require "st.zwave.CommandClass.Basic")({ version=1 }) local SwitchMultilevel = (require "st.zwave.CommandClass.SwitchMultilevel")({ version=4 }) local fan_speed_helper = (require "zwave_fan_helpers") -local FAN_4_SPEED_FINGERPRINTS = { - {mfr = 0x001D, prod = 0x0038, model = 0x0002}, -- Leviton 4-Speed Fan Controller -} local function map_fan_4_speed_to_switch_level (speed) if speed == fan_speed_helper.fan_speed.OFF then @@ -64,14 +51,6 @@ end --- @param driver st.zwave.Driver --- @param device st.zwave.Device --- @return boolean true if the device is 4-speed fan, else false -local function can_handle_fan_4_speed(opts, driver, device, ...) - for _, fingerprint in ipairs(FAN_4_SPEED_FINGERPRINTS) do - if device:id_match(fingerprint.mfr, fingerprint.prod, fingerprint.model) then - return true - end - end - return false -end local capability_handlers = {} @@ -111,7 +90,7 @@ local zwave_fan_4_speed = { } }, NAME = "Z-Wave fan 4 speed", - can_handle = can_handle_fan_4_speed, + can_handle = require("zwave-fan-4-speed.can_handle"), } return zwave_fan_4_speed diff --git a/drivers/SmartThings/zwave-fan/src/zwave_fan_helpers.lua b/drivers/SmartThings/zwave-fan/src/zwave_fan_helpers.lua index bb056cf06a..38c26fa78c 100644 --- a/drivers/SmartThings/zwave-fan/src/zwave_fan_helpers.lua +++ b/drivers/SmartThings/zwave-fan/src/zwave_fan_helpers.lua @@ -1,16 +1,6 @@ --- 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. +-- Copyright 2022 SmartThings, Inc. +-- Licensed under the Apache License, Version 2.0 + local capabilities = require "st.capabilities" --- @type st.zwave.CommandClass.SwitchMultilevel