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. // The call to 'updateMenuItems()' must be on another thread so that the view is popped above.
var myTimer = new Timer.Timer(); 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. // 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 // This must be last to avoid a race condition with show(), where the
// ErrorView can't be dismissed. // ErrorView can't be dismissed.
mShown = false; mShown = false;

View File

@ -21,28 +21,32 @@ using Toybox.Lang;
class Globals { class Globals {
//! Alert is a toast at the top of the watch screen, it stays present until tapped //! Alert is a toast at the top of the watch screen, it stays present until tapped
//! or this timeout has expired. //! 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 //! Time to let the existing HTTP responses get serviced after a
//! `Communications.NETWORK_RESPONSE_OUT_OF_MEMORY` response code. //! `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 //! Needs to be long enough to enable a "double ESC" to quit the application from
//! an ErrorView. //! 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. //! 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. static const scLowMem = 0.90; // percent as a fraction.
//! Constant for PIN confirmation dialog.<br> //! Constant for PIN confirmation dialog.<br>
//! Maximum number of failed PIN confirmation attempts allowed in `scPinMaxFailureMinutes`. //! Maximum number of failed PIN confirmation attempts allowed in `scPinMaxFailureMinutes`.
static const scPinMaxFailures = 5; static const scPinMaxFailures = 5;
//! Constant for PIN confirmation dialog.<br> //! Constant for PIN confirmation dialog.<br>
//! Period in minutes during which no more than `scPinMaxFailures` PIN attempts are tolerated. //! Period in minutes during which no more than `scPinMaxFailures` PIN attempts are tolerated.
static const scPinMaxFailureMinutes = 2; static const scPinMaxFailureMinutes = 2;
//! Constant for PIN confirmation dialog.<br> //! Constant for PIN confirmation dialog.<br>
//! Lock out time in minutes after a failed PIN entry. //! Lock out time in minutes after a failed PIN entry.
static const scPinLockTimeMinutes = 10; 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 mTemplates as Lang.Dictionary = {};
private var mNotifiedNoBle as Lang.Boolean = false; private var mNotifiedNoBle as Lang.Boolean = false;
private const wifiPollDelayMs = 2000;
//! Class Constructor //! Class Constructor
// //
function initialize() { 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?"); // System.println("HomeAssistantApp onReturnUpdateMenuItems() Response Code: NETWORK_RESPONSE_OUT_OF_MEMORY, are we going too fast?");
var myTimer = new Timer.Timer(); 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. // 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 // Revert status
status = getApiStatus(); status = getApiStatus();
break; break;
@ -447,7 +445,7 @@ class HomeAssistantApp extends Application.AppBase {
WatchUi.showToast(toast, null); WatchUi.showToast(toast, null);
} else { } else {
new Alert({ new Alert({
:timeout => Globals.scAlertTimeout, :timeout => Globals.scAlertTimeoutMs,
:font => Graphics.FONT_MEDIUM, :font => Graphics.FONT_MEDIUM,
:text => toast, :text => toast,
:fgcolor => Graphics.COLOR_WHITE, :fgcolor => Graphics.COLOR_WHITE,
@ -458,7 +456,7 @@ class HomeAssistantApp extends Application.AppBase {
mNotifiedNoBle = true; mNotifiedNoBle = true;
setApiStatus(WatchUi.loadResource($.Rez.Strings.Unavailable) as Lang.String); setApiStatus(WatchUi.loadResource($.Rez.Strings.Unavailable) as Lang.String);
mUpdateTimer.start(method(:startUpdates), wifiPollDelayMs, false); mUpdateTimer.start(method(:startUpdates), Globals.wifiPollResumeDelayMs, false);
mUpdating = false; mUpdating = false;
return; return;
@ -807,7 +805,7 @@ class HomeAssistantApp extends Application.AppBase {
Settings.update(); Settings.update();
updateStatus(); updateStatus();
mGlanceTimer = new Timer.Timer(); mGlanceTimer = new Timer.Timer();
mGlanceTimer.start(method(:updateStatus), Globals.scApiBackoff, true); mGlanceTimer.start(method(:updateStatus), Globals.scApiBackoffMs, true);
return [new HomeAssistantGlanceView(self)]; return [new HomeAssistantGlanceView(self)];
} }

View File

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

View File

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