Skip to content

fix(ui): Prevent NaN values in environment metrics#4316

Merged
jamesarich merged 1 commit into
mainfrom
fix/nan-metrics
Jan 26, 2026
Merged

fix(ui): Prevent NaN values in environment metrics#4316
jamesarich merged 1 commit into
mainfrom
fix/nan-metrics

Conversation

@jamesarich

Copy link
Copy Markdown
Collaborator

This commit prevents NaN (Not a Number) values from being displayed for dew point and soil temperature in the environment metrics UI.

It introduces checks to ensure that NaN values, which can occur during sensor readings or calculations, are handled gracefully and not passed to the UI layer.

Key Changes:

  • EnvironmentMetrics.kt:
    • Added a check to only display the dew point metric if the calculated value is not NaN.
    • Added a !soilTemperature.isNaN() check before displaying the soil temperature metric.
  • UnitConversions.kt:
    • The toTempString extension function now returns "--" if the float value is NaN, providing a fallback display string.
  • UnitConversionsTest.kt:
    • Added a new unit test to verify that toTempString correctly handles NaN inputs.

This commit prevents `NaN` (Not a Number) values from being displayed for dew point and soil temperature in the environment metrics UI.

It introduces checks to ensure that `NaN` values, which can occur during sensor readings or calculations, are handled gracefully and not passed to the UI layer.

### Key Changes:

- **`EnvironmentMetrics.kt`**:
  - Added a check to only display the dew point metric if the calculated value is not `NaN`.
  - Added a `!soilTemperature.isNaN()` check before displaying the soil temperature metric.
- **`UnitConversions.kt`**:
  - The `toTempString` extension function now returns `"--"` if the float value is `NaN`, providing a fallback display string.
- **`UnitConversionsTest.kt`**:
  - Added a new unit test to verify that `toTempString` correctly handles `NaN` inputs.

Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
@github-actions github-actions Bot added the bugfix PR tag label Jan 26, 2026
@jamesarich jamesarich enabled auto-merge January 26, 2026 12:35
@codecov

codecov Bot commented Jan 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 0.00%. Comparing base (a28aa4d) to head (6a0eb8e).
⚠️ Report is 2 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@          Coverage Diff          @@
##            main   #4316   +/-   ##
=====================================
  Coverage   0.00%   0.00%           
=====================================
  Files          3       3           
  Lines         28      28           
  Branches       8       8           
=====================================
  Misses        28      28           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jamesarich jamesarich added this pull request to the merge queue Jan 26, 2026
Merged via the queue into main with commit 50a04a9 Jan 26, 2026
11 checks passed
@jamesarich jamesarich deleted the fix/nan-metrics branch January 26, 2026 13:19
@dadanielat

Copy link
Copy Markdown

The current meshtastic app crashes when tapping on a node with NaN readings in the node list:
01-26 17:14:13.856 29722 29722 E AndroidRuntime: java.lang.IllegalArgumentException: Cannot round NaN value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix PR tag

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants