Skip to content
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

Use PPB for TVOC measurement units #1852

Merged
merged 4 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -309,11 +309,11 @@ local unit_default = {
[capabilities.fineDustSensor.NAME] = units.UGM3,
[capabilities.dustSensor.NAME] = units.UGM3,
[capabilities.radonMeasurement.NAME] = units.BQM3,
[capabilities.tvocMeasurement.NAME] = units.PPM
[capabilities.tvocMeasurement.NAME] = units.PPB -- TVOC is typically within the range of 0-5500 ppb, with good to moderate values being < 660 ppb
}

-- All ConcentrationMesurement clusters inherit from the same base cluster definitions,
-- so CarbonMonoxideConcentratinMeasurement is used below but the same enum types exist
-- All ConcentrationMeasurement clusters inherit from the same base cluster definitions,
-- so CarbonMonoxideConcentrationMeasurement is used below but the same enum types exist
-- in all ConcentrationMeasurement clusters
local level_strings = {
[clusters.CarbonMonoxideConcentrationMeasurement.types.LevelValueEnum.UNKNOWN] = "unknown",
Expand All @@ -325,10 +325,12 @@ local level_strings = {

local conversion_tables = {
[units.PPM] = {
[units.PPM] = function(value) return utils.round(value) end
[units.PPM] = function(value) return utils.round(value) end,
[units.PPB] = function(value) return utils.round(value * (10^3)) end
},
[units.PPB] = {
[units.PPM] = function(value) return utils.round(value/(10^3)) end
[units.PPM] = function(value) return utils.round(value/(10^3)) end,
[units.PPB] = function(value) return utils.round(value) end
},
[units.PPT] = {
[units.PPM] = function(value) return utils.round(value/(10^6)) end
Expand Down Expand Up @@ -473,7 +475,7 @@ local matter_air_quality_sensor_handler = {
[clusters.RadonConcentrationMeasurement.attributes.LevelValue.ID] = levelHandlerFactory(capabilities.radonHealthConcern.radonHealthConcern)
},
[clusters.TotalVolatileOrganicCompoundsConcentrationMeasurement.ID] = {
[clusters.TotalVolatileOrganicCompoundsConcentrationMeasurement.attributes.MeasuredValue.ID] = measurementHandlerFactory(capabilities.tvocMeasurement.NAME, capabilities.tvocMeasurement.tvocLevel, units.PPM),
[clusters.TotalVolatileOrganicCompoundsConcentrationMeasurement.attributes.MeasuredValue.ID] = measurementHandlerFactory(capabilities.tvocMeasurement.NAME, capabilities.tvocMeasurement.tvocLevel, units.PPB),
[clusters.TotalVolatileOrganicCompoundsConcentrationMeasurement.attributes.MeasurementUnit.ID] = store_unit_factory(capabilities.tvocMeasurement.NAME),
[clusters.TotalVolatileOrganicCompoundsConcentrationMeasurement.attributes.LevelValue.ID] = levelHandlerFactory(capabilities.tvocHealthConcern.tvocHealthConcern)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,21 @@ test.register_coroutine_test(
test.socket.capability:__expect_send(
mock_device:generate_test_message("main", capabilities.dustSensor.dustLevel({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
)

Expand Down
8 changes: 5 additions & 3 deletions drivers/SmartThings/matter-thermostat/src/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ local unit_default = {
[capabilities.fineDustSensor.NAME] = units.UGM3,
[capabilities.dustSensor.NAME] = units.UGM3,
[capabilities.radonMeasurement.NAME] = units.BQM3,
[capabilities.tvocMeasurement.NAME] = units.PPM
[capabilities.tvocMeasurement.NAME] = units.PPB -- TVOC is typically within the range of 0-5500 ppb, with good to moderate values being < 660 ppb
}

-- All ConcentrationMesurement clusters inherit from the same base cluster definitions,
Expand Down Expand Up @@ -620,11 +620,13 @@ local molecular_weights = {
local conversion_tables = {
[units.PPM] = {
[units.PPM] = function(value) return utils.round(value) end,
[units.PPB] = function(value) return utils.round(value * (10^3)) end,
[units.UGM3] = function(value, molecular_weight) return utils.round((value * molecular_weight * 10^3) / MGM3_PPM_CONVERSION_FACTOR) end,
[units.MGM3] = function(value, molecular_weight) return utils.round((value * molecular_weight) / MGM3_PPM_CONVERSION_FACTOR) end,
},
[units.PPB] = {
[units.PPM] = function(value) return utils.round(value/(10^3)) end
[units.PPM] = function(value) return utils.round(value/(10^3)) end,
[units.PPB] = function(value) return utils.round(value) end,
},
[units.PPT] = {
[units.PPM] = function(value) return utils.round(value/(10^6)) end
Expand Down Expand Up @@ -1429,7 +1431,7 @@ local matter_driver_template = {
[clusters.RadonConcentrationMeasurement.attributes.LevelValue.ID] = levelHandlerFactory(capabilities.radonHealthConcern.radonHealthConcern)
},
[clusters.TotalVolatileOrganicCompoundsConcentrationMeasurement.ID] = {
[clusters.TotalVolatileOrganicCompoundsConcentrationMeasurement.attributes.MeasuredValue.ID] = measurementHandlerFactory(capabilities.tvocMeasurement.NAME, capabilities.tvocMeasurement.tvocLevel, units.PPM),
[clusters.TotalVolatileOrganicCompoundsConcentrationMeasurement.attributes.MeasuredValue.ID] = measurementHandlerFactory(capabilities.tvocMeasurement.NAME, capabilities.tvocMeasurement.tvocLevel, units.PPB),
[clusters.TotalVolatileOrganicCompoundsConcentrationMeasurement.attributes.MeasurementUnit.ID] = store_unit_factory(capabilities.tvocMeasurement.NAME),
[clusters.TotalVolatileOrganicCompoundsConcentrationMeasurement.attributes.LevelValue.ID] = levelHandlerFactory(capabilities.tvocHealthConcern.tvocHealthConcern)
}
Expand Down
Loading