From e474168ba8a9f3de4fa78ec3bec4a052c0e91864 Mon Sep 17 00:00:00 2001 From: Janez T Date: Thu, 19 Mar 2026 13:52:15 +0100 Subject: [PATCH] feat: Show self telemetry in device info sheet Tapping signal/battery in header now also shows device's own telemetry (temperature, humidity, pressure, GPS) when available. Triggers a self telemetry request on sheet open. Data comes from the device contact's telemetry field. --- lib/providers/connection_provider.dart | 18 ++++++++++ lib/screens/home_screen.dart | 50 ++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) diff --git a/lib/providers/connection_provider.dart b/lib/providers/connection_provider.dart index 1ddf199..ea6a5fd 100644 --- a/lib/providers/connection_provider.dart +++ b/lib/providers/connection_provider.dart @@ -2363,6 +2363,24 @@ class ConnectionProvider with ChangeNotifier { /// - Total storage in KB (if available) /// /// Results arrive via onBatteryAndStorage callback and update deviceInfo. + /// Request the companion device's own telemetry (GPS, temp, sensors). + /// The response arrives via onTelemetryReceived with the device's own key. + Future requestSelfTelemetry() async { + if (!_activeService.isConnected) return; + try { + // Request own telemetry by sending telemetry req with zero-length key + final deviceKey = _deviceInfo.publicKey; + if (deviceKey != null) { + await _activeService.requestTelemetry( + Uint8List.fromList(deviceKey), + zeroHop: true, + ); + } + } catch (e) { + debugPrint('⚠️ [Provider] requestSelfTelemetry failed: $e'); + } + } + Future getBatteryAndStorage() async { if (!_activeService.isConnected) { _error = 'Not connected to device'; diff --git a/lib/screens/home_screen.dart b/lib/screens/home_screen.dart index 2c207f1..4e2d77a 100644 --- a/lib/screens/home_screen.dart +++ b/lib/screens/home_screen.dart @@ -8,6 +8,7 @@ import 'package:shared_preferences/shared_preferences.dart'; import 'package:vibration/vibration.dart'; import '../providers/connection_provider.dart'; import '../providers/app_provider.dart'; +import '../models/contact.dart'; import '../models/device_info.dart' show ConnectionMode, DeviceInfo; import '../providers/messages_provider.dart'; import '../providers/contacts_provider.dart'; @@ -435,6 +436,19 @@ class _HomeScreenState extends State } void _showDeviceInfoSheet(BuildContext context, DeviceInfo deviceInfo) { + // Request self telemetry so it's fresh + context.read().requestSelfTelemetry(); + + // Find the device's own contact to show self telemetry + final selfKey = deviceInfo.publicKey; + Contact? selfContact; + if (selfKey != null) { + selfContact = context.read().findContactByKey( + Uint8List.fromList(selfKey), + ); + } + final telemetry = selfContact?.telemetry; + showModalBottomSheet( context: context, shape: const RoundedRectangleBorder( @@ -513,6 +527,42 @@ class _HomeScreenState extends State 'TX Power', '${deviceInfo.txPower} dBm', ), + if (telemetry != null) ...[ + const Divider(height: 24), + Text( + 'Self Telemetry', + style: Theme.of(context).textTheme.titleSmall, + ), + const SizedBox(height: 8), + if (telemetry.temperature != null) + _deviceInfoRow( + context, + Icons.thermostat, + 'Temperature', + '${telemetry.temperature!.toStringAsFixed(1)}°C', + ), + if (telemetry.humidity != null) + _deviceInfoRow( + context, + Icons.water_drop, + 'Humidity', + '${telemetry.humidity!.toStringAsFixed(1)}%', + ), + if (telemetry.pressure != null) + _deviceInfoRow( + context, + Icons.compress, + 'Pressure', + '${telemetry.pressure!.toStringAsFixed(1)} hPa', + ), + if (telemetry.gpsLocation != null) + _deviceInfoRow( + context, + Icons.gps_fixed, + 'GPS', + '${telemetry.gpsLocation!.latitude.toStringAsFixed(5)}, ${telemetry.gpsLocation!.longitude.toStringAsFixed(5)}', + ), + ], ], ), ),