Skip to content

Matter Switch: Add subdriver for Third Reality MK1 #2109

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 11 commits into
base: matter-switch-update-field-names
Choose a base branch
from

Conversation

nickolas-deboom
Copy link
Contributor

@nickolas-deboom nickolas-deboom commented May 1, 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

Description of Change

Add new profile and a subdriver to support the Third Reality keyboard, which contains 12 matter-enabled buttons.

Summary of Testing

Tested on device and with new unit tests.

Copy link

github-actions bot commented May 1, 2025

Duplicate profile check: Passed - no duplicate profiles detected.

Copy link

github-actions bot commented May 1, 2025

Copy link

github-actions bot commented May 1, 2025

Test Results

   66 files  ±0    426 suites  +1   0s ⏱️ ±0s
2 176 tests  - 7  2 176 ✅  - 7  0 💤 ±0  0 ❌ ±0 
3 709 runs   - 9  3 709 ✅  - 9  0 💤 ±0  0 ❌ ±0 

Results for commit 02b2f8a. ± Comparison against base commit ea07e1b.

This pull request removes 8 and adds 1 tests. Note that renamed tests count towards both.
Clear alarm and smokeDetector states, and read firmware version when the device is added
Should detect newer firmware version and use correct endian format to turn off the siren
Should detect newer firmware version and use correct endian format to turn on the siren
Should detect older firmware version and use correct endian format to turn on the siren
Test firmware version conversion using direct simulation
ZoneStatusChangeNotification should be handled: tested
infochanged to check for necessary preferences settings: tempSensitivity, warningDuration
init and doConfigure lifecycles should be handled properly
Handle single press sequence

♻️ This comment has been updated with latest results.

Copy link

github-actions bot commented May 1, 2025

File Coverage
All files 92%
/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/init.lua 92%
/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 92%

Minimum allowed coverage is 90%

Generated by 🐒 cobertura-action against 02b2f8a

@nickolas-deboom nickolas-deboom changed the title Matter Switch: Add 13 button profile Matter Switch: Add subdriver for 12 button device May 1, 2025
@nickolas-deboom nickolas-deboom changed the title Matter Switch: Add subdriver for 12 button device Matter Switch: Add subdriver for 12 button keyboard May 1, 2025
@ldeora
Copy link

ldeora commented May 1, 2025

Is there a reason why the profiles for 9, 10 and 11 buttons are intentionally omitted? A device like the 3rd Reality MK1 Keyboard would work out of the box with these profiles. The device and the platform are Matter certified after all...

@nickolas-deboom
Copy link
Contributor Author

Is there a reason why the profiles for 9, 10 and 11 buttons are intentionally omitted? A device like the 3rd Reality MK1 Keyboard would work out of the box with these profiles. The device and the platform are Matter certified after all...

This PR is specifically meant for supporting the 3rd Reality MK1.

@nickolas-deboom nickolas-deboom changed the title Matter Switch: Add subdriver for 12 button keyboard Matter Switch: Add subdriver for Third Reality MK1 May 1, 2025
@nickolas-deboom nickolas-deboom force-pushed the add-new-button-profile branch 3 times, most recently from 7a822d1 to ccbdbbd Compare May 1, 2025 17:52
@nickolas-deboom nickolas-deboom force-pushed the add-new-button-profile branch 2 times, most recently from 52e5174 to bc937cc Compare May 8, 2025 15:35
@nickolas-deboom nickolas-deboom changed the base branch from main to matter-switch-update-field-names May 8, 2025 15:35
@nickolas-deboom nickolas-deboom requested a review from ctowns May 8, 2025 15:36
end

local function device_added(driver, device)
device_init(driver, device)
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe let's just subscribe or even return here rather than re-call the whole init? I understand we're mostly doing this call to overwrite the main driver, so I think we could also make a comment of that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The main driver also calls device_init within device_added, which was done to ensure init is called in the case of device caching: ed8fe8f

So I think it might be needed here still?

Copy link
Contributor

Choose a reason for hiding this comment

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

@ctowns what was the reasoning for adding this init function in added for only matter switch? I see it was added in this pr but I don't see a description.

Copy link
Contributor

Choose a reason for hiding this comment

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

This was done to ensure that subscribe was called for all devices, because in some cases there is a race condition that causes the init event to not fire for some devices. Therefore, calling init again in added was meant to ensure that the processing in init was occuring even if the init event was not queued due to the race condition.

Parent-Child devices were primarily affected, so I wouldn't expect it to be an issue here.

There is a detail explanation here: https://smartthings.atlassian.net/browse/CHAD-13449

local function match_profile(driver, device)
device:try_update_metadata({profile = "12-button-keyboard"})
build_button_component_map(device)
configure_buttons(device)
Copy link
Contributor

Choose a reason for hiding this comment

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

would we want to use the new buttons.configure call here as well?

Copy link
Contributor Author

@nickolas-deboom nickolas-deboom May 8, 2025

Choose a reason for hiding this comment

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

Yes but that will need to wait until PR 1754 gets merged (or if this one gets merged first, then that other PR will need to do this change)

local function info_changed(driver, device, event, args)
if device.profile.id ~= args.old_st_store.profile.id then
configure_buttons(device)
subscribe(device)
Copy link
Contributor

@ctowns ctowns May 8, 2025

Choose a reason for hiding this comment

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

You could potentially just override the device:subscribe function directly by calling:

device:extend_device("subscribe", subscribe)

which will override the library subscribe function directly and point the device to the subscribe function you have defined here. I can't think of any cases where this would be needed over the solution you currently have, but if a library function call somewhere calls device:subscribe, it might be nice to just have the default subscribe itself overridden, since that is what the extend_device api is meant to be used for.

@nickolas-deboom nickolas-deboom force-pushed the matter-switch-update-field-names branch from 3d2d422 to 49ba419 Compare May 9, 2025 16:10
The Aqara Cube and Eve Energy subdrivers need doConfigure and
driverSwitched lifecycle event handler overrides to prevent the handlers
from running in the main driver, which would result in match_profile
running.

Also fix nil value error in is_aqara_cube function.
@nickolas-deboom nickolas-deboom force-pushed the matter-switch-update-field-names branch from 49ba419 to ea07e1b Compare May 9, 2025 18:37
Add new profiles to support 13-button devices.
This commit makes this change specific to the Third Reality MK1 keyboard
rather than just adding support for a 12 button device. This allows
custom component names to be used ("F1", "F2", ...) rather than the
default names (i.e. "button3").
Button and switch init will eventually be moved to doConfigure in the
main driver, so moving it there in the subdriver.
Override additional functions in the subdriver to resolve issues found
during testing.
A handler for driverSwitched was added to the main driver, so add an
override to the subdriver to prevent the main driver version from
running.
This driver does not support creating child devices, and any child
device would be prevented from using this driver due to the logic in
is_third_reality_mk1, so the additional gates in other functions can be
removed.
@nickolas-deboom nickolas-deboom force-pushed the add-new-button-profile branch from ac5d0a0 to 02b2f8a Compare May 9, 2025 18:40
@nickolas-deboom nickolas-deboom force-pushed the matter-switch-update-field-names branch from ea07e1b to 653030b Compare May 9, 2025 18:47
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.

4 participants