mirror of
https://github.com/house-of-abbey/GarminHomeAssistant.git
synced 2025-04-30 12:42:27 +00:00
Rearranging Web API Requests
Making sure the menu update API call is completed before the Webhook IDs are fetched in order to reduce latency to usefulness.
This commit is contained in:
@ -39,7 +39,6 @@ class HomeAssistantApp extends Application.AppBase {
|
||||
private var mIsApp as Lang.Boolean = false; // Or Widget
|
||||
private var mUpdating as Lang.Boolean = false; // Don't start a second chain of updates
|
||||
private var mTemplates as Lang.Dictionary = {};
|
||||
private var startUpdating as Lang.Boolean = false;
|
||||
|
||||
function initialize() {
|
||||
AppBase.initialize();
|
||||
@ -120,12 +119,16 @@ class HomeAssistantApp extends Application.AppBase {
|
||||
return ErrorView.create(WatchUi.loadResource($.Rez.Strings.NoInternet) as Lang.String);
|
||||
} else {
|
||||
var isCached = fetchMenuConfig();
|
||||
var ret = null;
|
||||
fetchApiStatus();
|
||||
if (isCached) {
|
||||
return [mHaMenu, new HomeAssistantViewDelegate(true)];
|
||||
ret = [mHaMenu, new HomeAssistantViewDelegate(true)];
|
||||
} else {
|
||||
return [new WatchUi.View(), new WatchUi.BehaviorDelegate()];
|
||||
ret = [new WatchUi.View(), new WatchUi.BehaviorDelegate()];
|
||||
}
|
||||
// Separated from Settings.update() in order to call after fetchMenuConfig() and not call it on changes settings.
|
||||
Settings.webhook();
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
@ -263,17 +266,15 @@ class HomeAssistantApp extends Application.AppBase {
|
||||
private function buildMenu(menu as Lang.Dictionary) {
|
||||
mHaMenu = new HomeAssistantView(menu, null);
|
||||
mQuitTimer.begin();
|
||||
if (startUpdating) {
|
||||
startUpdates();
|
||||
}
|
||||
startUpdates();
|
||||
}
|
||||
|
||||
function startUpdates() {
|
||||
if (mHaMenu != null and !mUpdating) {
|
||||
// Start the continuous update process that continues for as long as the application is running.
|
||||
updateMenuItems();
|
||||
mUpdating = true;
|
||||
}
|
||||
startUpdating = true;
|
||||
}
|
||||
|
||||
function onReturnUpdateMenuItems(responseCode as Lang.Number, data as Null or Lang.Dictionary) as Void {
|
||||
|
@ -69,7 +69,9 @@ class Settings {
|
||||
mMenuAlignment = Properties.getValue("menu_alignment");
|
||||
mIsSensorsLevelEnabled = Properties.getValue("enable_battery_level");
|
||||
mBatteryRefreshRate = Properties.getValue("battery_level_refresh_rate");
|
||||
}
|
||||
|
||||
static function webhook() {
|
||||
if (System has :ServiceDelegate) {
|
||||
mHasService = true;
|
||||
}
|
||||
@ -106,13 +108,13 @@ class Settings {
|
||||
unsetWebhookId();
|
||||
}
|
||||
}
|
||||
// System.println("Settings update(): getTemporalEventRegisteredTime() = " + Background.getTemporalEventRegisteredTime());
|
||||
// System.println("Settings webhook(): getTemporalEventRegisteredTime() = " + Background.getTemporalEventRegisteredTime());
|
||||
// if (Background.getTemporalEventRegisteredTime() != null) {
|
||||
// System.println("Settings update(): getTemporalEventRegisteredTime().value() = " + Background.getTemporalEventRegisteredTime().value().format("%d") + " seconds");
|
||||
// System.println("Settings webhook(): getTemporalEventRegisteredTime().value() = " + Background.getTemporalEventRegisteredTime().value().format("%d") + " seconds");
|
||||
// } else {
|
||||
// System.println("Settings update(): getTemporalEventRegisteredTime() = null");
|
||||
// System.println("Settings webhook(): getTemporalEventRegisteredTime() = null");
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
static function getApiKey() as Lang.String {
|
||||
return mApiKey;
|
||||
|
Reference in New Issue
Block a user