Added numeric Menu Item

This commit is contained in:
thmichel
2025-10-10 11:46:20 +02:00
parent cb382d820f
commit 52e2efddd8
9 changed files with 578 additions and 208 deletions

View File

@@ -126,6 +126,19 @@ class HomeAssistantView extends WatchUi.Menu2 {
}
));
}
} else if (type.equals("numeric") && service != null) {
addItem(HomeAssistantMenuItemFactory.create().numeric(
name,
entity,
content,
service,
data,
{
:exit => exit,
:confirm => confirm,
:pin => pin
}
));
} else if (type.equals("info") && content != null) {
// Cannot exit from a non-actionable information only menu item.
addItem(HomeAssistantMenuItemFactory.create().tap(
@@ -154,7 +167,8 @@ class HomeAssistantView extends WatchUi.Menu2 {
//!
//! @return An array of menu items that need to be updated periodically to reflect the latest Home Assistant state.
//
function getItemsToUpdate() as Lang.Array<HomeAssistantToggleMenuItem or HomeAssistantTapMenuItem or HomeAssistantGroupMenuItem or Null> {
function getItemsToUpdate() as Lang.Array<HomeAssistantToggleMenuItem or HomeAssistantTapMenuItem or HomeAssistantGroupMenuItem or HomeAssistantNumericMenuItem or Null> {
var fullList = [];
var lmi = mItems as Lang.Array<WatchUi.MenuItem>;
@@ -167,6 +181,12 @@ class HomeAssistantView extends WatchUi.Menu2 {
fullList.add(item);
}
fullList.addAll(item.getMenuView().getItemsToUpdate());
} else if (item instanceof HomeAssistantNumericMenuItem) {
// Numeric items can have an optional template to evaluate
var nmi = item as HomeAssistantNumericMenuItem;
if (nmi.hasTemplate()) {
fullList.add(item);
}
} else if (item instanceof HomeAssistantToggleMenuItem) {
fullList.add(item);
} else if (item instanceof HomeAssistantTapMenuItem) {
@@ -216,7 +236,7 @@ class HomeAssistantViewDelegate extends WatchUi.Menu2InputDelegate {
// If its started from glance or as an activity, directly exit the widget/app
// (on widgets without glance, this exit() won't do anything,
// so the base view will be shown instead, through the popView below this "if body")
System.exit();
System.exit();
}
WatchUi.popView(WatchUi.SLIDE_RIGHT);
@@ -248,6 +268,12 @@ class HomeAssistantViewDelegate extends WatchUi.Menu2InputDelegate {
var haItem = item as HomeAssistantTapMenuItem;
// System.println(haItem.getLabel() + " " + haItem.getId());
haItem.callService();
} else if (item instanceof HomeAssistantNumericMenuItem) {
var haItem = item as HomeAssistantNumericMenuItem;
// System.println(haItem.getLabel() + " " + haItem.getId());
// create new view to select new valu
var numView = new HomeAssistantNumericView(haItem);
WatchUi.pushView(numView, new HomeAssistantNumericViewDelegate(false,haItem), WatchUi.SLIDE_LEFT);
} else if (item instanceof HomeAssistantGroupMenuItem) {
var haMenuItem = item as HomeAssistantGroupMenuItem;
// System.println("IconMenu: " + haMenuItem.getLabel() + " " + haMenuItem.getId());