Fix for update before Webhook ID (re-)created.

This commit is contained in:
Philip Abbey
2025-08-15 17:04:54 +01:00
parent 756647d156
commit 7d77a79ad8
2 changed files with 40 additions and 19 deletions

View File

@@ -311,7 +311,7 @@ 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 (!Settings.getWebhookId().equals("")) { if (!Settings.getWebhookId().equals("") && !Settings.getClearWebhookId()) {
startUpdates(); startUpdates();
} // If not, this will be done via a chain in Settings.webhook() and mWebhookManager.requestWebhookId() that registers the sensors. } // If not, this will be done via a chain in Settings.webhook() and mWebhookManager.requestWebhookId() that registers the sensors.
} }
@@ -399,20 +399,25 @@ class HomeAssistantApp extends Application.AppBase {
case 200: case 200:
status = WatchUi.loadResource($.Rez.Strings.Available) as Lang.String; status = WatchUi.loadResource($.Rez.Strings.Available) as Lang.String;
// System.println("mItemsToUpdate: " + mItemsToUpdate); // System.println("mItemsToUpdate: " + mItemsToUpdate);
if (mItemsToUpdate != null) { if (data == null) {
for (var i = 0; i < mItemsToUpdate.size(); i++) { // Simulation and real device behave differently, hence 2nd NoJson error message for "data == null".
var item = mItemsToUpdate[i]; ErrorView.show(WatchUi.loadResource($.Rez.Strings.NoJson) as Lang.String);
var state = data.get(i.toString()); } else {
item.updateState(state); if (mItemsToUpdate != null) {
if (item instanceof HomeAssistantToggleMenuItem) { for (var i = 0; i < mItemsToUpdate.size(); i++) {
(item as HomeAssistantToggleMenuItem).updateToggleState(data.get(i.toString() + "t")); var item = mItemsToUpdate[i];
var state = data.get(i.toString());
item.updateState(state);
if (item instanceof HomeAssistantToggleMenuItem) {
(item as HomeAssistantToggleMenuItem).updateToggleState(data.get(i.toString() + "t"));
}
}
var delay = Settings.getPollDelay();
if (delay > 0) {
mUpdateTimer.start(method(:updateMenuItems), delay, false);
} else {
updateMenuItems();
} }
}
var delay = Settings.getPollDelay();
if (delay > 0) {
mUpdateTimer.start(method(:updateMenuItems), delay, false);
} else {
updateMenuItems();
} }
} }
break; break;
@@ -816,7 +821,7 @@ class HomeAssistantApp extends Application.AppBase {
mGlanceTimer = null; mGlanceTimer = null;
fetchMenuConfig(); fetchMenuConfig();
fetchApiStatus(); fetchApiStatus();
if (Settings.getWebhookId() != null && !Settings.getWebhookId().equals("")) { if (!Settings.getWebhookId().equals("") && !Settings.getClearWebhookId()) {
fetchGlanceContent(); fetchGlanceContent();
} }
} }

View File

@@ -141,7 +141,11 @@ class Settings {
//! @return The API Key //! @return The API Key
// //
static function getApiKey() as Lang.String { static function getApiKey() as Lang.String {
return mApiKey; if (mApiKey == null) {
return "";
} else {
return mApiKey;
}
} }
//! Get the Webhook ID supplied as part of the Settings. //! Get the Webhook ID supplied as part of the Settings.
@@ -149,7 +153,11 @@ class Settings {
//! @return The Webhook ID //! @return The Webhook ID
// //
static function getWebhookId() as Lang.String { static function getWebhookId() as Lang.String {
return mWebhookId; if (mWebhookId == null) {
return "";
} else {
return mWebhookId;
}
} }
//! Set the Webhook ID supplied as part of the Settings. //! Set the Webhook ID supplied as part of the Settings.
@@ -173,7 +181,11 @@ class Settings {
//! @return The API URL //! @return The API URL
// //
static function getApiUrl() as Lang.String { static function getApiUrl() as Lang.String {
return mApiUrl; if (mApiUrl == null) {
return "";
} else {
return mApiUrl;
}
} }
//! Get the menu configuration URL supplied as part of the Settings. //! Get the menu configuration URL supplied as part of the Settings.
@@ -181,7 +193,11 @@ class Settings {
//! @return The menu configuration URL //! @return The menu configuration URL
// //
static function getConfigUrl() as Lang.String { static function getConfigUrl() as Lang.String {
return mConfigUrl; if (mConfigUrl == null) {
return "";
} else {
return mConfigUrl;
}
} }
//! Get the menu cache Boolean option supplied as part of the Settings. //! Get the menu cache Boolean option supplied as part of the Settings.