Compare commits

...

7 Commits
v2.23 ... v2.25

Author SHA1 Message Date
a77870c2eb Fix for 2 bugs in issue 221 (#222)
Template rendering and Webhook ID on initial start.

Please review and (hopefully) approve, but don't merge as I need to
deploy to the beta app.
2025-03-27 06:32:27 +00:00
155649f162 Fix for 2 bugs in issue 221
Template rendering and Webhook ID on initial start.
2025-03-26 22:37:33 +00:00
1ae4085113 219 new garmin device keeps replacing previous device (#220) 2025-03-23 16:59:52 +00:00
7a14a65ba3 Update HISTORY.md
2.24 text
2025-03-23 16:54:52 +00:00
adf69d7dec Rearranging Web API Requests
Making sure the menu update API call is completed before the Webhook IDs are fetched in order to reduce latency to usefulness.
2025-03-23 16:54:13 +00:00
d105e69484 Update WebhookManager.mc
Removed Settings.unsetWebhookId() where it might be causing problems with replacement "Garmin Device" in Home Assistant.
2025-03-23 16:01:53 +00:00
184e2ac80e Add 4 new devices
approachs50, descentg2, descentmk1, and gpsmap66
2025-03-23 15:59:29 +00:00
11 changed files with 69 additions and 19 deletions

View File

@ -36,3 +36,4 @@
| 2.21 | Added 7 new devices (`edge1050`, `enduro3`, `fenix843mm`, `fenix847mm`, `fenix8solar47mm`, `fenix8solar51mm`, `fenixe`) and upgraded the SDK to 7.3.0. Fix for a bug on Edge devices introduced by v2.16 activity reporting improvements. |
| 2.22 | Major feature release adding an optional PIN to menu items. This significant new feature has been provided by [moesterheld](https://github.com/moesterheld). Please do not rely on this application for security. Use at your own risk! |
| 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. |

View File

@ -30,13 +30,14 @@
-->
<iq:application id="98c36259-498a-4458-9cef-74a273ad2bc3" type="watch-app" name="@Strings.AppName" entry="HomeAssistantApp" launcherIcon="@Drawables.LauncherIcon" minApiLevel="3.1.0">
<!--
Use the following from the Visual Studio Code comand palette to edit
Use the following from the Visual Studio Code command palette to edit
the build targets:
"Monkey C: Set Products by Product Category" - Lets you add all products
that belong to the same product category
"Monkey C: Edit Products" - Lets you add or remove any product
-->
<iq:products>
<iq:product id="approachs50"/>
<iq:product id="approachs7042mm"/>
<iq:product id="approachs7047mm"/>
<iq:product id="d2air"/>
@ -46,6 +47,8 @@
<iq:product id="d2deltas"/>
<iq:product id="d2mach1"/>
<iq:product id="descentg1"/>
<iq:product id="descentg2"/>
<iq:product id="descentmk1"/>
<iq:product id="descentmk2"/>
<iq:product id="descentmk2s"/>
<iq:product id="descentmk343mm"/>
@ -113,6 +116,7 @@
<iq:product id="fr945lte"/>
<iq:product id="fr955"/>
<iq:product id="fr965"/>
<iq:product id="gpsmap66"/>
<iq:product id="gpsmap67"/>
<iq:product id="instinct2"/>
<iq:product id="instinct2s"/>

View File

@ -34,6 +34,8 @@ project.manifest = manifest.xml
# Icon 55 53 48 46 42 37 32 30 28 26 24 21 19 18
# Screen 480 454 416 390 360 320 280 260 240 218 208 176 166 156
# Screen Size 390x390 launcher icon size 56x56
approachs50.resourcePath = $(approachs50.resourcePath);resources-launcher-56-56;resources-icons-46
# Screen Size 390x390 launcher icon size 70x70
approachs7042mm.resourcePath = $(approachs7042mm.resourcePath);resources-launcher-70-70;resources-icons-46
# Screen Size 454x454 launcher icon size 80x80
@ -50,6 +52,10 @@ d2deltas.resourcePath = $(d2deltas.resourcePath);resources-launcher-40-40;resour
d2mach1.resourcePath = $(d2mach1.resourcePath);resources-launcher-60-60;resources-icons-48
# Screen Size 176x176 launcher icon size 62x62
descentg1.resourcePath = $(descentg1.resourcePath);resources-launcher-62-62;resources-icons-21
# Screen Size 390x390 launcher icon size 60x60
descentg2.resourcePath = $(descentg2.resourcePath);resources-launcher-60-60;resources-icons-46
# Screen Size 240x240 launcher icon size 40x40
descentmk1.resourcePath = $(descentmk1.resourcePath);resources-launcher-40-40;resources-icons-28
# Screen Size 280x280 launcher icon size 40x40
descentmk2.resourcePath = $(descentmk2.resourcePath);resources-launcher-40-40;resources-icons-32
# Screen Size 240x240 launcher icon size 40x40
@ -164,6 +170,8 @@ fr955.resourcePath = $(fr955.resourcePath);resources-launcher-40-40;resources-ic
# Screen Size 454x454 launcher icon size 65x65
fr965.resourcePath = $(fr965.resourcePath);resources-launcher-65-65;resources-icons-53
# Screen Size 240x400 launcher icon size 38x33
gpsmap66.resourcePath = $(gpsmap66.resourcePath);resources-launcher-33-33;resources-icons-28
# Screen Size 240x400 launcher icon size 38x33
gpsmap67.resourcePath = $(gpsmap67.resourcePath);resources-launcher-33-33;resources-icons-28
# Screen Size 176x176 launcher icon size 62x62
instinct2.resourcePath = $(instinct2.resourcePath);resources-launcher-62-62;resources-icons-21-w

View File

@ -0,0 +1,17 @@
<!--
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
-->
<drawables>
<bitmap id="LauncherIcon" filename="launcher.svg" />
</drawables>

View File

@ -0,0 +1,4 @@
<svg fill="none" height="56" viewBox="0 0 400 400" width="56" xmlns="http://www.w3.org/2000/svg">
<path d="M320 301.762C320 310.012 313.25 316.762 305 316.762H95C86.75 316.762 80 310.012 80 301.762V211.762C80 203.512 84.77 191.993 90.61 186.153L189.39 87.3725C195.22 81.5425 204.77 81.5425 210.6 87.3725L309.39 186.162C315.22 191.992 320 203.522 320 211.772V301.772V301.762Z" fill="#F2F4F9"/>
<path d="M309.39 186.153L210.61 87.3725C204.78 81.5425 195.23 81.5425 189.4 87.3725L90.61 186.153C84.78 191.983 80 203.512 80 211.762V301.762C80 310.012 86.75 316.762 95 316.762H187.27L146.64 276.132C144.55 276.852 142.32 277.262 140 277.262C128.7 277.262 119.5 268.062 119.5 256.762C119.5 245.462 128.7 236.262 140 236.262C151.3 236.262 160.5 245.462 160.5 256.762C160.5 259.092 160.09 261.322 159.37 263.412L191 295.042V179.162C184.2 175.822 179.5 168.842 179.5 160.772C179.5 149.472 188.7 140.272 200 140.272C211.3 140.272 220.5 149.472 220.5 160.772C220.5 168.842 215.8 175.822 209 179.162V260.432L240.46 228.972C239.84 227.012 239.5 224.932 239.5 222.772C239.5 211.472 248.7 202.272 260 202.272C271.3 202.272 280.5 211.472 280.5 222.772C280.5 234.072 271.3 243.272 260 243.272C257.5 243.272 255.12 242.802 252.91 241.982L209 285.892V316.772H305C313.25 316.772 320 310.022 320 301.772V211.772C320 203.522 315.23 192.002 309.39 186.162V186.153Z" fill="#18BCF2"/>
</svg>

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

@ -39,7 +39,6 @@ class HomeAssistantApp extends Application.AppBase {
private var mIsApp as Lang.Boolean = false; // Or Widget
private var mUpdating as Lang.Boolean = false; // Don't start a second chain of updates
private var mTemplates as Lang.Dictionary = {};
private var startUpdating as Lang.Boolean = false;
function initialize() {
AppBase.initialize();
@ -120,12 +119,16 @@ class HomeAssistantApp extends Application.AppBase {
return ErrorView.create(WatchUi.loadResource($.Rez.Strings.NoInternet) as Lang.String);
} else {
var isCached = fetchMenuConfig();
var ret = null;
fetchApiStatus();
if (isCached) {
return [mHaMenu, new HomeAssistantViewDelegate(true)];
ret = [mHaMenu, new HomeAssistantViewDelegate(true)];
} else {
return [new WatchUi.View(), new WatchUi.BehaviorDelegate()];
ret = [new WatchUi.View(), new WatchUi.BehaviorDelegate()];
}
// Separated from Settings.update() in order to call after fetchMenuConfig() and not call it on changes settings.
Settings.webhook();
return ret;
}
}
@ -263,17 +266,14 @@ class HomeAssistantApp extends Application.AppBase {
private function buildMenu(menu as Lang.Dictionary) {
mHaMenu = new HomeAssistantView(menu, null);
mQuitTimer.begin();
if (startUpdating) {
startUpdates();
}
}
function startUpdates() {
if (mHaMenu != null and !mUpdating) {
// Start the continuous update process that continues for as long as the application is running.
updateMenuItems();
mUpdating = true;
}
startUpdating = true;
}
function onReturnUpdateMenuItems(responseCode as Lang.Number, data as Null or Lang.Dictionary) as Void {

View File

@ -56,6 +56,12 @@ class HomeAssistantGroupMenuItem extends WatchUi.IconMenuItem {
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("HomeAsistantGroupMenuItem updateState() data = " + data);
if (data.get("error") != null) {
@ -64,7 +70,7 @@ class HomeAssistantGroupMenuItem extends WatchUi.IconMenuItem {
setSubLabel($.Rez.Strings.PotentialError);
}
} else {
// The template must return a Lang.String, a number can be either integer or float and hence cannot be formatted locally without error.
// 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();

View File

@ -72,6 +72,12 @@ class HomeAssistantTapMenuItem extends WatchUi.IconMenuItem {
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("HomeAsistantTemplateMenuItem updateState() data = " + data);
if (data.get("error") != null) {
@ -80,7 +86,7 @@ class HomeAssistantTapMenuItem extends WatchUi.IconMenuItem {
setSubLabel($.Rez.Strings.PotentialError);
}
} else {
// The template must return a Lang.String, a number can be either integer or float and hence cannot be formatted locally without error.
// 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();

View File

@ -74,6 +74,12 @@ class HomeAssistantToggleMenuItem extends WatchUi.ToggleMenuItem {
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("HomeAsistantToggleMenuItem updateState() data = " + data);
if (data.get("error") != null) {
@ -82,7 +88,7 @@ class HomeAssistantToggleMenuItem extends WatchUi.ToggleMenuItem {
setSubLabel($.Rez.Strings.PotentialError);
}
} else {
// The template must return a Lang.String, a number can be either integer or float and hence cannot be formatted locally without error.
// 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();

View File

@ -69,7 +69,9 @@ class Settings {
mMenuAlignment = Properties.getValue("menu_alignment");
mIsSensorsLevelEnabled = Properties.getValue("enable_battery_level");
mBatteryRefreshRate = Properties.getValue("battery_level_refresh_rate");
}
static function webhook() {
if (System has :ServiceDelegate) {
mHasService = true;
}
@ -106,13 +108,13 @@ class Settings {
unsetWebhookId();
}
}
// System.println("Settings update(): getTemporalEventRegisteredTime() = " + Background.getTemporalEventRegisteredTime());
// System.println("Settings webhook(): getTemporalEventRegisteredTime() = " + Background.getTemporalEventRegisteredTime());
// if (Background.getTemporalEventRegisteredTime() != null) {
// System.println("Settings update(): getTemporalEventRegisteredTime().value() = " + Background.getTemporalEventRegisteredTime().value().format("%d") + " seconds");
// System.println("Settings webhook(): getTemporalEventRegisteredTime().value() = " + Background.getTemporalEventRegisteredTime().value().format("%d") + " seconds");
// } else {
// System.println("Settings update(): getTemporalEventRegisteredTime() = null");
// System.println("Settings webhook(): getTemporalEventRegisteredTime() = null");
// }
}
}
static function getApiKey() as Lang.String {
return mApiKey;

View File

@ -120,25 +120,21 @@ class WebhookManager {
case Communications.BLE_HOST_TIMEOUT:
case Communications.BLE_CONNECTION_UNAVAILABLE:
// System.println("WebhookManager onReturnRegisterWebhookSensor() Response Code: BLE_HOST_TIMEOUT or BLE_CONNECTION_UNAVAILABLE, Bluetooth connection severed.");
Settings.unsetWebhookId();
ErrorView.show(WatchUi.loadResource($.Rez.Strings.WebhookFailed) as Lang.String + "\n" + WatchUi.loadResource($.Rez.Strings.NoPhone) as Lang.String);
break;
case Communications.BLE_QUEUE_FULL:
// System.println("WebhookManager onReturnRegisterWebhookSensor() Response Code: BLE_QUEUE_FULL, API calls too rapid.");
Settings.unsetWebhookId();
ErrorView.show(WatchUi.loadResource($.Rez.Strings.WebhookFailed) as Lang.String + "\n" + WatchUi.loadResource($.Rez.Strings.ApiFlood) as Lang.String);
break;
case Communications.NETWORK_REQUEST_TIMED_OUT:
// System.println("WebhookManager onReturnRegisterWebhookSensor() Response Code: NETWORK_REQUEST_TIMED_OUT, check Internet connection.");
Settings.unsetWebhookId();
ErrorView.show(WatchUi.loadResource($.Rez.Strings.WebhookFailed) as Lang.String + "\n" + WatchUi.loadResource($.Rez.Strings.NoResponse) as Lang.String);
break;
case Communications.NETWORK_RESPONSE_OUT_OF_MEMORY:
// System.println("WebhookManager onReturnRegisterWebhookSensor() Response Code: NETWORK_RESPONSE_OUT_OF_MEMORY, are we going too fast?");
Settings.unsetWebhookId();
// Ignore and see if we can carry on
break;