Skip to content
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
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

nickolas-deboom
Copy link
Contributor

@nickolas-deboom nickolas-deboom commented Nov 14, 2024

Type of Change

  • WWST Certification Request
    • If this is your first time contributing code:
      • I have reviewed the README.md file
      • I have reviewed the CODE_OF_CONDUCT.md file
      • I have signed the CLA
    • I plan on entering a WWST Certification Request or have entered a request through the WWST Certification console at developer.smartthings.com
  • Bug fix
  • New feature
  • Refactor

Checklist

  • I have performed a self-review of my code
  • I have commented my code in hard-to-understand areas
  • I have verified my changes by testing with a device or have communicated a plan for testing
  • I am adding new behavior, such as adding a sub-driver, and have added and run new unit tests to cover the new behavior

Description of Change

CHAD-14347

This change adds support for the Inovelli VTM31-SN Dimmer Switch. Initial support for this device was added by PR 1663. This PR includes a profile for this device with embedded preferences as well as handling for these preferences.

The preferences were created to match those defined in Inovelli's matter driver for this device.

Summary of Completed Tests

See here for screenshots from testing with the device.
Also see test_matter_multi_button_switch_mcd.lua which tests a mock device with a similar endpoint structure as the Inovelli device.

Copy link

Duplicate profile check: Passed - no duplicate profiles detected.

Copy link

Copy link

github-actions bot commented Nov 14, 2024

Test Results

   64 files    402 suites   0s ⏱️
2 002 tests 2 002 ✅ 0 💤 0 ❌
3 456 runs  3 456 ✅ 0 💤 0 ❌

Results for commit 3405324.

♻️ This comment has been updated with latest results.

Copy link

github-actions bot commented Nov 14, 2024

File Coverage
All files 92%
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/matter-switch/src/inovelli-vtm31-sn/init.lua 47%
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/matter-switch/src/embedded-cluster-utils.lua 38%
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/matter-switch/src/eve-energy/init.lua 91%
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/matter-switch/src/aqara-cube/init.lua 96%
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/matter-switch/src/init.lua 96%

Minimum allowed coverage is 90%

Generated by 🐒 cobertura-action against 3405324


local LATEST_CLOCK_SET_TIMESTAMP = "latest_clock_set_timestamp"

local preference_map_inovelli_vtm31sn = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would make sense to move preferences that are specific to a certain device to a sub driver if we are able to. Or these configs could be moved to their own file at least to keep it separate from the base driver where we should try to handle things as generically as possible

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved the inovelli-specific handling to a subdriver in 2e8b4b5

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the mode cluster is going to be used here, this would be the first use of it in the matter-switch driver. This means we'd need to add it as an embedded cluster so it could be used on older FW that doesn't support the mode cluster via the lua libs definitions yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like ModeSelect has been been in the spec since matter 1.0. Is there a way to check when it was first added to the lua libs?

return
end

if device.manufacturer_info.vendor_id == fingerprint_profile_overrides[1].vendor_id and
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is somewhat confusing and I think it could use some comments or documentation somewhere since there is some device specific knowledge here. For example, why is the time diff here and what is the significance of the values?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this code is used to prevent preferences from being changed faster than every two seconds. This was the same way that Inovelli implemented this for the zigbee driver, so it could be a device limitation. I will add some comments to make things a little more clear.

@@ -571,6 +585,15 @@ local function initialize_switch(driver, device)
device:set_field(COMPONENT_TO_ENDPOINT_MAP_BUTTON, component_map, {persist = true})
end

-- If there is a custom static profile for the device, configure buttons if needed and
Copy link
Contributor

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 the embedded-cluster-utils module.

Copy link
Contributor

@ctowns ctowns left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you update these changes with the latest from main? I believe there are some code changes in main related to the overrides in the matter-switch driver that will impact this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants