-
Notifications
You must be signed in to change notification settings - Fork 464
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
Add support for Inovelli VTM31-SN Dimmer Switch #1754
Open
nickolas-deboom
wants to merge
7
commits into
main
Choose a base branch
from
support-inovelli-vtm31sn
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 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ce551e2
Add support for Inovelli VTM31-SN Dimmer Switch
nickolas-deboom 435c7d5
Improve info_changed logic
nickolas-deboom 2e8b4b5
Move specific device handling to subdriver
nickolas-deboom a3a79ab
fix formatting and remove unused function
nickolas-deboom f48add6
Merge branch 'main' into support-inovelli-vtm31sn
nickolas-deboom cce231f
Merge branch 'main' into support-inovelli-vtm31sn
nickolas-deboom 3405324
Merge branch 'main' into support-inovelli-vtm31sn
nickolas-deboom 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 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
127 changes: 127 additions & 0 deletions
127
drivers/SmartThings/matter-switch/profiles/inovelli-vtm31-sn.yml
This file contains 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,127 @@ | ||
name: inovelli-vtm31-sn | ||
components: | ||
- id: main | ||
capabilities: | ||
- id: switch | ||
version: 1 | ||
- id: switchLevel | ||
version: 1 | ||
- id: refresh | ||
version: 1 | ||
- id: configuration | ||
version: 1 | ||
- id: firmwareUpdate | ||
version: 1 | ||
categories: | ||
- name: Switch | ||
- id: button1 | ||
label: Up Button | ||
capabilities: | ||
- id: button | ||
version: 1 | ||
categories: | ||
- name: RemoteController | ||
- id: button2 | ||
label: Down Button | ||
capabilities: | ||
- id: button | ||
version: 1 | ||
categories: | ||
- name: RemoteController | ||
- id: button3 | ||
label: Config Button | ||
capabilities: | ||
- id: button | ||
version: 1 | ||
categories: | ||
- name: RemoteController | ||
preferences: | ||
- name: "switchMode" | ||
title: "1. Switch Mode" | ||
description: "Use as a Dimmer or an On/Off switch" | ||
required: false | ||
preferenceType: enumeration | ||
definition: | ||
options: | ||
"0": "On/Off + Single (default)" | ||
"1": "On/OFf + Dumb" | ||
"2": "On/Off + Aux" | ||
"3": "On/OFf + Full Wave" | ||
"4": "Dimmer + Single" | ||
"5": "Dimmer + Dumb" | ||
"6": "Dimmer + Aux" | ||
default: 0 | ||
- name: "smartBulbMode" | ||
title: "2. Smart Bulb Mode" | ||
description: "For use with Smart Bulbs that need constant power and are controlled via commands rather than power. Smart Bulb Mode does not work in Sumb 3-Way Switch mode" | ||
required: false | ||
preferenceType: enumeration | ||
definition: | ||
options: | ||
"0": "Disabled (default)" | ||
"1": "Smart Bulb Mode" | ||
default: 0 | ||
- name: "dimmingEdge" | ||
title: "3. Dimming Edge" | ||
description: "Change dimming type to leading edge (default) or trailing edge for better bulb compatibility" | ||
required: false | ||
preferenceType: enumeration | ||
definition: | ||
options: | ||
"0": "Leading (default)" | ||
"1": "Trailing" | ||
default: 0 | ||
- name: "dimmingSpeed" | ||
title: "4. Dimming Speed" | ||
description: "This changes the speed that the light dims. A setting of '0' turns the light immediately on. Increasing the value slows down the transition speed. Default=25 (2500ms or 2.5s)" | ||
required: false | ||
preferenceType: enumeration | ||
definition: | ||
options: | ||
"0": "Instant" | ||
"1": "500ms" | ||
"2": "800ms" | ||
"3": "1s" | ||
"4": "1.5s" | ||
"5": "2s" | ||
"6": "2.5s (default)" | ||
"7": "3s" | ||
"8": "3.5s" | ||
"9": "4s" | ||
"10": "5s" | ||
"11": "6s" | ||
"12": "7s" | ||
"13": "8s" | ||
"14": "10s" | ||
default: 6 | ||
- name: "relayClick" | ||
title: "5. Relay Click" | ||
description: "Audible Click in On/Off mode" | ||
required: false | ||
preferenceType: enumeration | ||
definition: | ||
options: | ||
"0": "Enabled (default)" | ||
"1": "Disabled" | ||
default: 0 | ||
- name: "ledIndicatorColor" | ||
title: "6. LED Indicator Color (w/On)" | ||
description: "Set the color of the Full LED Indicator when the load is on" | ||
required: false | ||
preferenceType: enumeration | ||
definition: | ||
options: | ||
"0": "Red" | ||
"1": "Orange" | ||
"2": "Lemon" | ||
"3": "Lime" | ||
"4": "Green" | ||
"5": "Teal" | ||
"6": "Cyan" | ||
"7": "Aqua" | ||
"8": "Blue (default)" | ||
"9": "Violet" | ||
"10": "Magenta" | ||
"11": "Pink" | ||
"12": "White" | ||
default: 8 |
This file contains 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
81 changes: 81 additions & 0 deletions
81
drivers/SmartThings/matter-switch/src/inovelli-vtm31-sn/init.lua
This file contains 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,81 @@ | ||
-- Copyright 2024 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. | ||
|
||
local clusters = require "st.matter.clusters" | ||
local data_types = require "st.matter.data_types" | ||
local device_lib = require "st.device" | ||
local log = require "log" | ||
|
||
local INOVELLI_VTM31_SN_FINGERPRINT = { vendor_id = 0x1361, product_id = 0x0001 } | ||
|
||
local LATEST_CLOCK_SET_TIMESTAMP = "latest_clock_set_timestamp" | ||
|
||
local preference_map_inovelli_vtm31sn = { | ||
switchMode = {parameter_number = 1, size = data_types.Uint8}, | ||
smartBulbMode = {parameter_number = 2, size = data_types.Uint8}, | ||
dimmingEdge = {parameter_number = 3, size = data_types.Uint8}, | ||
dimmingSpeed = {parameter_number = 4, size = data_types.Uint8}, | ||
relayClick = {parameter_number = 5, size = data_types.Uint8}, | ||
ledIndicatorColor = {parameter_number = 6, size = data_types.Uint8}, | ||
} | ||
|
||
local is_inovelli_vtm31_sn = function(device) | ||
if device.manufacturer_info.vendor_id == INOVELLI_VTM31_SN_FINGERPRINT.vendor_id and | ||
device.manufacturer_info.product_id == INOVELLI_VTM31_SN_FINGERPRINT.product_id then | ||
log.info("Using sub driver") | ||
return true | ||
end | ||
return false | ||
end | ||
|
||
local preferences_to_numeric_value = function(new_value) | ||
local numeric = tonumber(new_value) | ||
if numeric == nil then -- in case the value is Boolean | ||
numeric = new_value and 1 or 0 | ||
end | ||
return numeric | ||
end | ||
|
||
local function info_changed(device, args) | ||
if device.network_type == device_lib.NETWORK_TYPE_CHILD then | ||
return | ||
end | ||
local time_diff = 3 | ||
local last_clock_set_time = device:get_field(LATEST_CLOCK_SET_TIMESTAMP) | ||
if last_clock_set_time ~= nil then | ||
time_diff = os.difftime(os.time(), last_clock_set_time) | ||
end | ||
device:set_field(LATEST_CLOCK_SET_TIMESTAMP, os.time(), {persist = true}) | ||
if time_diff > 2 then | ||
local preferences = preference_map_inovelli_vtm31sn | ||
for id, value in pairs(device.preferences) do | ||
if args.old_st_store.preferences[id] ~= value and preferences and preferences[id] then | ||
local new_parameter_value = preferences_to_numeric_value(device.preferences[id]) | ||
local req = clusters.ModeSelect.server.commands.ChangeToMode(device, preferences[id].parameter_number, | ||
new_parameter_value) | ||
device:send(req) | ||
end | ||
end | ||
end | ||
end | ||
|
||
local inovelli_vtm31_sn_handler = { | ||
NAME = "inovelli vzm31-sn handler", | ||
lifecycle_handlers = { | ||
infoChanged = info_changed | ||
}, | ||
can_handle = is_inovelli_vtm31_sn | ||
} | ||
|
||
return inovelli_vtm31_sn_handler |
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.
Since the inovelli switch already has a sub driver, I would say we should remove this override from the main driver and just add the special handling for the
init
event in the inovelli sub driver. This way we can try to keep the base driver as generic as possible (although there are already exceptions to this).So, I would just copy whatever functionality is needed from the base driver and then put it in the sub driver for the init function, and then trim whatever is not needed. Better yet, you could move the
configure_buttons
function to its own file so that it can be shared between the base and sub driver, similar to what is done with theembedded-cluster-utils
module.