mirror of
https://github.com/house-of-abbey/GarminHomeAssistant.git
synced 2025-09-15 05:21:33 +00:00
2 Bug fixes
1. Fixed a bug where templates failed to display in toggle menu items (at least on some devices). 2. Fixed a bug where a menu item requesting to exit on completion appeared to indicate failure when using Wi-Fi or LTE. The fix uses a delay in exiting the application modelled as sufficient for a Venu 2 device, so this might need tweaking for other devices.
This commit is contained in:
@@ -49,4 +49,9 @@ class Globals {
|
||||
//! 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
|
||||
|
||||
//! After running a task by Wi-Fi/LTE synchronisation the if the menu item requests to quit the
|
||||
//! application, this is the delay to wait after synchronisation completion before quitting.
|
||||
//! Failure to wait causes the transfer to indicate a failure.
|
||||
static const wifiQuitDelayMs = 5000; // ms
|
||||
}
|
||||
|
@@ -482,6 +482,8 @@ class HomeAssistantApp extends Application.AppBase {
|
||||
break;
|
||||
|
||||
case Communications.NETWORK_RESPONSE_OUT_OF_MEMORY:
|
||||
// As we're out of memory, pretend we've checked and don't try again.
|
||||
mIsCacheChecked = true;
|
||||
// System.println("HomeAssistantApp onReturnCheckMenuConfig() 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.
|
||||
|
@@ -21,7 +21,7 @@ using Toybox.Lang;
|
||||
//
|
||||
class HomeAssistantSyncDelegate extends Communications.SyncDelegate {
|
||||
//! Retain the last synchronisation error.
|
||||
private static var syncError as Lang.String?;
|
||||
private static var mSyncError as Lang.String?;
|
||||
|
||||
//! Class Constructor
|
||||
//
|
||||
@@ -38,9 +38,9 @@ class HomeAssistantSyncDelegate extends Communications.SyncDelegate {
|
||||
//! Called by the system when starting a bulk synchronisation.
|
||||
//
|
||||
public function onStartSync() as Void {
|
||||
syncError = null;
|
||||
mSyncError = null;
|
||||
if (WifiLteExecutionConfirmDelegate.mCommandData == null) {
|
||||
syncError = WatchUi.loadResource($.Rez.Strings.WifiLteExecutionDataError) as Lang.String;
|
||||
mSyncError = WatchUi.loadResource($.Rez.Strings.WifiLteExecutionDataError) as Lang.String;
|
||||
onStopSync();
|
||||
return;
|
||||
}
|
||||
@@ -98,42 +98,48 @@ class HomeAssistantSyncDelegate extends Communications.SyncDelegate {
|
||||
//
|
||||
public function haCallback(code as Lang.Number, data as Lang.Dictionary?) as Void {
|
||||
Communications.notifySyncProgress(100);
|
||||
if (code == 200) {
|
||||
syncError = null;
|
||||
if (WifiLteExecutionConfirmDelegate.mCommandData[:type].equals("entity")) {
|
||||
var callbackMethod = WifiLteExecutionConfirmDelegate.mCommandData[:callback];
|
||||
if (callbackMethod != null) {
|
||||
var d = data as Lang.Array;
|
||||
callbackMethod.invoke(d);
|
||||
}
|
||||
}
|
||||
onStopSync();
|
||||
return;
|
||||
}
|
||||
|
||||
switch(code) {
|
||||
case Communications.NETWORK_REQUEST_TIMED_OUT:
|
||||
syncError = WatchUi.loadResource($.Rez.Strings.TimedOut) as Lang.String;
|
||||
mSyncError = WatchUi.loadResource($.Rez.Strings.TimedOut);
|
||||
break;
|
||||
case Communications.NETWORK_RESPONSE_OUT_OF_MEMORY:
|
||||
case Communications.INVALID_HTTP_BODY_IN_NETWORK_RESPONSE:
|
||||
syncError = WatchUi.loadResource($.Rez.Strings.NoJson) as Lang.String;
|
||||
syncError = "";
|
||||
mSyncError = WatchUi.loadResource($.Rez.Strings.PotentialError);
|
||||
break;
|
||||
case 404:
|
||||
mSyncError = WatchUi.loadResource($.Rez.Strings.ApiUrlNotFound);
|
||||
break;
|
||||
case 200:
|
||||
mSyncError = null;
|
||||
if (WifiLteExecutionConfirmDelegate.mCommandData[:type].equals("entity")) {
|
||||
var callbackMethod = WifiLteExecutionConfirmDelegate.mCommandData[:callback];
|
||||
if (callbackMethod != null) {
|
||||
callbackMethod.invoke(data as Lang.Array);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
var codeMsg = WatchUi.loadResource($.Rez.Strings.UnhandledHttpErr) as Lang.String;
|
||||
syncError = codeMsg + code;
|
||||
mSyncError = WatchUi.loadResource($.Rez.Strings.UnhandledHttpErr) + code;
|
||||
break;
|
||||
}
|
||||
|
||||
onStopSync();
|
||||
}
|
||||
|
||||
//! Clean up
|
||||
//
|
||||
public function onStopSync() as Void {
|
||||
if (WifiLteExecutionConfirmDelegate.mCommandData[:exit]) {
|
||||
System.exit();
|
||||
}
|
||||
Communications.notifySyncComplete(mSyncError);
|
||||
Communications.cancelAllRequests();
|
||||
Communications.notifySyncComplete(syncError);
|
||||
// Need to delay the exit here or the transfer shows as failed (and it might not be).
|
||||
if (WifiLteExecutionConfirmDelegate.mCommandData[:exit]) {
|
||||
var myTimer = new Timer.Timer();
|
||||
myTimer.start(method(:exit), Globals.wifiQuitDelayMs, false);
|
||||
}
|
||||
}
|
||||
|
||||
//! Required for `method(:exit)` to be able to find a method at all.
|
||||
//
|
||||
public function exit() as Void {
|
||||
System.exit();
|
||||
}
|
||||
}
|
||||
|
@@ -104,7 +104,11 @@ class HomeAssistantToggleMenuItem extends WatchUi.ToggleMenuItem {
|
||||
if (data == null) {
|
||||
setSubLabel(null);
|
||||
} else if(data instanceof Lang.String) {
|
||||
setSubLabel(data);
|
||||
// Need to set both labels, you can't just 'setSubLabel(data)' or nothing displays.
|
||||
setSubLabel({
|
||||
:enabled => data,
|
||||
:disabled => data
|
||||
});
|
||||
} else if(data instanceof Lang.Number) {
|
||||
var d = data as Lang.Number;
|
||||
setSubLabel(d.format("%d"));
|
||||
|
Reference in New Issue
Block a user