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

Spot tested on the following VDA device types: OnOff Switch, Dimmer Switch, Color Temp Light, Extended Color Light, Mounted OnOff Control, Mounted Dimmable Load Control.

Copy link

Copy link

github-actions bot commented Sep 16, 2025

File Coverage
All files 92%
/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/utils/embedded_cluster_utils.lua 38%
/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/generic_handlers/event_handlers.lua 97%
/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/generic_handlers/capability_handlers.lua 88%
/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/sub_drivers/aqara_cube/init.lua 96%
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/matter-switch/src/init.lua 97%
/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/sub_drivers/eve_energy/init.lua 92%

Minimum allowed coverage is 90%

Generated by 🐒 cobertura-action against 03d5f69

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 03d5f69.

♻️ 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!


-- Include driver-side definitions when lua libs api version is < 11
if version.api < 11 then
clusters.ValveConfigurationAndControl = require "embedded_clusters.ValveConfigurationAndControl"
Copy link
Contributor

@nickolas-deboom nickolas-deboom Sep 23, 2025

Choose a reason for hiding this comment

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

This require statement and others for embedded clusters fail for some reason, saying Received unexpected error: ./embedded_clusters/ValveConfigurationAndControl/init.lua:2: module 'ValveConfigurationAndControl.server.attributes' not found

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, the embedded cluster definitions just need to be updated to reflect the new path, i.e.
local ValveConfigurationAndControlServerAttributes = require "ValveConfigurationAndControl.server.attributes"
should be
local ValveConfigurationAndControlServerAttributes = require "embedded_clusters.ValveConfigurationAndControl.server.attributes" here

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!

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.

5 participants