Amended Globals.mc

Moved wifiPollDelayMs to Globals class.
This commit is contained in:
Philip Abbey
2025-07-25 08:38:55 +01:00
parent 0d73de494e
commit d110826392
5 changed files with 18 additions and 16 deletions

View File

@ -137,7 +137,7 @@ class ErrorView extends ScalableView {
// The call to 'updateMenuItems()' must be on another thread so that the view is popped above.
var myTimer = new Timer.Timer();
// Now this feels very "closely coupled" to the application, but it is the most reliable method instead of using a timer.
myTimer.start(getApp().method(:updateMenuItems), Globals.scApiResume, false);
myTimer.start(getApp().method(:updateMenuItems), Globals.scApiResumeMs, false);
// This must be last to avoid a race condition with show(), where the
// ErrorView can't be dismissed.
mShown = false;

View File

@ -21,15 +21,15 @@ using Toybox.Lang;
class Globals {
//! Alert is a toast at the top of the watch screen, it stays present until tapped
//! or this timeout has expired.
static const scAlertTimeout = 2000; // ms
static const scAlertTimeoutMs = 2000; // ms
//! Time to let the existing HTTP responses get serviced after a
//! `Communications.NETWORK_RESPONSE_OUT_OF_MEMORY` response code.
static const scApiBackoff = 2000; // ms
static const scApiBackoffMs = 2000; // ms
//! Needs to be long enough to enable a "double ESC" to quit the application from
//! an ErrorView.
static const scApiResume = 200; // ms
static const scApiResumeMs = 200; // ms
//! Warn the user after fetching the menu if their watch is low on memory before the device crashes.
static const scLowMem = 0.90; // percent as a fraction.
@ -45,4 +45,8 @@ class Globals {
//! Constant for PIN confirmation dialog.<br>
//! Lock out time in minutes after a failed PIN entry.
static const scPinLockTimeMinutes = 10;
//! After running a task by Wi-Fi/LTE synchronisation the periodic updates need to resume. This
//! is the delay between synchronisation completion and resumption of updates.
static const wifiPollResumeDelayMs = 2000; // ms
}

View File

@ -42,8 +42,6 @@ class HomeAssistantApp extends Application.AppBase {
private var mTemplates as Lang.Dictionary = {};
private var mNotifiedNoBle as Lang.Boolean = false;
private const wifiPollDelayMs = 2000;
//! Class Constructor
//
function initialize() {
@ -385,7 +383,7 @@ class HomeAssistantApp extends Application.AppBase {
// System.println("HomeAssistantApp onReturnUpdateMenuItems() Response Code: NETWORK_RESPONSE_OUT_OF_MEMORY, are we going too fast?");
var myTimer = new Timer.Timer();
// Now this feels very "closely coupled" to the application, but it is the most reliable method instead of using a timer.
myTimer.start(method(:updateMenuItems), Globals.scApiBackoff, false);
myTimer.start(method(:updateMenuItems), Globals.scApiBackoffMs, false);
// Revert status
status = getApiStatus();
break;
@ -447,7 +445,7 @@ class HomeAssistantApp extends Application.AppBase {
WatchUi.showToast(toast, null);
} else {
new Alert({
:timeout => Globals.scAlertTimeout,
:timeout => Globals.scAlertTimeoutMs,
:font => Graphics.FONT_MEDIUM,
:text => toast,
:fgcolor => Graphics.COLOR_WHITE,
@ -458,7 +456,7 @@ class HomeAssistantApp extends Application.AppBase {
mNotifiedNoBle = true;
setApiStatus(WatchUi.loadResource($.Rez.Strings.Unavailable) as Lang.String);
mUpdateTimer.start(method(:startUpdates), wifiPollDelayMs, false);
mUpdateTimer.start(method(:startUpdates), Globals.wifiPollResumeDelayMs, false);
mUpdating = false;
return;
@ -807,7 +805,7 @@ class HomeAssistantApp extends Application.AppBase {
Settings.update();
updateStatus();
mGlanceTimer = new Timer.Timer();
mGlanceTimer.start(method(:updateStatus), Globals.scApiBackoff, true);
mGlanceTimer.start(method(:updateStatus), Globals.scApiBackoffMs, true);
return [new HomeAssistantGlanceView(self)];
}

View File

@ -100,7 +100,7 @@ class HomeAssistantService {
WatchUi.showToast(toast, null);
} else {
new Alert({
:timeout => Globals.scAlertTimeout,
:timeout => Globals.scAlertTimeoutMs,
:font => Graphics.FONT_MEDIUM,
:text => toast,
:fgcolor => Graphics.COLOR_WHITE,

View File

@ -136,7 +136,7 @@ class WifiLteExecutionConfirmDelegate extends WatchUi.ConfirmationDelegate {
WatchUi.showToast(toast, null);
} else {
new Alert({
:timeout => Globals.scAlertTimeout,
:timeout => Globals.scAlertTimeoutMs,
:font => Graphics.FONT_MEDIUM,
:text => toast,
:fgcolor => Graphics.COLOR_WHITE,