-
Notifications
You must be signed in to change notification settings - Fork 494
Add N/A checking for molecular weight of AQS level handling #2154
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
2
commits into
main
Choose a base branch
from
fix-na-unit-conversion
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
2 commits
Select commit
Hold shift + click to select a range
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
162 changes: 162 additions & 0 deletions
162
drivers/SmartThings/matter-thermostat/src/test/test_matter_air_quality_sensor.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,162 @@ | ||
-- Copyright 2023 SmartThings | ||
-- | ||
-- Licensed under the Apache License, Version 2.0 (the "License"); | ||
-- you may not use this file except in compliance with the License. | ||
-- You may obtain a copy of the License at | ||
-- | ||
-- http://www.apache.org/licenses/LICENSE-2.0 | ||
-- | ||
-- Unless required by applicable law or agreed to in writing, software | ||
-- distributed under the License is distributed on an "AS IS" BASIS, | ||
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
-- See the License for the specific language governing permissions and | ||
-- limitations under the License. | ||
|
||
local test = require "integration_test" | ||
local capabilities = require "st.capabilities" | ||
local t_utils = require "integration_test.utils" | ||
local SinglePrecisionFloat = require "st.matter.data_types.SinglePrecisionFloat" | ||
|
||
local clusters = require "st.matter.clusters" | ||
|
||
local mock_device = test.mock_device.build_test_matter_device({ | ||
profile = t_utils.get_profile_definition("air-purifier-hepa-ac-temperature-humidity-fan-aqs-pm25-tvoc-meas.yml"), | ||
manufacturer_info = { | ||
vendor_id = 0x0000, | ||
product_id = 0x0000, | ||
}, | ||
endpoints = { | ||
{ | ||
endpoint_id = 0, | ||
clusters = { | ||
{cluster_id = clusters.Basic.ID, cluster_type = "SERVER"}, | ||
}, | ||
device_types = { | ||
{device_type_id = 0x0016, device_type_revision = 1} -- RootNode | ||
} | ||
}, | ||
{ | ||
endpoint_id = 1, | ||
clusters = { | ||
{cluster_id = clusters.AirQuality.ID, cluster_type = "SERVER"}, | ||
{cluster_id = clusters.TemperatureMeasurement.ID, cluster_type = "SERVER"}, | ||
{cluster_id = clusters.RelativeHumidityMeasurement.ID, cluster_type = "SERVER"}, | ||
{cluster_id = clusters.CarbonMonoxideConcentrationMeasurement.ID, cluster_type = "SERVER", feature_map = 3}, | ||
{cluster_id = clusters.CarbonDioxideConcentrationMeasurement.ID, cluster_type = "SERVER", feature_map = 3}, | ||
{cluster_id = clusters.NitrogenDioxideConcentrationMeasurement.ID, cluster_type = "SERVER", feature_map = 3}, | ||
{cluster_id = clusters.OzoneConcentrationMeasurement.ID, cluster_type = "SERVER", feature_map = 3}, | ||
{cluster_id = clusters.FormaldehydeConcentrationMeasurement.ID, cluster_type = "SERVER", feature_map = 3}, | ||
{cluster_id = clusters.Pm1ConcentrationMeasurement.ID, cluster_type = "SERVER", feature_map = 3}, | ||
{cluster_id = clusters.Pm25ConcentrationMeasurement.ID, cluster_type = "SERVER", feature_map = 3}, | ||
{cluster_id = clusters.Pm10ConcentrationMeasurement.ID, cluster_type = "SERVER", feature_map = 3}, | ||
{cluster_id = clusters.RadonConcentrationMeasurement.ID, cluster_type = "SERVER", feature_map = 3}, | ||
{cluster_id = clusters.TotalVolatileOrganicCompoundsConcentrationMeasurement.ID, cluster_type = "SERVER", feature_map = 3}, | ||
}, | ||
device_types = { | ||
{device_type_id = 0x002C, device_type_revision = 1} -- Air Quality Sensor | ||
} | ||
} | ||
} | ||
}) | ||
|
||
-- create test_init functions | ||
local function initialize_mock_device(generic_mock_device, generic_subscribed_attributes) | ||
local subscribe_request = nil | ||
for _, attributes in pairs(generic_subscribed_attributes) do | ||
for _, attribute in ipairs(attributes) do | ||
if subscribe_request == nil then | ||
subscribe_request = attribute:subscribe(generic_mock_device) | ||
else | ||
subscribe_request:merge(attribute:subscribe(generic_mock_device)) | ||
end | ||
end | ||
end | ||
test.socket.matter:__expect_send({generic_mock_device.id, subscribe_request}) | ||
test.mock_device.add_test_device(generic_mock_device) | ||
end | ||
|
||
local function test_init() | ||
local subscribed_attributes = { | ||
[capabilities.relativeHumidityMeasurement.ID] = { | ||
clusters.RelativeHumidityMeasurement.attributes.MeasuredValue | ||
}, | ||
[capabilities.temperatureMeasurement.ID] = { | ||
clusters.TemperatureMeasurement.attributes.MeasuredValue, | ||
clusters.TemperatureMeasurement.attributes.MinMeasuredValue, | ||
clusters.TemperatureMeasurement.attributes.MaxMeasuredValue | ||
}, | ||
[capabilities.airQualityHealthConcern.ID] = { | ||
clusters.AirQuality.attributes.AirQuality | ||
}, | ||
[capabilities.finedustSensor.ID] = { | ||
clusters.Pm25ConcentrationMeasurement.attributes.MeasuredValue, | ||
clusters.Pm25ConcentrationMeasurement.attributes.MeasurementUnit, | ||
}, | ||
[capabilities.tvocMeasurement.ID] = { | ||
clusters.TotalVolatileOrganicCompoundsConcentrationMeasurement.attributes.MeasuredValue, | ||
clusters.TotalVolatileOrganicCompoundsConcentrationMeasurement.attributes.MeasurementUnit, | ||
}, | ||
} | ||
initialize_mock_device(mock_device, subscribed_attributes) | ||
end | ||
test.set_test_init_function(test_init) | ||
|
||
test.register_coroutine_test( | ||
"Measured value reports should generate events if there is a stored unit", | ||
function() | ||
test.socket.matter:__queue_receive({ | ||
mock_device.id, | ||
clusters.Pm25ConcentrationMeasurement.attributes.MeasurementUnit:build_test_report_data( | ||
mock_device, 1, clusters.Pm25ConcentrationMeasurement.types.MeasurementUnitEnum.UGM3 | ||
) | ||
}) | ||
test.socket.matter:__queue_receive({ | ||
mock_device.id, | ||
clusters.Pm25ConcentrationMeasurement.attributes.MeasuredValue:build_test_report_data( | ||
mock_device, 1, SinglePrecisionFloat(0, 4, .11187500) -- ~17.9 | ||
) | ||
}) | ||
test.socket.capability:__expect_send( | ||
mock_device:generate_test_message("main", capabilities.fineDustSensor.fineDustLevel({value = 18, unit = "μg/m^3"})) | ||
) | ||
test.socket.matter:__queue_receive({ | ||
mock_device.id, | ||
clusters.TotalVolatileOrganicCompoundsConcentrationMeasurement.attributes.MeasurementUnit:build_test_report_data( | ||
mock_device, 1, clusters.TotalVolatileOrganicCompoundsConcentrationMeasurement.types.MeasurementUnitEnum.PPM | ||
) | ||
}) | ||
test.socket.matter:__queue_receive({ | ||
mock_device.id, | ||
clusters.TotalVolatileOrganicCompoundsConcentrationMeasurement.attributes.MeasuredValue:build_test_report_data( | ||
mock_device, 1, SinglePrecisionFloat(0, -1, .5) -- 0.750 ppm | ||
) | ||
}) | ||
test.socket.capability:__expect_send( | ||
mock_device:generate_test_message("main", capabilities.tvocMeasurement.tvocLevel({value = 750, unit = "ppb"})) | ||
) | ||
end | ||
) | ||
|
||
test.register_coroutine_test( | ||
"Measured value reports should generate events if stored unit does not match target unit and weight is N/A", | ||
function() | ||
test.socket.matter:__queue_receive({ | ||
mock_device.id, | ||
clusters.Pm25ConcentrationMeasurement.attributes.MeasurementUnit:build_test_report_data( | ||
mock_device, 1, clusters.Pm25ConcentrationMeasurement.types.MeasurementUnitEnum.PPM | ||
) | ||
}) | ||
test.socket.matter:__queue_receive({ | ||
mock_device.id, | ||
clusters.Pm25ConcentrationMeasurement.attributes.MeasuredValue:build_test_report_data( | ||
mock_device, 1, SinglePrecisionFloat(0, 4, .11187500) -- ~17.9 | ||
) | ||
}) | ||
test.socket.capability:__expect_send( | ||
mock_device:generate_test_message("main", capabilities.fineDustSensor.fineDustLevel({value = 18, unit = "μg/m^3"})) | ||
) | ||
end | ||
) | ||
|
||
-- run tests | ||
test.run_registered_tests() |
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.
Uh oh!
There was an error while loading. Please reload this page.