-
Notifications
You must be signed in to change notification settings - Fork 553
Matter Sensor/Thermostat: Handle invalid unit conversions #3116
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
hcarter-775
wants to merge
6
commits into
main
Choose a base branch
from
chore/handle-invalid-unit-conversions
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
56ed4b5
Matter Sensor: Handle invalid sensor unit conversions, add more conve…
hcarter-775 ffd29e4
Matter Thermostat: Handle invalid sensor unit conversions
hcarter-775 ac7e054
cleanup! matter sensor
hcarter-775 bb91db4
cleanup! matter thermostat
hcarter-775 391779f
add matter thermostat tests
hcarter-775 42f6792
add matter sensor tests
hcarter-775 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
drivers/SmartThings/matter-sensor/src/test/test_unsupported_unit_conversion.lua
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| -- Copyright © 2025 SmartThings, Inc. | ||
| -- Licensed under the Apache License, Version 2.0 | ||
|
|
||
| local test = require "integration_test" | ||
| local capabilities = require "st.capabilities" | ||
|
|
||
| -- Unit conversion utilities for sensor | ||
| local air_quality_sensor_utils = require "sub_drivers.air_quality_sensor.air_quality_sensor_utils.utils" | ||
| local air_quality_sensor_fields = require "sub_drivers.air_quality_sensor.air_quality_sensor_utils.fields" | ||
|
|
||
| test.set_rpc_version(0) | ||
|
|
||
| local units = air_quality_sensor_fields.units | ||
|
|
||
| test.register_coroutine_test( | ||
| "Unsupported unit conversion from PPT to MGM3 should return nil", | ||
| function() | ||
| local result = air_quality_sensor_utils.convert_value_to_unit(100, units.PPT, units.MGM3, capabilities.ozoneMeasurement.NAME) | ||
| assert(result == nil, "Expected nil for unsupported PPT to MGM3 conversion, got: " .. tostring(result)) | ||
| end | ||
| ) | ||
|
|
||
| test.register_coroutine_test( | ||
| "Unsupported unit conversion from PPB to UGM3 should return nil", | ||
| function() | ||
| local result = air_quality_sensor_utils.convert_value_to_unit(100, units.PPB, units.UGM3, capabilities.carbonMonoxideMeasurement.NAME) | ||
| assert(result == nil, "Expected nil for unsupported PPB to UGM3 conversion, got: " .. tostring(result)) | ||
| end | ||
| ) | ||
|
|
||
| test.register_coroutine_test( | ||
| "Unsupported unit conversion from NGM3 to PPM should return nil", | ||
| function() | ||
| local result = air_quality_sensor_utils.convert_value_to_unit(100, units.NGM3, units.PPM, capabilities.carbonMonoxideMeasurement.NAME) | ||
| assert(result == nil, "Expected nil for unsupported NGM3 to PPM conversion, got: " .. tostring(result)) | ||
| end | ||
| ) | ||
|
|
||
| test.register_coroutine_test( | ||
| "Supported unit conversion from PPM to PPB should return correct value", | ||
| function() | ||
| local result = air_quality_sensor_utils.convert_value_to_unit(100, units.PPM, units.PPB, capabilities.carbonMonoxideMeasurement.NAME) | ||
| assert(result ~= nil, "Expected a value for supported PPM to PPB conversion") | ||
| assert(result == 100000, "Expected 100000 for PPM to PPB conversion, got: " .. tostring(result)) | ||
| end | ||
| ) | ||
|
|
||
| test.register_coroutine_test( | ||
| "Supported unit conversion from PPB to PPM should return correct value", | ||
| function() | ||
| local result = air_quality_sensor_utils.convert_value_to_unit(1000, units.PPB, units.PPM, capabilities.carbonMonoxideMeasurement.NAME) | ||
| assert(result ~= nil, "Expected a value for supported PPB to PPM conversion") | ||
| assert(result == 1, "Expected 1 for PPB to PPM conversion, got: " .. tostring(result)) | ||
| end | ||
| ) | ||
|
|
||
| test.register_coroutine_test( | ||
| "Unit conversion with non-numeric value should return nil", | ||
| function() | ||
| local result = air_quality_sensor_utils.convert_value_to_unit("not a number", units.PPM, units.PPB, capabilities.carbonMonoxideMeasurement.NAME) | ||
| assert(result == nil, "Expected nil when value is not a number, got: " .. tostring(result)) | ||
| end | ||
| ) | ||
|
|
||
| test.run_registered_tests() |
65 changes: 65 additions & 0 deletions
65
drivers/SmartThings/matter-thermostat/src/test/test_unsupported_unit_conversion.lua
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| -- Copyright © 2025 SmartThings, Inc. | ||
| -- Licensed under the Apache License, Version 2.0 | ||
|
|
||
| local test = require "integration_test" | ||
| local capabilities = require "st.capabilities" | ||
|
|
||
| -- Unit conversion utilities for thermostat | ||
| local thermostat_utils = require "thermostat_utils.utils" | ||
| local thermostat_fields = require "thermostat_utils.fields" | ||
|
|
||
| test.set_rpc_version(0) | ||
|
|
||
| local units = thermostat_fields.units | ||
|
|
||
| test.register_coroutine_test( | ||
| "Unsupported unit conversion from PPT to MGM3 should return nil", | ||
| function() | ||
| local result = thermostat_utils.convert_value_to_unit(100, units.PPT, units.MGM3, capabilities.ozoneMeasurement.NAME) | ||
| assert(result == nil, "Expected nil for unsupported PPT to MGM3 conversion, got: " .. tostring(result)) | ||
| end | ||
| ) | ||
|
|
||
| test.register_coroutine_test( | ||
| "Unsupported unit conversion from PPB to UGM3 should return nil", | ||
| function() | ||
| local result = thermostat_utils.convert_value_to_unit(100, units.PPB, units.UGM3, capabilities.carbonMonoxideMeasurement.NAME) | ||
| assert(result == nil, "Expected nil for unsupported PPB to UGM3 conversion, got: " .. tostring(result)) | ||
| end | ||
| ) | ||
|
|
||
| test.register_coroutine_test( | ||
| "Unsupported unit conversion from NGM3 to PPM should return nil", | ||
| function() | ||
| local result = thermostat_utils.convert_value_to_unit(100, units.NGM3, units.PPM, capabilities.carbonMonoxideMeasurement.NAME) | ||
| assert(result == nil, "Expected nil for unsupported NGM3 to PPM conversion, got: " .. tostring(result)) | ||
| end | ||
| ) | ||
|
|
||
| test.register_coroutine_test( | ||
| "Supported unit conversion from PPM to PPB should return correct value", | ||
| function() | ||
| local result = thermostat_utils.convert_value_to_unit(100, units.PPM, units.PPB, capabilities.carbonMonoxideMeasurement.NAME) | ||
| assert(result ~= nil, "Expected a value for supported PPM to PPB conversion") | ||
| assert(result == 100000, "Expected 100000 for PPM to PPB conversion, got: " .. tostring(result)) | ||
| end | ||
| ) | ||
|
|
||
| test.register_coroutine_test( | ||
| "Supported unit conversion from PPB to PPM should return correct value", | ||
| function() | ||
| local result = thermostat_utils.convert_value_to_unit(1000, units.PPB, units.PPM, capabilities.carbonMonoxideMeasurement.NAME) | ||
| assert(result ~= nil, "Expected a value for supported PPB to PPM conversion") | ||
| assert(result == 1, "Expected 1 for PPB to PPM conversion, got: " .. tostring(result)) | ||
| end | ||
| ) | ||
|
|
||
| test.register_coroutine_test( | ||
| "Unit conversion with non-numeric value should return nil", | ||
| function() | ||
| local result = thermostat_utils.convert_value_to_unit("not a number", units.PPM, units.PPB, capabilities.carbonMonoxideMeasurement.NAME) | ||
| assert(result == nil, "Expected nil when value is not a number, got: " .. tostring(result)) | ||
| end | ||
| ) | ||
|
|
||
| test.run_registered_tests() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this removed but there is still code that reads the field?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we set the field elsewhere, in the measurement unit read handler. There is no need to set a field to a default. If the unit is unavailable in the field, we just use the default.