Menu item code tidy

Prior to sorting out inheritance.
This commit is contained in:
Philip Abbey
2025-03-27 20:45:51 +00:00
parent e41f451fbc
commit 236a4969d7
3 changed files with 16 additions and 9 deletions

View File

@ -47,6 +47,10 @@ class HomeAssistantGroupMenuItem extends WatchUi.IconMenuItem {
mMenu = new HomeAssistantView(definition, null); mMenu = new HomeAssistantView(definition, null);
} }
function hasTemplate() as Lang.Boolean {
return mTemplate != null;
}
function buildTemplate() as Lang.String or Null { function buildTemplate() as Lang.String or Null {
return mTemplate; return mTemplate;
} }
@ -63,7 +67,7 @@ class HomeAssistantGroupMenuItem extends WatchUi.IconMenuItem {
var f = data as Lang.Float; var f = data as Lang.Float;
setSubLabel(f.format("%f")); setSubLabel(f.format("%f"));
} else if(data instanceof Lang.Dictionary) { } else if(data instanceof Lang.Dictionary) {
// System.println("HomeAsistantGroupMenuItem updateState() data = " + data); // System.println("HomeAssistantGroupMenuItem updateState() data = " + data);
if (data.get("error") != null) { if (data.get("error") != null) {
setSubLabel($.Rez.Strings.TemplateError); setSubLabel($.Rez.Strings.TemplateError);
} else { } else {
@ -80,8 +84,4 @@ class HomeAssistantGroupMenuItem extends WatchUi.IconMenuItem {
return mMenu; return mMenu;
} }
function hasTemplate() as Lang.Boolean {
return mTemplate != null;
}
} }

View File

@ -79,7 +79,7 @@ class HomeAssistantTapMenuItem extends WatchUi.IconMenuItem {
var f = data as Lang.Float; var f = data as Lang.Float;
setSubLabel(f.format("%f")); setSubLabel(f.format("%f"));
} else if(data instanceof Lang.Dictionary) { } else if(data instanceof Lang.Dictionary) {
// System.println("HomeAsistantTemplateMenuItem updateState() data = " + data); // System.println("HomeAssistantTapMenuItem updateState() data = " + data);
if (data.get("error") != null) { if (data.get("error") != null) {
setSubLabel($.Rez.Strings.TemplateError); setSubLabel($.Rez.Strings.TemplateError);
} else { } else {

View File

@ -42,7 +42,13 @@ class HomeAssistantToggleMenuItem extends WatchUi.ToggleMenuItem {
:icon as Graphics.BitmapType or WatchUi.Drawable or Lang.Symbol :icon as Graphics.BitmapType or WatchUi.Drawable or Lang.Symbol
} or Null } or Null
) { ) {
WatchUi.ToggleMenuItem.initialize(label, null, null, false, options); WatchUi.ToggleMenuItem.initialize(
label,
null,
null,
false,
options
);
if (Attention has :vibrate) { if (Attention has :vibrate) {
mHasVibrate = true; mHasVibrate = true;
} }
@ -81,7 +87,7 @@ class HomeAssistantToggleMenuItem extends WatchUi.ToggleMenuItem {
var f = data as Lang.Float; var f = data as Lang.Float;
setSubLabel(f.format("%f")); setSubLabel(f.format("%f"));
} else if(data instanceof Lang.Dictionary) { } else if(data instanceof Lang.Dictionary) {
// System.println("HomeAsistantToggleMenuItem updateState() data = " + data); // System.println("HomeAssistantToggleMenuItem updateState() data = " + data);
if (data.get("error") != null) { if (data.get("error") != null) {
setSubLabel($.Rez.Strings.TemplateError); setSubLabel($.Rez.Strings.TemplateError);
} else { } else {
@ -93,6 +99,7 @@ class HomeAssistantToggleMenuItem extends WatchUi.ToggleMenuItem {
} }
WatchUi.requestUpdate(); WatchUi.requestUpdate();
} }
function updateToggleState(data as Lang.String or Lang.Dictionary or Null) as Void { function updateToggleState(data as Lang.String or Lang.Dictionary or Null) as Void {
if (data == null) { if (data == null) {
setUiToggle("off"); setUiToggle("off");
@ -102,7 +109,7 @@ class HomeAssistantToggleMenuItem extends WatchUi.ToggleMenuItem {
setSubLabel($.Rez.Strings.Unavailable); setSubLabel($.Rez.Strings.Unavailable);
} }
} else if(data instanceof Lang.Dictionary) { } else if(data instanceof Lang.Dictionary) {
// System.println("HomeAsistantToggleMenuItem updateState() data = " + data); // System.println("HomeAssistantToggleMenuItem updateState() data = " + data);
if (mTemplate == null) { if (mTemplate == null) {
if (data.get("error") != null) { if (data.get("error") != null) {
setSubLabel($.Rez.Strings.TemplateError); setSubLabel($.Rez.Strings.TemplateError);