-
-
Notifications
You must be signed in to change notification settings - Fork 497
fix(ui): stop discarding measured-zero sensor and RSSI readings #6507
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
Merged
Merged
Changes from all commits
Commits
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
27 changes: 27 additions & 0 deletions
27
.coderabbit/ast-grep-rules/no-float-metric-zero-sentinel.yml
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,27 @@ | ||
| # Recurring defect class A — see "Presence vs sentinel zero" in .skills/code-review/SKILL.md. | ||
| # | ||
| # The protobuf models are Wire-generated, so presence IS nullability: EnvironmentMetrics.temperature and friends are | ||
| # declared `Float? = null` and there is no hasX() accessor. A `(x ?: 0f) != 0f` guard collapses "absent" and | ||
| # "measured zero" into one state and silently discards a real reading. Use `x?.let { ... }` instead — see | ||
| # `gatherSensors` in core/ui/.../NodeItem.kt for the reference pattern. | ||
| # | ||
| # Humidity is the deliberate exception: 0 %RH is not physically reachable, so relative_humidity / co2_humidity keep | ||
| # their zero-guards and are not listed here. Same for barometric_pressure (0 hPa is a vacuum). | ||
| id: no-float-metric-zero-sentinel | ||
| language: kotlin | ||
| severity: error | ||
| message: "0 is a real reading on this scale — use `?.let { }` instead of a zero-guard." | ||
| # Every spelling of the zero-float literal is listed: a reformat from `0f` to `0.0f` must not slip past the rule. | ||
| rule: | ||
| any: | ||
| - pattern: "($X ?: 0f) != 0f" | ||
| - pattern: "($X ?: 0f) == 0f" | ||
| - pattern: "($X ?: 0F) != 0F" | ||
| - pattern: "($X ?: 0F) == 0F" | ||
| - pattern: "($X ?: 0.0f) != 0.0f" | ||
| - pattern: "($X ?: 0.0f) == 0.0f" | ||
| - pattern: "($X ?: 0.0F) != 0.0F" | ||
| - pattern: "($X ?: 0.0F) == 0.0F" | ||
| constraints: | ||
| X: | ||
| regex: "(temperature|voltage|current|soil_moisture)$" | ||
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,20 @@ | ||
| # Recurring defect class A — see "Presence vs sentinel zero" in .skills/code-review/SKILL.md. | ||
| # | ||
| # 0 dBm is the STRONGEST value on the RSSI scale, so defaulting a missing reading to 0 renders an unknown signal as an | ||
| # excellent one. Keep the value nullable end-to-end and let `MetricFormatter.rssi(null)` render an em dash. | ||
| # | ||
| # Scope: this rule targets DEFAULTING a live reading (`?: 0`), not comparing a stored one. A `rssi == 0` test against | ||
| # persisted data can be legitimate migration handling — `Reaction.kt` reads pre-schema-51 rows that stored 0 where the | ||
| # column is now nullable, so there a 0 really is indistinguishable from "no reading". Broadening this rule to `== 0` | ||
| # would flag that documented exception and nothing else, so it deliberately stops at the `?: 0` form. | ||
| id: no-rssi-zero-default | ||
| language: kotlin | ||
| severity: error | ||
| message: "0 dBm is the strongest RSSI, not \"unknown\" — keep the value nullable." | ||
| rule: | ||
| any: | ||
| - pattern: "$X ?: 0" | ||
| - pattern: "($X ?: 0) != 0" | ||
| constraints: | ||
| X: | ||
| regex: "(?i)rssi$" | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
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
55 changes: 55 additions & 0 deletions
55
core/ble/src/commonTest/kotlin/org/meshtastic/core/ble/MeshtasticBleDeviceRssiTest.kt
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,55 @@ | ||
| /* | ||
| * Copyright (c) 2026 Meshtastic LLC | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU General Public License as published by | ||
| * the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU General Public License | ||
| * along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
| */ | ||
| package org.meshtastic.core.ble | ||
|
|
||
| import com.juul.kable.Advertisement | ||
| import dev.mokkery.MockMode | ||
| import dev.mokkery.answering.returns | ||
| import dev.mokkery.every | ||
| import dev.mokkery.mock | ||
| import kotlinx.coroutines.test.runTest | ||
| import kotlin.test.Test | ||
| import kotlin.test.assertEquals | ||
| import kotlin.test.assertNull | ||
|
|
||
| /** | ||
| * 0 dBm is the strongest value on the RSSI scale, so a bonded-only device with no advertisement must report `null` | ||
| * rather than collapse into an excellent-signal reading. Both cases are pinned together. | ||
| */ | ||
| class MeshtasticBleDeviceRssiTest { | ||
|
|
||
| @Test | ||
| fun `advertised zero rssi is reported`() = runTest { | ||
| val advertisement: Advertisement = mock(MockMode.autofill) { every { rssi } returns 0 } | ||
| val device = MeshtasticBleDevice(address = ADDRESS, advertisement = advertisement) | ||
|
|
||
| assertEquals(0, device.rssi) | ||
| assertEquals(0, device.readRssi()) | ||
| } | ||
|
|
||
| @Test | ||
| fun `bonded-only device without an advertisement reports no rssi`() = runTest { | ||
| val device = MeshtasticBleDevice(address = ADDRESS) | ||
|
|
||
| assertNull(device.rssi) | ||
| assertNull(device.readRssi()) | ||
| } | ||
|
|
||
| private companion object { | ||
| const val ADDRESS = "AA:BB:CC:DD:EE:FF" | ||
| } | ||
| } |
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
72 changes: 72 additions & 0 deletions
72
core/model/src/commonTest/kotlin/org/meshtastic/core/model/NodeTelemetryStringsTest.kt
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,72 @@ | ||
| /* | ||
| * Copyright (c) 2026 Meshtastic LLC | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU General Public License as published by | ||
| * the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU General Public License | ||
| * along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
| */ | ||
| package org.meshtastic.core.model | ||
|
|
||
| import org.meshtastic.proto.EnvironmentMetrics | ||
| import kotlin.test.Test | ||
| import kotlin.test.assertEquals | ||
| import kotlin.test.assertTrue | ||
|
|
||
| /** | ||
| * `EnvironmentMetrics` fields are Wire-generated and nullable, so `null` is the only "not reported" signal. Each metric | ||
| * is pinned twice — absent and measured-zero — because either assertion alone lets the two states collapse back into | ||
| * one. | ||
| */ | ||
| class NodeTelemetryStringsTest { | ||
|
|
||
| private fun telemetry(metrics: EnvironmentMetrics) = | ||
| Node(num = 1, environmentMetrics = metrics).getTelemetryStrings() | ||
|
|
||
| @Test | ||
| fun absent_environment_metrics_render_nothing() { | ||
| assertEquals(emptyList(), telemetry(EnvironmentMetrics())) | ||
| } | ||
|
|
||
| @Test | ||
| fun zero_temperature_is_reported() { | ||
| assertEquals(listOf("0.0°C"), telemetry(EnvironmentMetrics(temperature = 0f))) | ||
| } | ||
|
|
||
| @Test | ||
| fun zero_voltage_and_current_are_reported() { | ||
| val strings = telemetry(EnvironmentMetrics(voltage = 0f, current = 0f)) | ||
| assertEquals(listOf("0.00 V", "0.0 mA"), strings) | ||
| } | ||
|
|
||
| @Test | ||
| fun zero_soil_readings_are_reported() { | ||
| val strings = telemetry(EnvironmentMetrics(soil_temperature = 0f, soil_moisture = 0)) | ||
| assertEquals(listOf("0.0°C", "0%"), strings) | ||
| } | ||
|
|
||
| @Test | ||
| fun soil_moisture_no_longer_requires_a_soil_temperature() { | ||
| assertEquals(listOf("42%"), telemetry(EnvironmentMetrics(soil_moisture = 42))) | ||
| } | ||
|
|
||
| @Test | ||
| fun out_of_range_soil_moisture_is_still_rejected() { | ||
| assertEquals(emptyList(), telemetry(EnvironmentMetrics(soil_moisture = 101))) | ||
| } | ||
|
|
||
| @Test | ||
| fun zero_humidity_stays_filtered() { | ||
| // 0 %RH is not physically reachable, so unlike the other metrics its zero-guard is intentional. | ||
| assertTrue(telemetry(EnvironmentMetrics(relative_humidity = 0f)).isEmpty()) | ||
| assertEquals(listOf("41%"), telemetry(EnvironmentMetrics(relative_humidity = 41f))) | ||
| } | ||
| } |
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
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.
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.