mirror of
https://github.com/house-of-abbey/GarminHomeAssistant.git
synced 2025-06-17 03:48:32 +00:00
3 bug fixes as per the issue description
This commit is contained in:
@ -173,16 +173,24 @@ class HomeAssistantApp extends Application.AppBase {
|
||||
break;
|
||||
|
||||
case 200:
|
||||
if (Settings.getCacheConfig()) {
|
||||
Storage.setValue("menu", data as Lang.Dictionary);
|
||||
mMenuStatus = WatchUi.loadResource($.Rez.Strings.Cached) as Lang.String;
|
||||
if (data == null) {
|
||||
mMenuStatus = WatchUi.loadResource($.Rez.Strings.Unavailable) as Lang.String;
|
||||
} else {
|
||||
mMenuStatus = WatchUi.loadResource($.Rez.Strings.Available) as Lang.String;
|
||||
if (Settings.getCacheConfig()) {
|
||||
Storage.setValue("menu", data as Lang.Dictionary);
|
||||
mMenuStatus = WatchUi.loadResource($.Rez.Strings.Cached) as Lang.String;
|
||||
} else {
|
||||
mMenuStatus = WatchUi.loadResource($.Rez.Strings.Available) as Lang.String;
|
||||
}
|
||||
}
|
||||
if (!mIsGlance) {
|
||||
buildMenu(data);
|
||||
if (!WidgetApp.isWidget) {
|
||||
WatchUi.switchToView(mHaMenu, new HomeAssistantViewDelegate(false), WatchUi.SLIDE_IMMEDIATE);
|
||||
if (data == null) {
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.NoJson) as Lang.String);
|
||||
} else {
|
||||
buildMenu(data);
|
||||
if (!WidgetApp.isWidget) {
|
||||
WatchUi.switchToView(mHaMenu, new HomeAssistantViewDelegate(false), WatchUi.SLIDE_IMMEDIATE);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -401,14 +409,11 @@ class HomeAssistantApp extends Application.AppBase {
|
||||
// (-101) error. This function is called by a timer every Globals.menuItemUpdateInterval ms.
|
||||
function updateNextMenuItem() as Void {
|
||||
var itu = mItemsToUpdate as Lang.Array<HomeAssistantToggleMenuItem>;
|
||||
if (itu == null) {
|
||||
// System.println("HomeAssistantApp updateNextMenuItem(): No menu items to update");
|
||||
if (!mIsGlance) {
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.ConfigUrlNotFound) as Lang.String);
|
||||
}
|
||||
} else {
|
||||
if (itu != null) {
|
||||
itu[mNextItemToUpdate].getState();
|
||||
mNextItemToUpdate = (mNextItemToUpdate + 1) % itu.size();
|
||||
// } else {
|
||||
// System.println("HomeAssistantApp updateNextMenuItem(): No menu items to update");
|
||||
}
|
||||
}
|
||||
|
||||
@ -417,8 +422,7 @@ class HomeAssistantApp extends Application.AppBase {
|
||||
}
|
||||
|
||||
function getGlanceView() as Lang.Array<WatchUi.GlanceView or WatchUi.GlanceViewDelegate> or Null {
|
||||
mIsGlance = true;
|
||||
// RezStrings.update_glance();
|
||||
mIsGlance = true;
|
||||
mApiStatus = WatchUi.loadResource($.Rez.Strings.Checking) as Lang.String;
|
||||
mMenuStatus = WatchUi.loadResource($.Rez.Strings.Checking) as Lang.String;
|
||||
updateStatus();
|
||||
|
@ -41,38 +41,40 @@ class HomeAssistantView extends WatchUi.Menu2 {
|
||||
}
|
||||
WatchUi.Menu2.initialize(options);
|
||||
|
||||
var items = definition.get("items") as Lang.Dictionary;
|
||||
for(var i = 0; i < items.size(); i++) {
|
||||
var type = items[i].get("type") as Lang.String or Null;
|
||||
var name = items[i].get("name") as Lang.String or Null;
|
||||
var content = items[i].get("content") as Lang.String or Null;
|
||||
var entity = items[i].get("entity") as Lang.String or Null;
|
||||
var tap_action = items[i].get("tap_action") as Lang.Dictionary or Null;
|
||||
var service = items[i].get("service") as Lang.String or Null; // Deprecated schema
|
||||
var confirm = false as Lang.Boolean or Null;
|
||||
var data = null as Lang.Dictionary or Null;
|
||||
if (tap_action != null) {
|
||||
service = tap_action.get("service");
|
||||
confirm = tap_action.get("confirm"); // Optional
|
||||
data = tap_action.get("data"); // Optional
|
||||
if (confirm == null) {
|
||||
confirm = false;
|
||||
}
|
||||
}
|
||||
if (type != null && name != null) {
|
||||
if (type.equals("toggle") && entity != null) {
|
||||
addItem(HomeAssistantMenuItemFactory.create().toggle(name, entity, confirm));
|
||||
} else if (type.equals("template") && content != null) {
|
||||
if (service == null) {
|
||||
addItem(HomeAssistantMenuItemFactory.create().template_notap(name, content));
|
||||
} else {
|
||||
addItem(HomeAssistantMenuItemFactory.create().template_tap(name, entity, content, service, confirm, data));
|
||||
var items = definition.get("items") as Lang.Array<Lang.Dictionary>;
|
||||
for (var i = 0; i < items.size(); i++) {
|
||||
if (items[i] instanceof(Lang.Dictionary)) {
|
||||
var type = items[i].get("type") as Lang.String or Null;
|
||||
var name = items[i].get("name") as Lang.String or Null;
|
||||
var content = items[i].get("content") as Lang.String or Null;
|
||||
var entity = items[i].get("entity") as Lang.String or Null;
|
||||
var tap_action = items[i].get("tap_action") as Lang.Dictionary or Null;
|
||||
var service = items[i].get("service") as Lang.String or Null; // Deprecated schema
|
||||
var confirm = false as Lang.Boolean or Null;
|
||||
var data = null as Lang.Dictionary or Null;
|
||||
if (tap_action != null) {
|
||||
service = tap_action.get("service");
|
||||
confirm = tap_action.get("confirm"); // Optional
|
||||
data = tap_action.get("data"); // Optional
|
||||
if (confirm == null) {
|
||||
confirm = false;
|
||||
}
|
||||
}
|
||||
if (type != null && name != null) {
|
||||
if (type.equals("toggle") && entity != null) {
|
||||
addItem(HomeAssistantMenuItemFactory.create().toggle(name, entity, confirm));
|
||||
} else if (type.equals("template") && content != null) {
|
||||
if (service == null) {
|
||||
addItem(HomeAssistantMenuItemFactory.create().template_notap(name, content));
|
||||
} else {
|
||||
addItem(HomeAssistantMenuItemFactory.create().template_tap(name, entity, content, service, confirm, data));
|
||||
}
|
||||
|
||||
} else if (type.equals("tap") && service != null) {
|
||||
addItem(HomeAssistantMenuItemFactory.create().tap(name, entity, service, confirm, data));
|
||||
} else if (type.equals("group")) {
|
||||
addItem(HomeAssistantMenuItemFactory.create().group(items[i]));
|
||||
} else if (type.equals("tap") && service != null) {
|
||||
addItem(HomeAssistantMenuItemFactory.create().tap(name, entity, service, confirm, data));
|
||||
} else if (type.equals("group")) {
|
||||
addItem(HomeAssistantMenuItemFactory.create().group(items[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -67,22 +67,19 @@ class Settings {
|
||||
|
||||
// Manage this inside the application or widget only (not a glance or background service process)
|
||||
if (mIsApp) {
|
||||
if (mIsBatteryLevelEnabled) {
|
||||
if (mIsBatteryLevelEnabled and mHasService) {
|
||||
if (getWebhookId().equals("")) {
|
||||
mWebhookManager = new WebhookManager();
|
||||
mWebhookManager.requestWebhookId();
|
||||
} else if (
|
||||
mHasService and
|
||||
((Background.getTemporalEventRegisteredTime() == null) or
|
||||
(Background.getTemporalEventRegisteredTime() != (mBatteryRefreshRate * 60)))
|
||||
) {
|
||||
}
|
||||
if ((Background.getTemporalEventRegisteredTime() == null) or
|
||||
(Background.getTemporalEventRegisteredTime() != (mBatteryRefreshRate * 60))) {
|
||||
Background.registerForTemporalEvent(new Time.Duration(mBatteryRefreshRate * 60)); // Convert to seconds
|
||||
}
|
||||
} else {
|
||||
// Explicitly disable the background event which persists when the application closes.
|
||||
if (mHasService and (Background.getTemporalEventRegisteredTime() != null)) {
|
||||
Background.deleteTemporalEvent();
|
||||
}
|
||||
// If !mHasService disable the Settings option as user feedback
|
||||
unsetIsBatteryLevelEnabled();
|
||||
unsetWebhookId();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user