Skip to content

Conversation

@hcarter-775
Copy link
Contributor

@hcarter-775 hcarter-775 commented Sep 16, 2025

Description of Change

This PR aims to re-organize the Matter Switch driver to be easier to read and more self-documenting in its nature.

It does not change any current handling at all, and only re-organizes where the variables and functions are defined, that is, moving them under different files and meta-tables.

The general directory structure is as follows, within src/:

  • embedded-clusters
    • all embedded cluster directories added for backwards compatibility
  • generic-handlers
    • an event_handlers, attribute_handlers, and capability_handlers file, with some functions renamed
  • sub-drivers
    • all current sub-drivers, just placed under this directory
  • utils
    • move embedded-cluster-utils and color-utils here
    • add a switch_fields file with all global vars, a switch_utils file with nearly all non-handler functions, and a device_configuration file with the remaining non-handler functions that relate to device profiling.

Summary of Completed Tests

Ensured capability and attribute handlers ran on the following VDA device types:

  • OnOff Switch,
  • Dimmer Switch,
  • Color Temp Light,
  • Extended Color Light,
  • Mounted OnOff Control,
  • Mounted Dimmable Load Control
  • Generic Switch
  • Electrical Sensor (Aqara H2 Switch)

This testing does not handle an exhaustive list of all handlers that could be hit since this driver includes MCD devices that have illuminance, occupancy, motion, fans, etc. To try every combination is out of scope for this refactor. However, this spot testing, plus a series of unit tests hitting every handler ensures that no mapping between handler and attribute was missed, nor that anything was unduly erased during the refactor. Further, I have restarted the driver multiple times with some of these device types (OnOff Switch, Dimmer Switch) and have seen functionality remain constant.

Since this just moves code around, the primary worry here is that something was deleted or that some typo has come up, which breaks some piece of the code. However, since all tested devices do continue to work and all unit tests continue to pass, I am confident that this has not happened.

Further, I have scanned each handler manually and using inline VScode toolsand ensured each map is expected. I have also manually stepped through all introduced fields.blank and switch_utils.blank calls and ensured they all map to something meaningful.

Last, I have been able to confirm through unit tests with a backend of older lua libs that the embedded cluster definitions continue to run as expected.

@github-actions
Copy link

github-actions bot commented Sep 16, 2025

Channel deleted.

@github-actions
Copy link

github-actions bot commented Sep 16, 2025

File Coverage
All files 92%
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/matter-switch/src/generic_handlers/event_handlers.lua 97%
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/matter-switch/src/generic_handlers/attribute_handlers.lua 83%
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/matter-switch/src/generic_handlers/capability_handlers.lua 88%
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/matter-switch/src/generic_handlers/power_consumption_report.lua 96%
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/matter-switch/src/utils/switch_fields.lua 98%
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/matter-switch/src/utils/device_configuration.lua 97%
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/matter-switch/src/utils/embedded_cluster_utils.lua 38%
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/matter-switch/src/utils/switch_utils.lua 91%
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/matter-switch/src/sub_drivers/eve_energy/init.lua 92%
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/matter-switch/src/sub_drivers/aqara_cube/init.lua 96%
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/matter-switch/src/sub_drivers/third_reality_mk1/init.lua 95%
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/matter-switch/src/init.lua 97%

Minimum allowed coverage is 90%

Generated by 🐒 cobertura-action against eee6f89

@github-actions
Copy link

github-actions bot commented Sep 16, 2025

Test Results

   71 files    452 suites   0s ⏱️
2 351 tests 2 351 ✅ 0 💤 0 ❌
3 959 runs  3 959 ✅ 0 💤 0 ❌

Results for commit eee6f89.

♻️ This comment has been updated with latest results.

Copy link
Contributor

@greens greens left a comment

Choose a reason for hiding this comment

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

quick question: Are there any hubcore versions out there in production that don't have these clusters in their lua_libs still?

Copy link
Contributor

Choose a reason for hiding this comment

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

missing copyright statement

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added

@hcarter-775
Copy link
Contributor Author

quick question: Are there any hubcore versions out there in production that don't have these clusters in their lua_libs still?

Yes, there is a non-zero percentage. We are still watching these numbers to see when is appropriate to remove these altogether, but for now have elected to keep them in the driver.

clusters.ElectricalEnergyMeasurement.attributes.PeriodicEnergyImported
}
}
local attribute_handlers = require "generic-handlers.attribute_handlers"
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: IMO we should have our sub folders using snake_case, but its sort of the wild west; the lua libs follow this, but we dont for the driver and subdriver directory names ¯\(ツ)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

100% agree, just didn't want to rock the boat too hard

@hcarter-775 hcarter-775 force-pushed the refactor-switch-driver branch from 52bfc0d to eaba018 Compare September 18, 2025 21:31
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.

This looks good to me - could you provide a little more commentary on the testing you did in the Summary of Completed Testing section. Did your spot testing include testing all capabilities, driver restart, etc.? Also, do we have coverage of all device types (have we tested an energy device)? If not, I would call out if any device types are covered by unit tests only. But, the refactor makes sense to me and I assume the unit tests would fail if there was any obvious problem, so overall I think this looks good to me.

Great job with the refactor, this looks very well organized!

Copy link
Contributor

@nickolas-deboom nickolas-deboom left a comment

Choose a reason for hiding this comment

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

Looks good to me besides the comment I left about the embedded clusters!

@hcarter-775 hcarter-775 merged commit 4c273ca into main Sep 25, 2025
11 checks passed
@hcarter-775 hcarter-775 deleted the refactor-switch-driver branch September 25, 2025 21:03
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.

6 participants