Skip to content

Implement modular profiles for matter switch #2142

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

Conversation

nickolas-deboom
Copy link
Contributor

@nickolas-deboom nickolas-deboom commented May 23, 2025

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

This PR was initially branched off of #2112, but now targets main instead as the other PR was used for testing purposes and so was not optimized. The changes in this PR add support for modular profiles to the matter switch driver. Additionally, a subdriver for static profile code is introduced and also some functionality is separated into button-utils and common-utils so that it can be used across multiple modules. This allows the main driver to contain the latest code and not needing to maintain two separate paths depending on whether a given setup supports modular profiles or not. Another benefit is that the static profile subdriver won't need to be loaded for environments supporting modular profiles.

There are 5 main device types covered by the matter switch driver: Buttons, On/Off Lights, Smart Plugs, Switches, and Water Valves. These 5 categories are used in the driver to help select a modular profile to use, in order to set the category correctly based on the device type. Therefore there are 5 modular profiles introduced by this PR. Each of them also include 8 optional button components as buttons are commonly included in other devices.

Lights are excluded from modular profile support for now, since modular profiles don't currently support lighting groups on the cloud side.

Please let me know if you have any ideas on improvements, this should be considered a WIP as we continue to hash out ideas.

Summary of Completed Tests

More new test cases will be needed.

Copy link

Copy link

github-actions bot commented May 23, 2025

Test Results

   67 files  ±0    441 suites  +1   0s ⏱️ ±0s
2 251 tests +1  2 251 ✅ +1  0 💤 ±0  0 ❌ ±0 
3 842 runs  +1  3 842 ✅ +1  0 💤 ±0  0 ❌ ±0 

Results for commit 0d5023f. ± Comparison against base commit 634161b.

♻️ This comment has been updated with latest results.

Copy link

github-actions bot commented May 23, 2025

File Coverage
All files 88%
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/matter-switch/src/button-utils.lua 99%
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/matter-switch/src/third-reality-mk1/init.lua 95%
/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/static-profiles/init.lua 96%
/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/aqara-cube/init.lua 96%
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/matter-switch/src/modular-profiles-utils.lua 54%
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/matter-switch/src/common-utils.lua 95%
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/matter-switch/src/init.lua 88%

Minimum allowed coverage is 90%

Generated by 🐒 cobertura-action against 0d5023f

@nickolas-deboom nickolas-deboom changed the title Create modular profiles subdriver Create static profiles subdriver May 28, 2025
@nickolas-deboom nickolas-deboom changed the base branch from modular-profiles-test-matter-switch to main May 28, 2025 18:45
-- Check if the device supports BatPercentRemaining or BatChargeLevel.
-- Prefer BatPercentRemaining if available.
if attr.value == clusters.PowerSource.attributes.BatPercentRemaining.ID then
battery_attr_support = common_utils.battery_support.BATTERY_PERCENTAGE
break
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 removed this break because I think that if the attribute list doesn't come in sorted order (and maybe it does so this doesn't matter) then this could lead to battery level being chosen instead of battery percentage if a device supports both

Copy link

Duplicate profile check: Passed - no duplicate profiles detected.

@@ -32,16 +33,6 @@ local INITIAL_PRESS_ONLY = "__initial_press_only" -- for devices that support MS
local CUBEACTION_TIMER = "__cubeAction_timer"
local CUBEACTION_TIME = 3

local function is_aqara_cube(opts, driver, device)
if device.network_type == device_lib.NETWORK_TYPE_MATTER then
Copy link
Contributor Author

@nickolas-deboom nickolas-deboom May 28, 2025

Choose a reason for hiding this comment

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

Moving these functions out of subdrivers and into common_utils so that they can be used to determine if they should be used rather than the static profile subdriver.

@nickolas-deboom nickolas-deboom changed the title Create static profiles subdriver Implement modular profiles for matter switch May 28, 2025
@nickolas-deboom nickolas-deboom force-pushed the create-modular-profiles-subdriver branch 2 times, most recently from 7508866 to eaa9b79 Compare May 28, 2025 20:43
@nickolas-deboom nickolas-deboom force-pushed the create-modular-profiles-subdriver branch from 325e7b6 to 2b181a2 Compare May 28, 2025 21:18
@@ -0,0 +1,464 @@
-- Copyright 2025 SmartThings
Copy link
Contributor Author

@nickolas-deboom nickolas-deboom May 28, 2025

Choose a reason for hiding this comment

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

Note that the only new code introduced by this file is the supports_modular_profile function and changes to find_default_endpoint. Everything else was moved from init.lua (and the is_aqara_cube, is_eve_energy_products, etc functions from the subdrivers) without modification.

end
end
if profile_name ~= "" then
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note that this handling was moved to the static profile subdriver's implementation of the PowerSource AttributeList handler.

@nickolas-deboom nickolas-deboom force-pushed the create-modular-profiles-subdriver branch 3 times, most recently from 0776cde to f402bc9 Compare May 29, 2025 18:40
@nickolas-deboom nickolas-deboom force-pushed the create-modular-profiles-subdriver branch from 59c5fe0 to 130c39d Compare May 30, 2025 18:59
nickolas-deboom added a commit that referenced this pull request May 30, 2025
Renaming buttons.lua to button-utils.lua to align with the changes
coming in #2142.
With the previous commit, switches and buttons were not being initialized when modular
profiles were used
Add new modular profiles to support other device types that require different
categories. Add new logic in the driver to support the new profiles.
Support additional, optional plug components in the plug-modular
profile. Also, fix the component mapping for button endpoints.
Using a subdriver for modular profile code and also separate some
functionality into button-utils and common-utils so that it can be
across multiple files.
It might make more sense to put the code for environments that don't
support modular profiles into a subdriver so that it doesn't even need
to be loaded on setups that do support modular profiles. This way, the
main driver contains the most up to date code rather than having to maintain
two paths.
Also update other subdrivers so that they are preferred over the static
profile subdriver.
Move the else clause of common-utils/find_default_endpoint into
static/profiles/init.lua rather than having two paths for static vs
modular.
Porting over some code from modular-profiles-utils into common-utils to
support a more advanced is_static_profile_device function, allowing us
to check the device category and exclude Light devices from using
modular profiles, since lighting groups do not currently work with
modular profiles.
@nickolas-deboom nickolas-deboom force-pushed the create-modular-profiles-subdriver branch from eb05b0b to becfe25 Compare June 3, 2025 14:41
Swap mandatory capabilities for switch and valve. Also remove check for
Aqara W100 from supports_modular_profile as this device would support
modular profiles.
@nickolas-deboom nickolas-deboom force-pushed the create-modular-profiles-subdriver branch from becfe25 to 5edce5a Compare June 3, 2025 15:12
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.

1 participant