mirror of
https://github.com/house-of-abbey/GarminHomeAssistant.git
synced 2025-06-16 11:28:40 +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 mIsApp as Lang.Boolean = false; // Or Widget
|
||||||
private var mUpdating as Lang.Boolean = false; // Don't start a second chain of updates
|
private var mUpdating as Lang.Boolean = false; // Don't start a second chain of updates
|
||||||
private var mTemplates as Lang.Dictionary = {};
|
private var mTemplates as Lang.Dictionary = {};
|
||||||
private var startUpdating as Lang.Boolean = false;
|
|
||||||
|
|
||||||
function initialize() {
|
function initialize() {
|
||||||
AppBase.initialize();
|
AppBase.initialize();
|
||||||
@ -120,12 +119,16 @@ class HomeAssistantApp extends Application.AppBase {
|
|||||||
return ErrorView.create(WatchUi.loadResource($.Rez.Strings.NoInternet) as Lang.String);
|
return ErrorView.create(WatchUi.loadResource($.Rez.Strings.NoInternet) as Lang.String);
|
||||||
} else {
|
} else {
|
||||||
var isCached = fetchMenuConfig();
|
var isCached = fetchMenuConfig();
|
||||||
|
var ret = null;
|
||||||
fetchApiStatus();
|
fetchApiStatus();
|
||||||
if (isCached) {
|
if (isCached) {
|
||||||
return [mHaMenu, new HomeAssistantViewDelegate(true)];
|
ret = [mHaMenu, new HomeAssistantViewDelegate(true)];
|
||||||
} else {
|
} 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) {
|
private function buildMenu(menu as Lang.Dictionary) {
|
||||||
mHaMenu = new HomeAssistantView(menu, null);
|
mHaMenu = new HomeAssistantView(menu, null);
|
||||||
mQuitTimer.begin();
|
mQuitTimer.begin();
|
||||||
if (startUpdating) {
|
startUpdates();
|
||||||
startUpdates();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function startUpdates() {
|
function startUpdates() {
|
||||||
if (mHaMenu != null and !mUpdating) {
|
if (mHaMenu != null and !mUpdating) {
|
||||||
// Start the continuous update process that continues for as long as the application is running.
|
// Start the continuous update process that continues for as long as the application is running.
|
||||||
updateMenuItems();
|
updateMenuItems();
|
||||||
|
mUpdating = true;
|
||||||
}
|
}
|
||||||
startUpdating = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function onReturnUpdateMenuItems(responseCode as Lang.Number, data as Null or Lang.Dictionary) as Void {
|
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");
|
mMenuAlignment = Properties.getValue("menu_alignment");
|
||||||
mIsSensorsLevelEnabled = Properties.getValue("enable_battery_level");
|
mIsSensorsLevelEnabled = Properties.getValue("enable_battery_level");
|
||||||
mBatteryRefreshRate = Properties.getValue("battery_level_refresh_rate");
|
mBatteryRefreshRate = Properties.getValue("battery_level_refresh_rate");
|
||||||
|
}
|
||||||
|
|
||||||
|
static function webhook() {
|
||||||
if (System has :ServiceDelegate) {
|
if (System has :ServiceDelegate) {
|
||||||
mHasService = true;
|
mHasService = true;
|
||||||
}
|
}
|
||||||
@ -106,13 +108,13 @@ class Settings {
|
|||||||
unsetWebhookId();
|
unsetWebhookId();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// System.println("Settings update(): getTemporalEventRegisteredTime() = " + Background.getTemporalEventRegisteredTime());
|
// System.println("Settings webhook(): getTemporalEventRegisteredTime() = " + Background.getTemporalEventRegisteredTime());
|
||||||
// if (Background.getTemporalEventRegisteredTime() != null) {
|
// 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 {
|
// } else {
|
||||||
// System.println("Settings update(): getTemporalEventRegisteredTime() = null");
|
// System.println("Settings webhook(): getTemporalEventRegisteredTime() = null");
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
static function getApiKey() as Lang.String {
|
static function getApiKey() as Lang.String {
|
||||||
return mApiKey;
|
return mApiKey;
|
||||||
|
Reference in New Issue
Block a user