Skip to content

Sort EPs before get device type and add unit test #2216

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 2 commits into
base: main
Choose a base branch
from

Conversation

Huangxiangjie
Copy link
Contributor

@Huangxiangjie Huangxiangjie commented Jun 24, 2025

Check all that apply

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

We find device.endpoints sometimes is disordered, like “ep0, ep5, ep1, ep3, ep4, ep2“. So we plan to sort device endpoints in ASC before judging the device type of equipment,

Summary of Completed Tests

We added Unit Test and tested with real device.

Copy link

Copy link

github-actions bot commented Jun 24, 2025

Test Results

   68 files    444 suites   0s ⏱️
2 317 tests 2 317 ✅ 0 💤 0 ❌
3 917 runs  3 917 ✅ 0 💤 0 ❌

Results for commit 25255d0.

♻️ This comment has been updated with latest results.

Copy link

github-actions bot commented Jun 24, 2025

File Coverage
All files 88%
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/matter-thermostat/src/embedded-cluster-utils.lua 95%
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/matter-thermostat/src/init.lua 88%

Minimum allowed coverage is 90%

Generated by 🐒 cobertura-action against 25255d0

@@ -534,7 +534,14 @@ local function get_endpoints_for_dt(device, device_type)
end

local function get_device_type(device)
Copy link
Contributor

@hcarter-775 hcarter-775 Jun 25, 2025

Choose a reason for hiding this comment

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

I think a slightly more generic version of this function could be:

local function get_device_type(device)
  local device_type_found = {}
  for _, ep in ipairs(device.endpoints) do
    if ep.device_types ~= nil then
      for _, dt in ipairs(ep.device_types) do
        device_type_found[dt.device_type_id] = true
      end
    end
  end

  for _, id in ipairs({
    RAC_DEVICE_TYPE_ID,
    AP_DEVICE_TYPE_ID,
    THERMOSTAT_DEVICE_TYPE_ID,
    FAN_DEVICE_TYPE_ID,
    WATER_HEATER_DEVICE_TYPE_ID,
    HEAT_PUMP_DEVICE_TYPE_ID
  }) do if device_type_found[id] then return id end end

  return false
end

This ensures that we're not just basing the logic on which device type we see first, but rather the order of "precedence" that we give the device types in the drivers. I tested this and confirmed it works with your test case. Thanks

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 also think this is a more generic version and updated PR.
We tested with real device, it works fine, thank you.

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.

2 participants