fix(location): guard frequency timer minimum and filter zero options

Prevent position polling timer from firing with frequency < 60s (protects
against 0s values that saturate the API). Also filter out 0 from location
capability options in the frequency selector.
This commit is contained in:
2026-04-17 17:11:01 +02:00
parent e7ebe7f403
commit f5350f5e78

View File

@@ -87,9 +87,12 @@ class _LocationMapState extends ConsumerState<LocationMap>
_startMonitoring();
}
static const _minFrequency = 60;
void _startMonitoring() {
_followTimer?.cancel();
final frequency = widget.selectedDevice?.settings.frequency ?? 60;
final raw = widget.selectedDevice?.settings.frequency ?? 60;
final frequency = raw < _minFrequency ? _minFrequency : raw;
_followTimer = Timer.periodic(Duration(seconds: frequency), (_) {
if (ref.read(selectedDeviceProvider).value?.isDisconnected ?? true) return;
widget.onRefreshPosition();
@@ -244,7 +247,8 @@ class _LocationMapState extends ConsumerState<LocationMap>
if (!mounted) return;
if (success) {
_followTimer?.cancel();
_followTimer = Timer.periodic(Duration(seconds: frequency), (_) {
final safeFrequency = frequency < _minFrequency ? _minFrequency : frequency;
_followTimer = Timer.periodic(Duration(seconds: safeFrequency), (_) {
widget.onRefreshPosition();
});
showTopSnackbar(
@@ -642,7 +646,9 @@ class _LocationMapState extends ConsumerState<LocationMap>
FrequencySelector(
currentFrequency:
ref.watch(selectedDeviceProvider).value?.settings.frequency ?? 60,
options: widget.selectedDevice!.capabilities!.location!.options,
options: widget.selectedDevice!.capabilities!.location!.options
.where((o) => o > 0)
.toList(),
onChanged: _updateFrequency,
),
],