Cached 'has' result in initialize()

Also amended a bit of README that was missed and added a memory usage in the RootView for widgets here memory is limited, to serve as a warning to users who are likely to complain.
This commit is contained in:
Philip Abbey
2024-01-14 19:59:18 +00:00
parent 84aaa44995
commit 81762fbf7d
11 changed files with 92 additions and 22 deletions

View File

@ -24,6 +24,17 @@ using Toybox.Graphics;
using Toybox.Application.Properties;
class HomeAssistantService {
private var mHasToast as Lang.Boolean = false;
private var mHasVibrate as Lang.Boolean = false;
function initialise() {
if (WatchUi has :showToast) {
mHasToast = true;
}
if (Attention has :vibrate) {
mHasVibrate = true;
}
}
// Callback function after completing the POST request to call a service.
//
@ -88,7 +99,7 @@ class HomeAssistantService {
toast = (d[i].get("attributes") as Lang.Dictionary).get("friendly_name") as Lang.String;
}
}
if (WatchUi has :showToast) {
if (mHasToast) {
WatchUi.showToast(toast, null);
} else {
new Alert({
@ -143,7 +154,7 @@ class HomeAssistantService {
},
method(:onReturnCall)
);
if (Attention has :vibrate) {
if (mHasVibrate) {
Attention.vibrate([
new Attention.VibeProfile(50, 100), // On for 100ms
new Attention.VibeProfile( 0, 100), // Off for 100ms