From e41f451fbca17a96b016bafc3d9bbd8b8d7cde01 Mon Sep 17 00:00:00 2001 From: Philip Abbey Date: Thu, 27 Mar 2025 20:45:02 +0000 Subject: [PATCH 1/4] Update HomeAssistantApp.mc Fix for lost speedup from v2.24 when fixing a bug in v2.25. --- source/HomeAssistantApp.mc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/source/HomeAssistantApp.mc b/source/HomeAssistantApp.mc index 77e3df2..90b2d9a 100644 --- a/source/HomeAssistantApp.mc +++ b/source/HomeAssistantApp.mc @@ -266,6 +266,9 @@ class HomeAssistantApp extends Application.AppBase { private function buildMenu(menu as Lang.Dictionary) { mHaMenu = new HomeAssistantView(menu, null); mQuitTimer.begin(); + if (!Settings.getWebhookId().equals("")) { + startUpdates(); + } // If not, this will be done via a chain in Settings.webhook() and mWebhookManager.requestWebhookId() that registers the sensors. } function startUpdates() { From 236a4969d73e0b3c7cb5279b902fcfdeb7c28f29 Mon Sep 17 00:00:00 2001 From: Philip Abbey Date: Thu, 27 Mar 2025 20:45:51 +0000 Subject: [PATCH 2/4] Menu item code tidy Prior to sorting out inheritance. --- source/HomeAssistantGroupMenuItem.mc | 10 +++++----- source/HomeAssistantTapMenuItem.mc | 2 +- source/HomeAssistantToggleMenuItem.mc | 13 ++++++++++--- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/source/HomeAssistantGroupMenuItem.mc b/source/HomeAssistantGroupMenuItem.mc index 049a49f..e886cd4 100644 --- a/source/HomeAssistantGroupMenuItem.mc +++ b/source/HomeAssistantGroupMenuItem.mc @@ -47,6 +47,10 @@ class HomeAssistantGroupMenuItem extends WatchUi.IconMenuItem { mMenu = new HomeAssistantView(definition, null); } + function hasTemplate() as Lang.Boolean { + return mTemplate != null; + } + function buildTemplate() as Lang.String or Null { return mTemplate; } @@ -63,7 +67,7 @@ class HomeAssistantGroupMenuItem extends WatchUi.IconMenuItem { var f = data as Lang.Float; setSubLabel(f.format("%f")); } else if(data instanceof Lang.Dictionary) { - // System.println("HomeAsistantGroupMenuItem updateState() data = " + data); + // System.println("HomeAssistantGroupMenuItem updateState() data = " + data); if (data.get("error") != null) { setSubLabel($.Rez.Strings.TemplateError); } else { @@ -80,8 +84,4 @@ class HomeAssistantGroupMenuItem extends WatchUi.IconMenuItem { return mMenu; } - function hasTemplate() as Lang.Boolean { - return mTemplate != null; - } - } diff --git a/source/HomeAssistantTapMenuItem.mc b/source/HomeAssistantTapMenuItem.mc index 58a91aa..1c8a2be 100644 --- a/source/HomeAssistantTapMenuItem.mc +++ b/source/HomeAssistantTapMenuItem.mc @@ -79,7 +79,7 @@ class HomeAssistantTapMenuItem extends WatchUi.IconMenuItem { var f = data as Lang.Float; setSubLabel(f.format("%f")); } else if(data instanceof Lang.Dictionary) { - // System.println("HomeAsistantTemplateMenuItem updateState() data = " + data); + // System.println("HomeAssistantTapMenuItem updateState() data = " + data); if (data.get("error") != null) { setSubLabel($.Rez.Strings.TemplateError); } else { diff --git a/source/HomeAssistantToggleMenuItem.mc b/source/HomeAssistantToggleMenuItem.mc index a8b7dcb..6dcd06b 100644 --- a/source/HomeAssistantToggleMenuItem.mc +++ b/source/HomeAssistantToggleMenuItem.mc @@ -42,7 +42,13 @@ class HomeAssistantToggleMenuItem extends WatchUi.ToggleMenuItem { :icon as Graphics.BitmapType or WatchUi.Drawable or Lang.Symbol } or Null ) { - WatchUi.ToggleMenuItem.initialize(label, null, null, false, options); + WatchUi.ToggleMenuItem.initialize( + label, + null, + null, + false, + options + ); if (Attention has :vibrate) { mHasVibrate = true; } @@ -81,7 +87,7 @@ class HomeAssistantToggleMenuItem extends WatchUi.ToggleMenuItem { var f = data as Lang.Float; setSubLabel(f.format("%f")); } else if(data instanceof Lang.Dictionary) { - // System.println("HomeAsistantToggleMenuItem updateState() data = " + data); + // System.println("HomeAssistantToggleMenuItem updateState() data = " + data); if (data.get("error") != null) { setSubLabel($.Rez.Strings.TemplateError); } else { @@ -93,6 +99,7 @@ class HomeAssistantToggleMenuItem extends WatchUi.ToggleMenuItem { } WatchUi.requestUpdate(); } + function updateToggleState(data as Lang.String or Lang.Dictionary or Null) as Void { if (data == null) { setUiToggle("off"); @@ -102,7 +109,7 @@ class HomeAssistantToggleMenuItem extends WatchUi.ToggleMenuItem { setSubLabel($.Rez.Strings.Unavailable); } } else if(data instanceof Lang.Dictionary) { - // System.println("HomeAsistantToggleMenuItem updateState() data = " + data); + // System.println("HomeAssistantToggleMenuItem updateState() data = " + data); if (mTemplate == null) { if (data.get("error") != null) { setSubLabel($.Rez.Strings.TemplateError); From 71cba8c21c92212a0a90c9b35d1acd0f8c7b8880 Mon Sep 17 00:00:00 2001 From: Philip Abbey Date: Fri, 28 Mar 2025 00:20:53 +0000 Subject: [PATCH 3/4] Code attribution for author of PIN entry. Prior to sorting out inheritance. --- source/Globals.mc | 2 +- source/HomeAssistantApp.mc | 2 +- source/HomeAssistantPinConfirmation.mc | 2 +- source/HomeAssistantToggleMenuItem.mc | 2 +- source/HomeAssistantView.mc | 2 +- source/Settings.mc | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/source/Globals.mc b/source/Globals.mc index fbd64f8..9d9600c 100644 --- a/source/Globals.mc +++ b/source/Globals.mc @@ -9,7 +9,7 @@ // tested on a Venu 2 device. The source code is provided at: // https://github.com/house-of-abbey/GarminHomeAssistant. // -// P A Abbey & J D Abbey & Someone0nEarth, 31 October 2023 +// P A Abbey & J D Abbey & Someone0nEarth & moesterheld, 31 October 2023 // // // Description: diff --git a/source/HomeAssistantApp.mc b/source/HomeAssistantApp.mc index 90b2d9a..7ef6961 100644 --- a/source/HomeAssistantApp.mc +++ b/source/HomeAssistantApp.mc @@ -9,7 +9,7 @@ // tested on a Venu 2 device. The source code is provided at: // https://github.com/house-of-abbey/GarminHomeAssistant. // -// P A Abbey & J D Abbey & Someone0nEarth, 31 October 2023 +// P A Abbey & J D Abbey & Someone0nEarth & moesterheld, 31 October 2023 // // // Description: diff --git a/source/HomeAssistantPinConfirmation.mc b/source/HomeAssistantPinConfirmation.mc index ab51a98..7c519bf 100644 --- a/source/HomeAssistantPinConfirmation.mc +++ b/source/HomeAssistantPinConfirmation.mc @@ -9,7 +9,7 @@ // tested on a Venu 2 device. The source code is provided at: // https://github.com/house-of-abbey/GarminHomeAssistant. // -// P A Abbey & J D Abbey & Someone0nEarth, 31 October 2023 +// P A Abbey & J D Abbey & Someone0nEarth & moesterheld, 31 October 2023 // // // Description: diff --git a/source/HomeAssistantToggleMenuItem.mc b/source/HomeAssistantToggleMenuItem.mc index 6dcd06b..d7a14d0 100644 --- a/source/HomeAssistantToggleMenuItem.mc +++ b/source/HomeAssistantToggleMenuItem.mc @@ -9,7 +9,7 @@ // tested on a Venu 2 device. The source code is provided at: // https://github.com/house-of-abbey/GarminHomeAssistant. // -// P A Abbey & J D Abbey & Someone0nEarth, 31 October 2023 +// P A Abbey & J D Abbey & Someone0nEarth & moesterheld, 31 October 2023 // // // Description: diff --git a/source/HomeAssistantView.mc b/source/HomeAssistantView.mc index 5bd7877..f894432 100644 --- a/source/HomeAssistantView.mc +++ b/source/HomeAssistantView.mc @@ -9,7 +9,7 @@ // tested on a Venu 2 device. The source code is provided at: // https://github.com/house-of-abbey/GarminHomeAssistant. // -// P A Abbey & J D Abbey & Someone0nEarth, 31 October 2023 +// P A Abbey & J D Abbey & Someone0nEarth & moesterheld, 31 October 2023 // // // Description: diff --git a/source/Settings.mc b/source/Settings.mc index ed29123..283c276 100644 --- a/source/Settings.mc +++ b/source/Settings.mc @@ -9,7 +9,7 @@ // tested on a Venu 2 device. The source code is provided at: // https://github.com/house-of-abbey/GarminHomeAssistant. // -// P A Abbey & J D Abbey, SomeoneOnEarth, 23 November 2023 +// P A Abbey & J D Abbey, SomeoneOnEarth & moesterheld, 23 November 2023 // // // Description: From e8f2c0d3bbb9c9a5e51f6fa05db79f2c0274f9f3 Mon Sep 17 00:00:00 2001 From: Philip Abbey Date: Fri, 28 Mar 2025 00:22:09 +0000 Subject: [PATCH 4/4] Amended menu item class inheritance --- HISTORY.md | 1 + source/HomeAssistantGroupMenuItem.mc | 48 +++-------------- source/HomeAssistantMenuItem.mc | 79 ++++++++++++++++++++++++++++ source/HomeAssistantTapMenuItem.mc | 54 +++++-------------- 4 files changed, 100 insertions(+), 82 deletions(-) create mode 100644 source/HomeAssistantMenuItem.mc diff --git a/HISTORY.md b/HISTORY.md index 8471ad5..b1e6e38 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -38,3 +38,4 @@ | 2.23 | Added "info" menu item for displaying information via a template without a tap or toggle. Essentially like the old 'template' type that was deprecated when all items were amended to display evaluated templates. That action removed the display only items too hastily. Added 5 new devices in the model range Instinct 3 and Instinct E. | | 2.24 | Experiment to prevent new Webhook IDs being created unnecessarily. Reduced the latency for the first menu update. Added 4 new devices: approachs50, descentg2, descentmk1, and gpsmap66. | | 2.25 | 2 Bug fixes. First time startup issues caused by v2.24 change and a fix for pure numbers in returned templates. | +| 2.26 | Retry responsive menu fix failed in v2.24. Cosmetic internal class changes. | diff --git a/source/HomeAssistantGroupMenuItem.mc b/source/HomeAssistantGroupMenuItem.mc index e886cd4..f4df2a7 100644 --- a/source/HomeAssistantGroupMenuItem.mc +++ b/source/HomeAssistantGroupMenuItem.mc @@ -22,8 +22,7 @@ using Toybox.Lang; using Toybox.WatchUi; -class HomeAssistantGroupMenuItem extends WatchUi.IconMenuItem { - private var mTemplate as Lang.String or Null; +class HomeAssistantGroupMenuItem extends HomeAssistantMenuItem { private var mMenu as HomeAssistantView; function initialize( @@ -34,52 +33,21 @@ class HomeAssistantGroupMenuItem extends WatchUi.IconMenuItem { :alignment as WatchUi.MenuItem.Alignment } or Null ) { + if (options != null) { + options.put(:icon, icon); + } else { + options = { :icon => icon }; + } - WatchUi.IconMenuItem.initialize( + HomeAssistantMenuItem.initialize( definition.get("name") as Lang.String, - null, - null, - icon, + template, options ); - mTemplate = template; mMenu = new HomeAssistantView(definition, null); } - function hasTemplate() as Lang.Boolean { - return mTemplate != null; - } - - function buildTemplate() as Lang.String or Null { - return mTemplate; - } - - function updateState(data as Lang.String or Lang.Dictionary or Null) as Void { - if (data == null) { - setSubLabel(null); - } else if(data instanceof Lang.String) { - setSubLabel(data); - } else if(data instanceof Lang.Number) { - var d = data as Lang.Number; - setSubLabel(d.format("%d")); - } else if(data instanceof Lang.Float) { - var f = data as Lang.Float; - setSubLabel(f.format("%f")); - } else if(data instanceof Lang.Dictionary) { - // System.println("HomeAssistantGroupMenuItem updateState() data = " + data); - if (data.get("error") != null) { - setSubLabel($.Rez.Strings.TemplateError); - } else { - setSubLabel($.Rez.Strings.PotentialError); - } - } else { - // The template must return a Lang.String, Number or Float, or the item cannot be formatted locally without error. - setSubLabel(WatchUi.loadResource($.Rez.Strings.TemplateError) as Lang.String); - } - WatchUi.requestUpdate(); - } - function getMenuView() as HomeAssistantView { return mMenu; } diff --git a/source/HomeAssistantMenuItem.mc b/source/HomeAssistantMenuItem.mc new file mode 100644 index 0000000..fbb060d --- /dev/null +++ b/source/HomeAssistantMenuItem.mc @@ -0,0 +1,79 @@ +//----------------------------------------------------------------------------------- +// +// Distributed under MIT Licence +// See https://github.com/house-of-abbey/GarminHomeAssistant/blob/main/LICENSE. +// +//----------------------------------------------------------------------------------- +// +// GarminHomeAssistant is a Garmin IQ application written in Monkey C and routinely +// tested on a Venu 2 device. The source code is provided at: +// https://github.com/house-of-abbey/GarminHomeAssistant. +// +// P A Abbey & J D Abbey & Someone0nEarth, 31 October 2023 +// +// +// Description: +// +// Generic menu button with an icon that optionally renders a Home Assistant Template. +// +//----------------------------------------------------------------------------------- + +using Toybox.Lang; +using Toybox.WatchUi; +using Toybox.Graphics; + +class HomeAssistantMenuItem extends WatchUi.IconMenuItem { + private var mTemplate as Lang.String or Null; + + function initialize( + label as Lang.String or Lang.Symbol, + template as Lang.String, + options as { + :alignment as WatchUi.MenuItem.Alignment, + :icon as Graphics.BitmapType or WatchUi.Drawable or Lang.Symbol + } or Null + ) { + WatchUi.IconMenuItem.initialize( + label, + null, + null, + options.get(:icon), + options + ); + mTemplate = template; + } + + function hasTemplate() as Lang.Boolean { + return mTemplate != null; + } + + function buildTemplate() as Lang.String or Null { + return mTemplate; + } + + function updateState(data as Lang.String or Lang.Dictionary or Null) as Void { + if (data == null) { + setSubLabel($.Rez.Strings.Empty); + } else if(data instanceof Lang.String) { + setSubLabel(data); + } else if(data instanceof Lang.Number) { + var d = data as Lang.Number; + setSubLabel(d.format("%d")); + } else if(data instanceof Lang.Float) { + var f = data as Lang.Float; + setSubLabel(f.format("%f")); + } else if(data instanceof Lang.Dictionary) { + // System.println("HomeAssistantMenuItem updateState() data = " + data); + if (data.get("error") != null) { + setSubLabel($.Rez.Strings.TemplateError); + } else { + setSubLabel($.Rez.Strings.PotentialError); + } + } else { + // The template must return a Lang.String, Number or Float, or the item cannot be formatted locally without error. + setSubLabel(WatchUi.loadResource($.Rez.Strings.TemplateError) as Lang.String); + } + WatchUi.requestUpdate(); + } + +} \ No newline at end of file diff --git a/source/HomeAssistantTapMenuItem.mc b/source/HomeAssistantTapMenuItem.mc index 1c8a2be..9e89e78 100644 --- a/source/HomeAssistantTapMenuItem.mc +++ b/source/HomeAssistantTapMenuItem.mc @@ -9,7 +9,7 @@ // tested on a Venu 2 device. The source code is provided at: // https://github.com/house-of-abbey/GarminHomeAssistant. // -// P A Abbey & J D Abbey & Someone0nEarth, 31 October 2023 +// P A Abbey & J D Abbey & Someone0nEarth & moesterheld, 31 October 2023 // // // Description: @@ -22,9 +22,8 @@ using Toybox.Lang; using Toybox.WatchUi; using Toybox.Graphics; -class HomeAssistantTapMenuItem extends WatchUi.IconMenuItem { +class HomeAssistantTapMenuItem extends HomeAssistantMenuItem { private var mHomeAssistantService as HomeAssistantService; - private var mTemplate as Lang.String; private var mService as Lang.String or Null; private var mConfirm as Lang.Boolean; private var mPin as Lang.Boolean; @@ -39,59 +38,30 @@ class HomeAssistantTapMenuItem extends WatchUi.IconMenuItem { data as Lang.Dictionary or Null, icon as Graphics.BitmapType or WatchUi.Drawable, options as { - :alignment as WatchUi.MenuItem.Alignment + :alignment as WatchUi.MenuItem.Alignment, + :icon as Graphics.BitmapType or WatchUi.Drawable or Lang.Symbol } or Null, haService as HomeAssistantService ) { - WatchUi.IconMenuItem.initialize( + if (options != null) { + options.put(:icon, icon); + } else { + options = { :icon => icon }; + } + + HomeAssistantMenuItem.initialize( label, - null, - null, - icon, + template, options ); mHomeAssistantService = haService; - mTemplate = template; mService = service; mConfirm = confirm; mPin = pin; mData = data; } - function hasTemplate() as Lang.Boolean { - return mTemplate != null; - } - - function buildTemplate() as Lang.String or Null { - return mTemplate; - } - - function updateState(data as Lang.String or Lang.Dictionary or Null) as Void { - if (data == null) { - setSubLabel($.Rez.Strings.Empty); - } else if(data instanceof Lang.String) { - setSubLabel(data); - } else if(data instanceof Lang.Number) { - var d = data as Lang.Number; - setSubLabel(d.format("%d")); - } else if(data instanceof Lang.Float) { - var f = data as Lang.Float; - setSubLabel(f.format("%f")); - } else if(data instanceof Lang.Dictionary) { - // System.println("HomeAssistantTapMenuItem updateState() data = " + data); - if (data.get("error") != null) { - setSubLabel($.Rez.Strings.TemplateError); - } else { - setSubLabel($.Rez.Strings.PotentialError); - } - } else { - // The template must return a Lang.String, Number or Float, or the item cannot be formatted locally without error. - setSubLabel(WatchUi.loadResource($.Rez.Strings.TemplateError) as Lang.String); - } - WatchUi.requestUpdate(); - } - function callService() as Void { var hasTouchScreen = System.getDeviceSettings().isTouchScreen; if (mPin && hasTouchScreen) {