Skip to content

Conversation

@hcarter-775
Copy link
Contributor

@hcarter-775 hcarter-775 commented Nov 17, 2025

Description of Change

This cuts down the amount of checks and reformatting handled in the endpoint_to_component and emit_event_for_endpoint functions.

This logic was just added by me in the recent Camera PR and it was a bit rushed. This cleans up some unnecessary logic that was introduced.

Summary of Completed Tests

Tested by Unit Test and with VDA. Expanded functionality is currently only utilized by unreleased Camera subdriver

@github-actions
Copy link

github-actions bot commented Nov 17, 2025

Channel deleted.

@github-actions
Copy link

github-actions bot commented Nov 17, 2025

Test Results

   71 files  ±0    469 suites  +1   0s ⏱️ ±0s
2 457 tests +2  2 457 ✅ +2  0 💤 ±0  0 ❌ ±0 
4 177 runs  +9  4 177 ✅ +9  0 💤 ±0  0 ❌ ±0 

Results for commit 574fd58. ± Comparison against base commit 9fa6434.

♻️ This comment has been updated with latest results.

@github-actions
Copy link

github-actions bot commented Nov 17, 2025

File Coverage
All files 92%
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/matter-switch/src/sub_drivers/camera/camera_handlers/attribute_handlers.lua 95%
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/matter-switch/src/sub_drivers/camera/camera_handlers/capability_handlers.lua 78%
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/matter-switch/src/switch_utils/embedded_cluster_utils.lua 38%
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/matter-switch/src/switch_utils/utils.lua 90%
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/matter-switch/src/switch_utils/fields.lua 99%
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/matter-switch/src/switch_utils/device_configuration.lua 97%
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/matter-switch/src/sub_drivers/camera/camera_utils/device_configuration.lua 97%
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/matter-switch/src/sub_drivers/camera/camera_utils/utils.lua 95%
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/matter-switch/src/sub_drivers/camera/init.lua 98%
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/matter-switch/src/switch_handlers/capability_handlers.lua 88%
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/matter-switch/src/switch_handlers/attribute_handlers.lua 83%
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/matter-switch/src/switch_handlers/event_handlers.lua 97%
/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/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/sub_drivers/aqara_cube/init.lua 96%

Minimum allowed coverage is 90%

Generated by 🐒 cobertura-action against 574fd58

Comment on lines 205 to 209
local formatted_info = {}
if type(ep_info) == "number" then
ep_info = { endpoint_id = ep_info }
formatted_info = { endpoint_id = ep_info }
elseif type(ep_info) == "table" then
ep_info = {
endpoint_id = ep_info.endpoint_id,
cluster_id = ep_info.cluster_id,
attribute_id = ep_info.attribute_id
}
formatted_info = ep_info
Copy link
Contributor

Choose a reason for hiding this comment

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

Effectively, can't this just be

  if type(ep_info) == "number" then
    ep_info = { endpoint_id = ep_info }
  end

? There isn't any transform done to the table form, and other types are not transformed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh it can. I just thought that might be weird/wrong cause the capability event id is going to get appended later and that's not technically "ep info"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

but I suppose it's kinda equally weird to break it apart like I did, so I'll switch it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ended up removing capabilities from the mapping, so this makes even more sense now

--- to route events to.
---
--- @param device any a Matter device object
--- @param ep_info number|table endpoint_id or ib (includes endpoint_id, cluster_id, attribute_id)
Copy link
Contributor

Choose a reason for hiding this comment

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

Are cluster_id and attribute_id required when in table form? Is capability_id required as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

again, they are at the time but I suppose don't need to be. changed the wording in the upcoming commit

Copy link
Contributor Author

Choose a reason for hiding this comment

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

well, it actually reads endpoint_id or ib, and I note that the ib includes that data. I agree this wording is a little confused

--- single endpoint.
---
--- @param device any a Matter device object
--- @param opts number|table either is an ep_id or a table { endpoint_id, capability_id }
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this doc should include mention of the required fields of cluster_id and attribute_id when in table form.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

Comment on lines 186 to 187
and (not map_info.cluster_id or (map_info.cluster_id == opts.cluster_id
and utils.tbl_contains(map_info.attribute_ids, opts.attribute_id)))
Copy link
Contributor

Choose a reason for hiding this comment

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

We are using the logic that existence of the cluster_id field implies the existence of a non-nil attribute_id. Is this always the case?

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 is at the time (and I can't see when/why it wouldn't be), though I can see how it can seem a little arbitrary. fixed in next commit (cannot push now due to github outage)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

---
--- @param device any a Matter device object
--- @param opts number|table either is an ep_id or a table { endpoint_id, capability_id }
--- @param ep_info number|table either an ep_id or a table { endpoint_id, optional(cluster_id), optional(attribute_id) }
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we choose a single parameter type and make the the caller provide the additional info? I know lua doesn't have strong parameter typing but I think this is a practice we should try to avoid. If you need to handle additional optional values, they can be passed as optional parameters:

function utils.endpoint_to_component(device, ep, cluster_id, attribute_id)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We cannot. Since we want to have this be compatible with the lua libs, we cannot add extra arguments. This was a compromise I figured was relatively clear given the limitation.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand the reasoning for why we cannot add extra arguments - why is backwards compatibility a concern if we are creating a new function that overrides the lua libs? I think we should only use this override when needed, and it shouldn't be a blanket override for all devices in the switch driver, unless they specifically require this advanced mapping, right?

If this is a function override, I assume we can make it whatever we want. Even using extend_device allows us to override the function pointer from the lua libs and just point to this new function, even though I don't neccessarily think using extend_device in this case is the way to go.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also just a note that this discussion isn't a blocker if this needs to go in urgently, but I think it's worth having more discussion around how we should be designing these APIs for this complex mapping.

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.

LGTM, I tested with the camera example app and things are looking good with these changes.

@hcarter-775 hcarter-775 merged commit d957e69 into main Nov 24, 2025
11 checks passed
@hcarter-775 hcarter-775 deleted the update/e2c-mapping branch November 24, 2025 19:28
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