mirror of
https://github.com/house-of-abbey/GarminHomeAssistant.git
synced 2025-08-02 18:08:34 +00:00
An assortment of cosmetic changes
JSON schema fix to remove 'template' as a valid option, punctuation in strings, whitespace, and a new application history entry.
This commit is contained in:
@ -22,20 +22,19 @@ using Toybox.Lang;
|
||||
|
||||
(:glance)
|
||||
class Globals {
|
||||
static const scAlertTimeout = 2000; // ms
|
||||
static const scTapTimeout = 1000; // ms
|
||||
static const scAlertTimeout = 2000; // ms
|
||||
static const scTapTimeout = 1000; // ms
|
||||
// Time to let the existing HTTP responses get serviced after a
|
||||
// Communications.NETWORK_RESPONSE_OUT_OF_MEMORY response code.
|
||||
static const scApiBackoff = 1000; // ms
|
||||
static const scApiBackoff = 1000; // ms
|
||||
// Needs to be long enough to enable a "double ESC" to quit the application from
|
||||
// an ErrorView.
|
||||
static const scApiResume = 200; // ms
|
||||
static const scApiResume = 200; // ms
|
||||
// Warn the user after fetching the menu if their watch is low on memory before the device crashes.
|
||||
static const scLowMem = 0.90; // percent as a fraction.
|
||||
static const scLowMem = 0.90; // percent as a fraction.
|
||||
|
||||
// constants for PIN confirmation dialog
|
||||
static const scPinMaxFailures = 5; // maximum number of failed pin confirmation attemps allwed in ...
|
||||
static const scPinMaxFailureMinutes = 2; // ... this number of minutes before pin confirmation is locked for ...
|
||||
// Constants for PIN confirmation dialog
|
||||
static const scPinMaxFailures = 5; // Maximum number of failed PIN confirmation attemps allwed in ...
|
||||
static const scPinMaxFailureMinutes = 2; // ... this number of minutes before PIN confirmation is locked for ...
|
||||
static const scPinLockTimeMinutes = 10; // ... this number of minutes
|
||||
|
||||
}
|
||||
|
@ -99,25 +99,25 @@ class HomeAssistantApp extends Application.AppBase {
|
||||
|
||||
if (Settings.getApiKey().length() == 0) {
|
||||
// System.println("HomeAssistantApp getInitialView(): No API key in the application Settings.");
|
||||
return ErrorView.create(WatchUi.loadResource($.Rez.Strings.NoAPIKey) as Lang.String + ".");
|
||||
return ErrorView.create(WatchUi.loadResource($.Rez.Strings.NoAPIKey) as Lang.String);
|
||||
} else if (Settings.getApiUrl().length() == 0) {
|
||||
// System.println("HomeAssistantApp getInitialView(): No API URL in the application Settings.");
|
||||
return ErrorView.create(WatchUi.loadResource($.Rez.Strings.NoApiUrl) as Lang.String + ".");
|
||||
return ErrorView.create(WatchUi.loadResource($.Rez.Strings.NoApiUrl) as Lang.String);
|
||||
} else if (Settings.getApiUrl().substring(-1, Settings.getApiUrl().length()).equals("/")) {
|
||||
// System.println("HomeAssistantApp getInitialView(): API URL must not have a trailing slash '/'.");
|
||||
return ErrorView.create(WatchUi.loadResource($.Rez.Strings.TrailingSlashErr) as Lang.String + ".");
|
||||
return ErrorView.create(WatchUi.loadResource($.Rez.Strings.TrailingSlashErr) as Lang.String);
|
||||
} else if (Settings.getConfigUrl().length() == 0) {
|
||||
// System.println("HomeAssistantApp getInitialView(): No configuration URL in the application settings.");
|
||||
return ErrorView.create(WatchUi.loadResource($.Rez.Strings.NoConfigUrl) as Lang.String + ".");
|
||||
return ErrorView.create(WatchUi.loadResource($.Rez.Strings.NoConfigUrl) as Lang.String);
|
||||
} else if (Settings.getPin() == null) {
|
||||
// System.println("HomeAssistantApp getInitialView(): Invalid PIN in application settings.");
|
||||
return ErrorView.create(WatchUi.loadResource($.Rez.Strings.SettingsPinError) as Lang.String + ".");
|
||||
return ErrorView.create(WatchUi.loadResource($.Rez.Strings.SettingsPinError) as Lang.String);
|
||||
} else if (! System.getDeviceSettings().phoneConnected) {
|
||||
// System.println("HomeAssistantApp getInitialView(): No Phone connection, skipping API call.");
|
||||
return ErrorView.create(WatchUi.loadResource($.Rez.Strings.NoPhone) as Lang.String + ".");
|
||||
return ErrorView.create(WatchUi.loadResource($.Rez.Strings.NoPhone) as Lang.String);
|
||||
} else if (! System.getDeviceSettings().connectionAvailable) {
|
||||
// System.println("HomeAssistantApp getInitialView(): No Internet connection, skipping API call.");
|
||||
return ErrorView.create(WatchUi.loadResource($.Rez.Strings.NoInternet) as Lang.String + ".");
|
||||
return ErrorView.create(WatchUi.loadResource($.Rez.Strings.NoInternet) as Lang.String);
|
||||
} else {
|
||||
var isCached = fetchMenuConfig();
|
||||
fetchApiStatus();
|
||||
@ -142,7 +142,7 @@ class HomeAssistantApp extends Application.AppBase {
|
||||
case Communications.BLE_CONNECTION_UNAVAILABLE:
|
||||
// System.println("HomeAssistantApp onReturnFetchMenuConfig() Response Code: BLE_HOST_TIMEOUT or BLE_CONNECTION_UNAVAILABLE, Bluetooth connection severed.");
|
||||
if (!mIsGlance) {
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.NoPhone) as Lang.String + ".");
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.NoPhone) as Lang.String);
|
||||
}
|
||||
break;
|
||||
|
||||
@ -226,7 +226,7 @@ class HomeAssistantApp extends Application.AppBase {
|
||||
if (mIsGlance) {
|
||||
WatchUi.requestUpdate();
|
||||
} else {
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.NoPhone) as Lang.String + ".");
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.NoPhone) as Lang.String);
|
||||
}
|
||||
mMenuStatus = WatchUi.loadResource($.Rez.Strings.Unavailable) as Lang.String;
|
||||
} else if (! System.getDeviceSettings().connectionAvailable) {
|
||||
@ -234,7 +234,7 @@ class HomeAssistantApp extends Application.AppBase {
|
||||
if (mIsGlance) {
|
||||
WatchUi.requestUpdate();
|
||||
} else {
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.NoInternet) as Lang.String + ".");
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.NoInternet) as Lang.String);
|
||||
}
|
||||
mMenuStatus = WatchUi.loadResource($.Rez.Strings.Unavailable) as Lang.String;
|
||||
} else {
|
||||
@ -285,7 +285,7 @@ class HomeAssistantApp extends Application.AppBase {
|
||||
case Communications.BLE_HOST_TIMEOUT:
|
||||
case Communications.BLE_CONNECTION_UNAVAILABLE:
|
||||
// System.println("HomeAssistantApp onReturnUpdateMenuItems() Response Code: BLE_HOST_TIMEOUT or BLE_CONNECTION_UNAVAILABLE, Bluetooth connection severed.");
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.NoPhone) as Lang.String + ".");
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.NoPhone) as Lang.String);
|
||||
break;
|
||||
|
||||
case Communications.BLE_QUEUE_FULL:
|
||||
@ -353,11 +353,11 @@ class HomeAssistantApp extends Application.AppBase {
|
||||
function updateMenuItems() as Void {
|
||||
if (! System.getDeviceSettings().phoneConnected) {
|
||||
// System.println("HomeAssistantApp updateMenuItems(): No Phone connection, skipping API call.");
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.NoPhone) as Lang.String + ".");
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.NoPhone) as Lang.String);
|
||||
setApiStatus(WatchUi.loadResource($.Rez.Strings.Unavailable) as Lang.String);
|
||||
} else if (! System.getDeviceSettings().connectionAvailable) {
|
||||
// System.println("HomeAssistantApp updateMenuItems(): No Internet connection, skipping API call.");
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.NoInternet) as Lang.String + ".");
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.NoInternet) as Lang.String);
|
||||
setApiStatus(WatchUi.loadResource($.Rez.Strings.Unavailable) as Lang.String);
|
||||
} else {
|
||||
if (mItemsToUpdate == null or mTemplates == null) {
|
||||
@ -412,7 +412,7 @@ class HomeAssistantApp extends Application.AppBase {
|
||||
case Communications.BLE_CONNECTION_UNAVAILABLE:
|
||||
// System.println("HomeAssistantApp onReturnFetchApiStatus() Response Code: BLE_HOST_TIMEOUT or BLE_CONNECTION_UNAVAILABLE, Bluetooth connection severed.");
|
||||
if (!mIsGlance) {
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.NoPhone) as Lang.String + ".");
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.NoPhone) as Lang.String);
|
||||
}
|
||||
break;
|
||||
|
||||
@ -475,7 +475,7 @@ class HomeAssistantApp extends Application.AppBase {
|
||||
if (mIsGlance) {
|
||||
WatchUi.requestUpdate();
|
||||
} else {
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.NoPhone) as Lang.String + ".");
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.NoPhone) as Lang.String);
|
||||
}
|
||||
} else if (! System.getDeviceSettings().connectionAvailable) {
|
||||
// System.println("HomeAssistantApp fetchApiStatus(): No Internet connection, skipping API call.");
|
||||
@ -483,7 +483,7 @@ class HomeAssistantApp extends Application.AppBase {
|
||||
if (mIsGlance) {
|
||||
WatchUi.requestUpdate();
|
||||
} else {
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.NoInternet) as Lang.String + ".");
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.NoInternet) as Lang.String);
|
||||
}
|
||||
} else {
|
||||
Communications.makeWebRequest(
|
||||
|
@ -36,30 +36,30 @@ class PinDigit extends WatchUi.Selectable {
|
||||
x += marginX + HomeAssistantPinConfirmationView.MARGIN_X;
|
||||
var y = (digit == 0) ? stepY * 4 : (digit <= 3) ? stepY : (digit <=6) ? stepY * 2 : stepY * 3; // layout '0' in bottom row (5), others top to bottom in 3 rows (2-4) (row 1 is reserved for masked pin)
|
||||
y += marginY;
|
||||
var width = stepX - (marginX * 2);
|
||||
var width = stepX - (marginX * 2);
|
||||
var height = stepY - (marginY * 2);
|
||||
|
||||
var button = new PinDigitButton({
|
||||
:width=>width,
|
||||
:height=>height,
|
||||
:label=>digit
|
||||
:width => width,
|
||||
:height => height,
|
||||
:label => digit
|
||||
});
|
||||
|
||||
var buttonTouched = new PinDigitButton({
|
||||
:width=>width,
|
||||
:height=>height,
|
||||
:label=>digit,
|
||||
:touched=>true
|
||||
:width => width,
|
||||
:height => height,
|
||||
:label => digit,
|
||||
:touched => true
|
||||
});
|
||||
|
||||
// initialize selectable
|
||||
Selectable.initialize({
|
||||
:stateDefault=>button,
|
||||
:stateHighlighted=>buttonTouched,
|
||||
:locX =>x,
|
||||
:locY=>y,
|
||||
:width=>width,
|
||||
:height=>height
|
||||
:stateDefault => button,
|
||||
:stateHighlighted => buttonTouched,
|
||||
:locX => x,
|
||||
:locY => y,
|
||||
:width => width,
|
||||
:height => height
|
||||
});
|
||||
|
||||
mDigit = digit;
|
||||
@ -71,12 +71,12 @@ class PinDigit extends WatchUi.Selectable {
|
||||
}
|
||||
|
||||
class PinDigitButton extends WatchUi.Drawable {
|
||||
private var mText as Number;
|
||||
private var mText as Number;
|
||||
private var mTouched as Boolean = false;
|
||||
|
||||
function initialize(options) {
|
||||
Drawable.initialize(options);
|
||||
mText = options.get(:label);
|
||||
mText = options.get(:label);
|
||||
mTouched = options.get(:touched);
|
||||
}
|
||||
|
||||
|
@ -51,7 +51,7 @@ class HomeAssistantService {
|
||||
case Communications.BLE_HOST_TIMEOUT:
|
||||
case Communications.BLE_CONNECTION_UNAVAILABLE:
|
||||
// System.println("HomeAssistantService onReturnCall() Response Code: BLE_HOST_TIMEOUT or BLE_CONNECTION_UNAVAILABLE, Bluetooth connection severed.");
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.NoPhone) as Lang.String + ".");
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.NoPhone) as Lang.String);
|
||||
break;
|
||||
|
||||
case Communications.BLE_QUEUE_FULL:
|
||||
@ -113,10 +113,10 @@ class HomeAssistantService {
|
||||
) as Void {
|
||||
if (! System.getDeviceSettings().phoneConnected) {
|
||||
// System.println("HomeAssistantService call(): No Phone connection, skipping API call.");
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.NoPhone) as Lang.String + ".");
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.NoPhone) as Lang.String);
|
||||
} else if (! System.getDeviceSettings().connectionAvailable) {
|
||||
// System.println("HomeAssistantService call(): No Internet connection, skipping API call.");
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.NoInternet) as Lang.String + ".");
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.NoInternet) as Lang.String);
|
||||
} else {
|
||||
// Can't use null for substring() parameters due to API version level.
|
||||
var url = Settings.getApiUrl() + "/services/" + service.substring(0, service.find(".")) + "/" + service.substring(service.find(".")+1, service.length());
|
||||
|
@ -124,7 +124,7 @@ class HomeAssistantToggleMenuItem extends WatchUi.ToggleMenuItem {
|
||||
case Communications.BLE_HOST_TIMEOUT:
|
||||
case Communications.BLE_CONNECTION_UNAVAILABLE:
|
||||
// System.println("HomeAssistantToggleMenuItem onReturnSetState() Response Code: BLE_HOST_TIMEOUT or BLE_CONNECTION_UNAVAILABLE, Bluetooth connection severed.");
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.NoPhone) as Lang.String + ".");
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.NoPhone) as Lang.String);
|
||||
break;
|
||||
|
||||
case Communications.BLE_QUEUE_FULL:
|
||||
@ -175,11 +175,11 @@ class HomeAssistantToggleMenuItem extends WatchUi.ToggleMenuItem {
|
||||
setEnabled(!isEnabled());
|
||||
if (! System.getDeviceSettings().phoneConnected) {
|
||||
// System.println("HomeAssistantToggleMenuItem getState(): No Phone connection, skipping API call.");
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.NoPhone) as Lang.String + ".");
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.NoPhone) as Lang.String);
|
||||
} else if (! System.getDeviceSettings().connectionAvailable) {
|
||||
// System.println("HomeAssistantToggleMenuItem getState(): No Internet connection, skipping API call.");
|
||||
// Toggle the UI back
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.NoInternet) as Lang.String + ".");
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.NoInternet) as Lang.String);
|
||||
} else {
|
||||
// Updated SDK and got a new error
|
||||
// ERROR: venu: Cannot find symbol ':substring' on type 'PolyType<Null or $.Toybox.Lang.Object>'.
|
||||
@ -242,5 +242,4 @@ class HomeAssistantToggleMenuItem extends WatchUi.ToggleMenuItem {
|
||||
setState(b);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -30,8 +30,7 @@ class HomeAssistantView extends WatchUi.Menu2 {
|
||||
definition as Lang.Dictionary,
|
||||
options as {
|
||||
:focus as Lang.Number,
|
||||
:icon as Graphics.BitmapType or WatchUi.Drawable or Lang.Symbol,
|
||||
:theme as WatchUi.MenuTheme or Null
|
||||
:icon as Graphics.BitmapType or WatchUi.Drawable or Lang.Symbol
|
||||
} or Null
|
||||
) {
|
||||
if (options == null) {
|
||||
@ -56,7 +55,7 @@ class HomeAssistantView extends WatchUi.Menu2 {
|
||||
if (tap_action != null) {
|
||||
service = tap_action.get("service");
|
||||
confirm = tap_action.get("confirm"); // Optional
|
||||
pin = tap_action.get("pin"); // Optional
|
||||
pin = tap_action.get("pin"); // Optional
|
||||
data = tap_action.get("data"); // Optional
|
||||
if (confirm == null) {
|
||||
confirm = false;
|
||||
|
@ -34,7 +34,7 @@ class WebhookManager {
|
||||
case Communications.BLE_HOST_TIMEOUT:
|
||||
case Communications.BLE_CONNECTION_UNAVAILABLE:
|
||||
// System.println("WebhookManager onReturnRequestWebhookId() Response Code: BLE_HOST_TIMEOUT or BLE_CONNECTION_UNAVAILABLE, Bluetooth connection severed.");
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.WebhookFailed) as Lang.String + "\n" + WatchUi.loadResource($.Rez.Strings.NoPhone) as Lang.String + ".");
|
||||
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:
|
||||
@ -73,7 +73,7 @@ class WebhookManager {
|
||||
} else {
|
||||
// System.println("WebhookManager onReturnRequestWebhookId(): No webhook id in response data.");
|
||||
Settings.unsetIsSensorsLevelEnabled();
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.WebhookFailed) as Lang.String);
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.WebhookFailed) as Lang.String + ".");
|
||||
}
|
||||
break;
|
||||
|
||||
@ -121,7 +121,7 @@ class WebhookManager {
|
||||
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 + ".");
|
||||
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:
|
||||
@ -173,7 +173,7 @@ class WebhookManager {
|
||||
// System.println("WebhookManager onReturnRegisterWebhookSensor(): Failure, no 'success'.");
|
||||
Settings.unsetWebhookId();
|
||||
Settings.unsetIsSensorsLevelEnabled();
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.WebhookFailed) as Lang.String);
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.WebhookFailed) as Lang.String + ".");
|
||||
}
|
||||
} else {
|
||||
// !! Speculative code for an application crash !!
|
||||
|
Reference in New Issue
Block a user