Skip to content

feat(telemetry): auto-scale current/power units and humanize uptime (#3261)#3264

Merged
Yeraze merged 1 commit into
mainfrom
feat/telemetry-unit-autoscale
May 30, 2026
Merged

feat(telemetry): auto-scale current/power units and humanize uptime (#3261)#3264
Yeraze merged 1 commit into
mainfrom
feat/telemetry-unit-autoscale

Conversation

@Yeraze
Copy link
Copy Markdown
Owner

@Yeraze Yeraze commented May 30, 2026

Summary

Closes #3261.

MeshCore (and Meshtastic) telemetry rendered small current/power readings as unreadable 0.01 A / 0.00 W, and uptime as a large raw seconds count. This adds a shared display helper that auto-scales current and power to the most readable SI prefix and renders uptime as a human-readable duration — applied consistently across the telemetry table, charts, gauges, and numeric widgets.

Behavior

  • Current: 0.45 A → 450 mA, 1500 mA → 1.5 A
  • Power: 0.012 W → 12 mW, 2500 W → 2.5 kW
  • Uptime: 350000 s → 4d 1h (no unit suffix)
  • Non-scalable units (V, °C, %, dBm, …) are untouched.

Fixes both Meshtastic (mA / envCurrent) and MeshCore LPP telemetry (current=A, power=W, mc_*_uptime_secs).

Changes

  • src/utils/telemetryFormat.ts (new): unitScale / scaleMeasurement (magnitude-driven prefix selection), isUptimeType, formatDuration.
  • src/utils/telemetryFormat.test.ts (new): 29 unit tests covering prefix boundaries, sign handling, non-scalable units, and durations.
  • src/pages/UnifiedTelemetryPage.tsx: per-row auto-scaling of current/power; uptime rendered as a duration with no unit suffix; reuses the shared formatDuration.
  • src/components/TelemetryChart.tsx: one series-wide scale factor applied consistently to the plotted line, Y-axis unit, gauge range (round-tripped to base units on edit), and numeric readout.

Testing

  • tsc --noEmit: 0 errors
  • ESLint: 0 errors
  • Vitest (full suite): 5767 passed. Pre-existing MQTT/protobuf suite failures on main are unrelated and unaffected (verified by reproducing them on a clean base with these changes stashed).

🤖 Generated with Claude Code

…3261)

Sub-1 readings rendered as unreadable "0.01 A" / "0.00 W" and uptime showed
raw seconds. Add a shared display helper that rescales current (A<->mA) and
power (mW<->W<->kW) by magnitude, and renders uptime as a human-readable
duration.

- src/utils/telemetryFormat.ts: unitScale/scaleMeasurement, isUptimeType,
  formatDuration (+ unit tests)
- UnifiedTelemetryPage: per-row scaling + duration uptime in the fleet table
- TelemetryChart: one series-wide scale factor shared across the chart axis,
  gauge range (round-tripped on edit) and numeric readout

Fixes both Meshtastic (mA / envCurrent) and MeshCore LPP telemetry
(current=A, power=W, mc_*_uptime_secs).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 30, 2026

Claude finished @Yeraze's task —— View job


PR Review: Telemetry Unit Auto-scaling and Uptime Humanization ✅

I've thoroughly reviewed this pull request. Here's my comprehensive assessment:

Review Progress

  • Analyze new utility files (telemetryFormat.ts)
  • Review test coverage and quality (telemetryFormat.test.ts)
  • Examine component integrations (TelemetryChart.tsx, UnifiedTelemetryPage.tsx)
  • Check for potential issues and provide feedback

Code Quality Assessment

Excellent Implementation Quality

  • Clean separation of concerns: The new telemetryFormat.ts utility properly encapsulates formatting logic
  • Well-documented code: Comprehensive JSDoc comments explaining the scaling logic and design decisions
  • Type safety: Proper TypeScript interfaces with clear parameter documentation
  • Consistent code style: Follows existing project conventions and formatting

Robust Algorithm Design

  • Magnitude-driven scaling: Smart approach using representative magnitude to choose appropriate SI prefixes
  • Family-based unit grouping: Clean mapping of related units (mA/A for current, mW/W/kW for power)
  • Edge case handling: Proper handling of non-finite values, zero magnitudes, and non-scalable units
  • Prefix boundary logic: Correct implementation ensuring displayed values stay ≥ 1 in chosen units

Comprehensive Test Coverage

29 well-designed test cases covering:

  • Boundary conditions: Zero values, negative values, edge cases at prefix boundaries
  • Unit conversion accuracy: Precise floating-point assertions using toBeCloseTo()
  • Non-scalable units: Verification that voltage, temperature, etc. remain unchanged
  • Duration formatting: Complete coverage of time unit combinations
  • Uptime type detection: Both explicit types and regex patterns (*_uptime_secs)

Integration Quality

Excellent Component Integration

  • TelemetryChart.tsx (src/components/TelemetryChart.tsx:540-546):

    • Smart series-wide scaling using maximum absolute value ensures consistent axis labeling
    • Proper separation of temperature handling (retains existing C/F logic) vs. auto-scaling
    • Clean conversion between display and storage units for gauge ranges
  • UnifiedTelemetryPage.tsx (src/pages/UnifiedTelemetryPage.tsx:495-503):

    • Per-row auto-scaling for current/power values in the telemetry table
    • Uptime values correctly rendered as durations without unit suffixes
    • Maintains existing temperature unit preferences

Performance Considerations

Efficient Implementation

  • Minimal computational overhead: Simple arithmetic operations and lookups
  • No unnecessary allocations: Direct calculations without intermediate objects
  • Memoization-friendly: Pure functions with predictable outputs suitable for React optimization

Security Assessment

No Security Concerns

  • Input validation: Proper handling of non-finite numbers and edge cases
  • No external dependencies: Uses only standard JavaScript math operations
  • Safe type coercion: Appropriate use of Number.isFinite() for validation

Potential Issues & Recommendations

⚠️ Minor Considerations

  1. Unit extensibility: The current UNIT_FAMILIES is hardcoded. Consider if future units (µA, GW, etc.) will need easy addition
  2. Precision preservation: The implementation correctly handles precision, but consider documenting floating-point behavior for very small/large values
  3. Performance optimization: For high-frequency updates, consider caching scale calculations if the same unit/magnitude pairs are repeated

📝 Documentation Suggestions

  • Consider adding usage examples in the JSDoc comments
  • The scaling algorithm explanation is excellent - consider preserving this knowledge in architectural docs

Testing Quality

Exceptional Test Suite

  • Complete boundary testing: Zero, negative, and edge values
  • Precision handling: Proper use of toBeCloseTo() for floating-point comparisons
  • Comprehensive uptime detection: Both named types and pattern matching
  • Duration formatting edge cases: Negative values, various time combinations

Best Practices Adherence

Follows Project Standards

  • Repository guidelines: Adheres to CLAUDE.md conventions
  • Multi-source architecture: Properly integrated without affecting source scoping
  • Database neutrality: No database-specific code, pure utility functions
  • Type safety: Full TypeScript coverage with proper interfaces

Final Assessment

This is a high-quality implementation that addresses the readability issues described in issue #3261. The code is well-architected, thoroughly tested, and properly integrated. The magnitude-driven scaling approach is elegant and the comprehensive test coverage provides confidence in correctness.

Summary

  • Code Quality: Excellent
  • Test Coverage: Comprehensive (29 tests)
  • Performance: Efficient
  • Security: No concerns
  • Integration: Clean and well-designed
  • Best Practices: Fully compliant

Recommendation: Approve and merge - This PR successfully solves the telemetry readability problem with a robust, well-tested solution.

@Yeraze Yeraze merged commit 45f686c into main May 30, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEAT] Telemetri Meshcore

1 participant