Skip to content

Conversation

nickolas-deboom
Copy link
Contributor

Keys in datastore tables need to be strings in order to be JSON serializable. SUPPORTED_EVSE_MODES_MAP and
SUPPORTED_DEVICE_ENERGY_MANAGEMENT_MODES_MAP need to be updated.

Keys in datastore tables need to be strings in order to be JSON
serializable. SUPPORTED_EVSE_MODES_MAP and
SUPPORTED_DEVICE_ENERGY_MANAGEMENT_MODES_MAP need to be updated.
Copy link

Copy link

github-actions bot commented Sep 22, 2025

Test Results

   70 files    451 suites   0s ⏱️
2 344 tests 2 344 ✅ 0 💤 0 ❌
3 949 runs  3 949 ✅ 0 💤 0 ❌

Results for commit abc9d86.

♻️ This comment has been updated with latest results.

Copy link

github-actions bot commented Sep 22, 2025

File Coverage
All files 82%
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/matter-energy/src/embedded_cluster_utils.lua 80%
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/matter-energy/src/init.lua 82%

Minimum allowed coverage is 90%

Generated by 🐒 cobertura-action against abc9d86

table.insert(supportedEvseModes, mode.elements.label.value)
end
supportedEvseModesMap[ib.endpoint_id] = supportedEvseModes
supportedEvseModesMap[tostring(ib.endpoint_id)] = supportedEvseModes
Copy link
Contributor

@ctowns ctowns Sep 22, 2025

Choose a reason for hiding this comment

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

I think these changes make sense and address the immediate issue, but there is something that I think we could improve here: would we be able to use the set_field_for_endpoint and get_field_for_endpoint commands here instead of directly saving all this endpoint information to a table?

The set/get_field_for_endpoint command are already used throughout our other drivers, and in those cases we don't run into the issue of the index being a string because the "stringification" of the key value is handled by the functions themselves. Here are the functions copied from the matter-switch driver (although they are used in many drivers):

local function get_field_for_endpoint(device, field, endpoint)
  return device:get_field(string.format("%s_%d", field, endpoint))
end

local function set_field_for_endpoint(device, field, endpoint, value, additional_params)
  device:set_field(string.format("%s_%d", field, endpoint), value, additional_params)
end

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That would definitely be nice, I just wonder if that would cause issues given that it would be a different format than what is currently used on devices in the field. I supposed that it could be avoided by starting with an empty list in the supported modes handlers rather than adding to the existing lists.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Come to think of it, maybe that's how it should be done, since, although probably unlikely, a device could potentially not support a particular mode after supporting it previously, perhaps following a FW update. So it might make sense to start fresh each time the SupportedModes attributes are received.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Never mind, the driver already accounts for that. But still, I like the idea of using get/set_field_for_endpoint and will add an additional commit to this PR with an implementation

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 in abc9d86

local ep = component_to_endpoint(device, cmd.component)
local supportedDeviceEnergyMgmtModesMap = device:get_field(SUPPORTED_DEVICE_ENERGY_MANAGEMENT_MODES_MAP)
local supportedDeviceEnergyMgmtModes = supportedDeviceEnergyMgmtModesMap[ep] or {}
local supportedDeviceEnergyMgmtModes = get_field_for_endpoint(device, SUPPORTED_DEVICE_ENERGY_MANAGEMENT_MODES, ep)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
local supportedDeviceEnergyMgmtModes = get_field_for_endpoint(device, SUPPORTED_DEVICE_ENERGY_MANAGEMENT_MODES, ep)
local supportedDeviceEnergyMgmtModes = get_field_for_endpoint(device, SUPPORTED_DEVICE_ENERGY_MANAGEMENT_MODES, ep) or {}

local ep = component_to_endpoint(device, cmd.component)
local supportedEvseModesMap = device:get_field(SUPPORTED_EVSE_MODES_MAP)
local supportedEvseModes = supportedEvseModesMap[ep] or {}
local supportedEvseModes = get_field_for_endpoint(device, SUPPORTED_EVSE_MODES, ep)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
local supportedEvseModes = get_field_for_endpoint(device, SUPPORTED_EVSE_MODES, ep)
local supportedEvseModes = get_field_for_endpoint(device, SUPPORTED_EVSE_MODES, ep) or {}

Copy link
Contributor

@hcarter-775 hcarter-775 left a comment

Choose a reason for hiding this comment

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

spot test with VDA and I think this is good to go

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.

3 participants