Change polling interval to retrieve BusiLight status (#3)
Implement a more agressive polling interval to retrieve BusiLight status. From (in sec.): ``` - min: 0 - max: 60 - default: 5 - divisions: 12 ``` to (in sec.): ``` - min: 0 - max: 2 - default: 1 - divisions: 4 ``` Reviewed-on: #3
This commit was merged in pull request #3.
This commit is contained in:
@@ -10,7 +10,7 @@ import '../services/busylight_service.dart';
|
||||
const _kHostKey = 'busylight_host';
|
||||
const _kDefaultHost = 'http://igox-busylight.local';
|
||||
const _kPollIntervalKey = 'busylight_poll_interval';
|
||||
const _kDefaultPollInterval = 5; // seconds
|
||||
const _kDefaultPollInterval = 1.0; // seconds
|
||||
|
||||
final sharedPreferencesProvider = FutureProvider<SharedPreferences>(
|
||||
(_) => SharedPreferences.getInstance(),
|
||||
@@ -21,9 +21,9 @@ final deviceHostProvider = StateProvider<String>((ref) {
|
||||
return prefs?.getString(_kHostKey) ?? _kDefaultHost;
|
||||
});
|
||||
|
||||
final pollIntervalProvider = StateProvider<int>((ref) {
|
||||
final pollIntervalProvider = StateProvider<double>((ref) {
|
||||
final prefs = ref.watch(sharedPreferencesProvider).valueOrNull;
|
||||
return prefs?.getInt(_kPollIntervalKey) ?? _kDefaultPollInterval;
|
||||
return prefs?.getDouble(_kPollIntervalKey) ?? _kDefaultPollInterval.toDouble();
|
||||
});
|
||||
|
||||
// ── Service ──────────────────────────────────────────────────────────────────
|
||||
@@ -161,10 +161,11 @@ class PollingNotifier extends StateNotifier<void> {
|
||||
Timer? _timer;
|
||||
|
||||
void _start() {
|
||||
final interval = _ref.read(pollIntervalProvider);
|
||||
final intervalSeconds = _ref.read(pollIntervalProvider);
|
||||
final intervalMillis = (intervalSeconds * 1000).toInt();
|
||||
_timer?.cancel();
|
||||
if (interval <= 0) return;
|
||||
_timer = Timer.periodic(Duration(seconds: interval), (_) => _poll());
|
||||
if (intervalMillis <= 0) return;
|
||||
_timer = Timer.periodic(Duration(milliseconds: intervalMillis), (_) => _poll());
|
||||
}
|
||||
|
||||
void restart() => _start();
|
||||
|
||||
Reference in New Issue
Block a user