Removed Debug

On some devices it looks like removing the System.println() statements from inside an 'if' clause whose condition is a constant (static constant Globals.scDebug) makes a memory saving. This would suggest the compiler does not propagate constants and prune unreachable code. However in the device of greatest interest debug removal has made no difference to the memory usage. Here the conditional clauses have been turned into comments that can be removed on a case-by-case basis otherwise the debug printing is too voluminous anyway.
This commit is contained in:
Philip Abbey
2024-01-21 17:53:37 +00:00
parent 62b8f0fccf
commit d9ecaf34ee
12 changed files with 173 additions and 403 deletions

View File

@ -32,22 +32,16 @@ class BackgroundServiceDelegate extends System.ServiceDelegate {
} }
function onReturnBatteryUpdate(responseCode as Lang.Number, data as Null or Lang.Dictionary or Lang.String) as Void { function onReturnBatteryUpdate(responseCode as Lang.Number, data as Null or Lang.Dictionary or Lang.String) as Void {
if (Globals.scDebug) { // System.println("BackgroundServiceDelegate onReturnBatteryUpdate() Response Code: " + responseCode);
System.println("BackgroundServiceDelegate onReturnBatteryUpdate() Response Code: " + responseCode); // System.println("BackgroundServiceDelegate onReturnBatteryUpdate() Response Data: " + data);
System.println("BackgroundServiceDelegate onReturnBatteryUpdate() Response Data: " + data);
}
Background.exit(null); Background.exit(null);
} }
function onTemporalEvent() as Void { function onTemporalEvent() as Void {
if (! System.getDeviceSettings().phoneConnected) { if (! System.getDeviceSettings().phoneConnected) {
if (Globals.scDebug) { // System.println("BackgroundServiceDelegate onTemporalEvent(): No Phone connection, skipping API call.");
System.println("BackgroundServiceDelegate onTemporalEvent(): No Phone connection, skipping API call.");
}
} else if (! System.getDeviceSettings().connectionAvailable) { } else if (! System.getDeviceSettings().connectionAvailable) {
if (Globals.scDebug) { // System.println("BackgroundServiceDelegate onTemporalEvent(): No Internet connection, skipping API call.");
System.println("BackgroundServiceDelegate onTemporalEvent(): No Internet connection, skipping API call.");
}
} else { } else {
// Don't use Settings.* here as the object lasts < 30 secs and is recreated each time the background service is run // Don't use Settings.* here as the object lasts < 30 secs and is recreated each time the background service is run
Communications.makeWebRequest( Communications.makeWebRequest(

View File

@ -22,9 +22,6 @@ using Toybox.Lang;
(:glance) (:glance)
class Globals { class Globals {
// Enable printing of messages to the debug console (don't make this a Property
// as the messages can't be read from a watch!)
static const scDebug = false;
static const scAlertTimeout = 2000; // ms static const scAlertTimeout = 2000; // ms
static const scTapTimeout = 1000; // ms static const scTapTimeout = 1000; // ms
// Time to let the existing HTTP responses get serviced after a // Time to let the existing HTTP responses get serviced after a
@ -34,5 +31,5 @@ class Globals {
// an ErrorView. // 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. // Warn the user after fetching the menu if their watch is low on memory before the device crashes.
static const scLowMem = 0.95; // percent as a fraction. static const scLowMem = 0.90; // percent as a fraction.
} }

View File

@ -32,8 +32,9 @@ class HomeAssistantApp extends Application.AppBase {
private var mHaMenu as HomeAssistantView or Null; private var mHaMenu as HomeAssistantView or Null;
private var mQuitTimer as QuitTimer or Null; private var mQuitTimer as QuitTimer or Null;
private var mTimer as Timer.Timer or Null; private var mTimer as Timer.Timer or Null;
private var mItemsToUpdate as Lang.Array<HomeAssistantToggleMenuItem or HomeAssistantTemplateMenuItem> or Null; // Array initialised by onReturnFetchMenuConfig() // Array initialised by onReturnFetchMenuConfig()
private var mNextItemToUpdate as Lang.Number = 0; // Index into the above array private var mItemsToUpdate as Lang.Array<HomeAssistantToggleMenuItem or HomeAssistantTemplateMenuItem> or Null;
private var mNextItemToUpdate as Lang.Number = 0; // Index into the above array
private var mIsGlance as Lang.Boolean = false; private var mIsGlance as Lang.Boolean = false;
private var mIsApp as Lang.Boolean = false; // Or Widget private var mIsApp as Lang.Boolean = false; // Or Widget
@ -94,34 +95,22 @@ class HomeAssistantApp extends Application.AppBase {
Settings.update(); Settings.update();
if (Settings.getApiKey().length() == 0) { if (Settings.getApiKey().length() == 0) {
if (Globals.scDebug) { // System.println("HomeAssistantApp getInitialView(): No API key in the application Settings.");
System.println("HomeAssistantApp getInitialView(): No API key in the application Settings.");
}
return ErrorView.create(RezStrings.getNoApiKey() + "."); return ErrorView.create(RezStrings.getNoApiKey() + ".");
} else if (Settings.getApiUrl().length() == 0) { } else if (Settings.getApiUrl().length() == 0) {
if (Globals.scDebug) { // System.println("HomeAssistantApp getInitialView(): No API URL in the application Settings.");
System.println("HomeAssistantApp getInitialView(): No API URL in the application Settings.");
}
return ErrorView.create(RezStrings.getNoApiUrl() + "."); return ErrorView.create(RezStrings.getNoApiUrl() + ".");
} else if (Settings.getApiUrl().substring(-1, Settings.getApiUrl().length()).equals("/")) { } else if (Settings.getApiUrl().substring(-1, Settings.getApiUrl().length()).equals("/")) {
if (Globals.scDebug) { // System.println("HomeAssistantApp getInitialView(): API URL must not have a trailing slash '/'.");
System.println("HomeAssistantApp getInitialView(): API URL must not have a trailing slash '/'.");
}
return ErrorView.create(RezStrings.getTrailingSlashErr() + "."); return ErrorView.create(RezStrings.getTrailingSlashErr() + ".");
} else if (Settings.getConfigUrl().length() == 0) { } else if (Settings.getConfigUrl().length() == 0) {
if (Globals.scDebug) { // System.println("HomeAssistantApp getInitialView(): No configuration URL in the application settings.");
System.println("HomeAssistantApp getInitialView(): No configuration URL in the application settings.");
}
return ErrorView.create(RezStrings.getNoConfigUrl() + "."); return ErrorView.create(RezStrings.getNoConfigUrl() + ".");
} else if (! System.getDeviceSettings().phoneConnected) { } else if (! System.getDeviceSettings().phoneConnected) {
if (Globals.scDebug) { // System.println("HomeAssistantApp fetchMenuConfig(): No Phone connection, skipping API call.");
System.println("HomeAssistantApp fetchMenuConfig(): No Phone connection, skipping API call.");
}
return ErrorView.create(RezStrings.getNoPhone() + "."); return ErrorView.create(RezStrings.getNoPhone() + ".");
} else if (! System.getDeviceSettings().connectionAvailable) { } else if (! System.getDeviceSettings().connectionAvailable) {
if (Globals.scDebug) { // System.println("HomeAssistantApp fetchMenuConfig(): No Internet connection, skipping API call.");
System.println("HomeAssistantApp fetchMenuConfig(): No Internet connection, skipping API call.");
}
return ErrorView.create(RezStrings.getNoInternet() + "."); return ErrorView.create(RezStrings.getNoInternet() + ".");
} else { } else {
var isCached = fetchMenuConfig(); var isCached = fetchMenuConfig();
@ -142,54 +131,42 @@ class HomeAssistantApp extends Application.AppBase {
// //
(:glance) (:glance)
function onReturnFetchMenuConfig(responseCode as Lang.Number, data as Null or Lang.Dictionary or Lang.String) as Void { function onReturnFetchMenuConfig(responseCode as Lang.Number, data as Null or Lang.Dictionary or Lang.String) as Void {
if (Globals.scDebug) { // System.println("HomeAssistantApp onReturnFetchMenuConfig() Response Code: " + responseCode);
System.println("HomeAssistantApp onReturnFetchMenuConfig() Response Code: " + responseCode); // System.println("HomeAssistantApp onReturnFetchMenuConfig() Response Data: " + data);
System.println("HomeAssistantApp onReturnFetchMenuConfig() Response Data: " + data);
}
mMenuStatus = RezStrings.getUnavailable(); mMenuStatus = RezStrings.getUnavailable();
switch (responseCode) { switch (responseCode) {
case Communications.BLE_HOST_TIMEOUT: case Communications.BLE_HOST_TIMEOUT:
case Communications.BLE_CONNECTION_UNAVAILABLE: case Communications.BLE_CONNECTION_UNAVAILABLE:
if (Globals.scDebug) { // System.println("HomeAssistantApp onReturnFetchMenuConfig() Response Code: BLE_HOST_TIMEOUT or BLE_CONNECTION_UNAVAILABLE, Bluetooth connection severed.");
System.println("HomeAssistantApp onReturnFetchMenuConfig() Response Code: BLE_HOST_TIMEOUT or BLE_CONNECTION_UNAVAILABLE, Bluetooth connection severed.");
}
if (!mIsGlance) { if (!mIsGlance) {
ErrorView.show(RezStrings.getNoPhone() + "."); ErrorView.show(RezStrings.getNoPhone() + ".");
} }
break; break;
case Communications.BLE_QUEUE_FULL: case Communications.BLE_QUEUE_FULL:
if (Globals.scDebug) { // System.println("HomeAssistantApp onReturnFetchMenuConfig() Response Code: BLE_QUEUE_FULL, API calls too rapid.");
System.println("HomeAssistantApp onReturnFetchMenuConfig() Response Code: BLE_QUEUE_FULL, API calls too rapid.");
}
if (!mIsGlance) { if (!mIsGlance) {
ErrorView.show(RezStrings.getApiFlood()); ErrorView.show(RezStrings.getApiFlood());
} }
break; break;
case Communications.NETWORK_REQUEST_TIMED_OUT: case Communications.NETWORK_REQUEST_TIMED_OUT:
if (Globals.scDebug) { // System.println("HomeAssistantApp onReturnFetchMenuConfig() Response Code: NETWORK_REQUEST_TIMED_OUT, check Internet connection.");
System.println("HomeAssistantApp onReturnFetchMenuConfig() Response Code: NETWORK_REQUEST_TIMED_OUT, check Internet connection.");
}
if (!mIsGlance) { if (!mIsGlance) {
ErrorView.show(RezStrings.getNoResponse()); ErrorView.show(RezStrings.getNoResponse());
} }
break; break;
case Communications.INVALID_HTTP_BODY_IN_NETWORK_RESPONSE: case Communications.INVALID_HTTP_BODY_IN_NETWORK_RESPONSE:
if (Globals.scDebug) { // System.println("HomeAssistantApp onReturnFetchMenuConfig() Response Code: INVALID_HTTP_BODY_IN_NETWORK_RESPONSE, check JSON is returned.");
System.println("HomeAssistantApp onReturnFetchMenuConfig() Response Code: INVALID_HTTP_BODY_IN_NETWORK_RESPONSE, check JSON is returned.");
}
if (!mIsGlance) { if (!mIsGlance) {
ErrorView.show(RezStrings.getNoJson()); ErrorView.show(RezStrings.getNoJson());
} }
break; break;
case 404: case 404:
if (Globals.scDebug) { // System.println("HomeAssistantApp onReturnFetchMenuConfig() Response Code: 404, page not found. Check Configuration URL setting.");
System.println("HomeAssistantApp onReturnFetchMenuConfig() Response Code: 404, page not found. Check Configuration URL setting.");
}
if (!mIsGlance) { if (!mIsGlance) {
ErrorView.show(RezStrings.getConfigUrlNotFound()); ErrorView.show(RezStrings.getConfigUrlNotFound());
} }
@ -211,9 +188,7 @@ class HomeAssistantApp extends Application.AppBase {
break; break;
default: default:
if (Globals.scDebug) { // System.println("HomeAssistantApp onReturnFetchMenuConfig(): Unhandled HTTP response code = " + responseCode);
System.println("HomeAssistantApp onReturnFetchMenuConfig(): Unhandled HTTP response code = " + responseCode);
}
if (!mIsGlance) { if (!mIsGlance) {
ErrorView.show(RezStrings.getUnhandledHttpErr() + responseCode); ErrorView.show(RezStrings.getUnhandledHttpErr() + responseCode);
} }
@ -238,9 +213,7 @@ class HomeAssistantApp extends Application.AppBase {
} }
if (menu == null) { if (menu == null) {
if (! System.getDeviceSettings().phoneConnected) { if (! System.getDeviceSettings().phoneConnected) {
if (Globals.scDebug) { // System.println("HomeAssistantToggleMenuItem getState(): No Phone connection, skipping API call.");
System.println("HomeAssistantToggleMenuItem getState(): No Phone connection, skipping API call.");
}
if (mIsGlance) { if (mIsGlance) {
WatchUi.requestUpdate(); WatchUi.requestUpdate();
} else { } else {
@ -248,9 +221,7 @@ class HomeAssistantApp extends Application.AppBase {
} }
mMenuStatus = RezStrings.getUnavailable(); mMenuStatus = RezStrings.getUnavailable();
} else if (! System.getDeviceSettings().connectionAvailable) { } else if (! System.getDeviceSettings().connectionAvailable) {
if (Globals.scDebug) { // System.println("HomeAssistantToggleMenuItem getState(): No Internet connection, skipping API call.");
System.println("HomeAssistantToggleMenuItem getState(): No Internet connection, skipping API call.");
}
if (mIsGlance) { if (mIsGlance) {
WatchUi.requestUpdate(); WatchUi.requestUpdate();
} else { } else {
@ -301,54 +272,42 @@ class HomeAssistantApp extends Application.AppBase {
// //
(:glance) (:glance)
function onReturnFetchApiStatus(responseCode as Lang.Number, data as Null or Lang.Dictionary or Lang.String) as Void { function onReturnFetchApiStatus(responseCode as Lang.Number, data as Null or Lang.Dictionary or Lang.String) as Void {
if (Globals.scDebug) { // System.println("HomeAssistantApp onReturnFetchApiStatus() Response Code: " + responseCode);
System.println("HomeAssistantApp onReturnFetchApiStatus() Response Code: " + responseCode); // System.println("HomeAssistantApp onReturnFetchApiStatus() Response Data: " + data);
System.println("HomeAssistantApp onReturnFetchApiStatus() Response Data: " + data);
}
mApiStatus = RezStrings.getUnavailable(); mApiStatus = RezStrings.getUnavailable();
switch (responseCode) { switch (responseCode) {
case Communications.BLE_HOST_TIMEOUT: case Communications.BLE_HOST_TIMEOUT:
case Communications.BLE_CONNECTION_UNAVAILABLE: case Communications.BLE_CONNECTION_UNAVAILABLE:
if (Globals.scDebug) { // System.println("HomeAssistantApp onReturnFetchApiStatus() Response Code: BLE_HOST_TIMEOUT or BLE_CONNECTION_UNAVAILABLE, Bluetooth connection severed.");
System.println("HomeAssistantApp onReturnFetchApiStatus() Response Code: BLE_HOST_TIMEOUT or BLE_CONNECTION_UNAVAILABLE, Bluetooth connection severed.");
}
if (!mIsGlance) { if (!mIsGlance) {
ErrorView.show(RezStrings.getNoPhone() + "."); ErrorView.show(RezStrings.getNoPhone() + ".");
} }
break; break;
case Communications.BLE_QUEUE_FULL: case Communications.BLE_QUEUE_FULL:
if (Globals.scDebug) { // System.println("HomeAssistantApp onReturnFetchApiStatus() Response Code: BLE_QUEUE_FULL, API calls too rapid.");
System.println("HomeAssistantApp onReturnFetchApiStatus() Response Code: BLE_QUEUE_FULL, API calls too rapid.");
}
if (!mIsGlance) { if (!mIsGlance) {
ErrorView.show(RezStrings.getApiFlood()); ErrorView.show(RezStrings.getApiFlood());
} }
break; break;
case Communications.NETWORK_REQUEST_TIMED_OUT: case Communications.NETWORK_REQUEST_TIMED_OUT:
if (Globals.scDebug) { // System.println("HomeAssistantApp onReturnFetchApiStatus() Response Code: NETWORK_REQUEST_TIMED_OUT, check Internet connection.");
System.println("HomeAssistantApp onReturnFetchApiStatus() Response Code: NETWORK_REQUEST_TIMED_OUT, check Internet connection.");
}
if (!mIsGlance) { if (!mIsGlance) {
ErrorView.show(RezStrings.getNoResponse()); ErrorView.show(RezStrings.getNoResponse());
} }
break; break;
case Communications.INVALID_HTTP_BODY_IN_NETWORK_RESPONSE: case Communications.INVALID_HTTP_BODY_IN_NETWORK_RESPONSE:
if (Globals.scDebug) { // System.println("HomeAssistantApp onReturnFetchApiStatus() Response Code: INVALID_HTTP_BODY_IN_NETWORK_RESPONSE, check JSON is returned.");
System.println("HomeAssistantApp onReturnFetchApiStatus() Response Code: INVALID_HTTP_BODY_IN_NETWORK_RESPONSE, check JSON is returned.");
}
if (!mIsGlance) { if (!mIsGlance) {
ErrorView.show(RezStrings.getNoJson()); ErrorView.show(RezStrings.getNoJson());
} }
break; break;
case 404: case 404:
if (Globals.scDebug) { // System.println("HomeAssistantApp onReturnFetchApiStatus() Response Code: 404, page not found. Check Configuration URL setting.");
System.println("HomeAssistantApp onReturnFetchApiStatus() Response Code: 404, page not found. Check Configuration URL setting.");
}
if (!mIsGlance) { if (!mIsGlance) {
ErrorView.show(RezStrings.getConfigUrlNotFound()); ErrorView.show(RezStrings.getConfigUrlNotFound());
} }
@ -369,9 +328,7 @@ class HomeAssistantApp extends Application.AppBase {
break; break;
default: default:
if (Globals.scDebug) { // System.println("HomeAssistantApp onReturnFetchApiStatus(): Unhandled HTTP response code = " + responseCode);
System.println("HomeAssistantApp onReturnFetchApiStatus(): Unhandled HTTP response code = " + responseCode);
}
if (!mIsGlance) { if (!mIsGlance) {
ErrorView.show(RezStrings.getUnhandledHttpErr() + responseCode); ErrorView.show(RezStrings.getUnhandledHttpErr() + responseCode);
} }
@ -386,9 +343,7 @@ class HomeAssistantApp extends Application.AppBase {
WatchUi.requestUpdate(); WatchUi.requestUpdate();
} else { } else {
if (! System.getDeviceSettings().phoneConnected) { if (! System.getDeviceSettings().phoneConnected) {
if (Globals.scDebug) { // System.println("HomeAssistantToggleMenuItem getState(): No Phone connection, skipping API call.");
System.println("HomeAssistantToggleMenuItem getState(): No Phone connection, skipping API call.");
}
mApiStatus = RezStrings.getUnavailable(); mApiStatus = RezStrings.getUnavailable();
if (mIsGlance) { if (mIsGlance) {
WatchUi.requestUpdate(); WatchUi.requestUpdate();
@ -396,9 +351,7 @@ class HomeAssistantApp extends Application.AppBase {
ErrorView.show(RezStrings.getNoPhone() + "."); ErrorView.show(RezStrings.getNoPhone() + ".");
} }
} else if (! System.getDeviceSettings().connectionAvailable) { } else if (! System.getDeviceSettings().connectionAvailable) {
if (Globals.scDebug) { // System.println("HomeAssistantToggleMenuItem getState(): No Internet connection, skipping API call.");
System.println("HomeAssistantToggleMenuItem getState(): No Internet connection, skipping API call.");
}
mApiStatus = RezStrings.getUnavailable(); mApiStatus = RezStrings.getUnavailable();
if (mIsGlance) { if (mIsGlance) {
WatchUi.requestUpdate(); WatchUi.requestUpdate();
@ -449,9 +402,7 @@ class HomeAssistantApp extends Application.AppBase {
function updateNextMenuItem() as Void { function updateNextMenuItem() as Void {
var itu = mItemsToUpdate as Lang.Array<HomeAssistantToggleMenuItem>; var itu = mItemsToUpdate as Lang.Array<HomeAssistantToggleMenuItem>;
if (itu == null) { if (itu == null) {
if (Globals.scDebug) { // System.println("HomeAssistantApp updateNextMenuItem(): No menu items to update");
System.println("HomeAssistantApp updateNextMenuItem(): No menu items to update");
}
if (!mIsGlance) { if (!mIsGlance) {
ErrorView.show(RezStrings.getConfigUrlNotFound()); ErrorView.show(RezStrings.getConfigUrlNotFound());
} }
@ -486,9 +437,7 @@ class HomeAssistantApp extends Application.AppBase {
// Replace this functionality with a more central settings class as proposed in // Replace this functionality with a more central settings class as proposed in
// https://github.com/house-of-abbey/GarminHomeAssistant/pull/17. // https://github.com/house-of-abbey/GarminHomeAssistant/pull/17.
function onSettingsChanged() as Void { function onSettingsChanged() as Void {
if (Globals.scDebug) { // System.println("HomeAssistantApp onSettingsChanged()");
System.println("HomeAssistantApp onSettingsChanged()");
}
Settings.update(); Settings.update();
} }

View File

@ -44,58 +44,42 @@ class HomeAssistantService {
context as Lang.Object context as Lang.Object
) as Void { ) as Void {
var entity_id = context as Lang.String or Null; var entity_id = context as Lang.String or Null;
if (Globals.scDebug) { // System.println("HomeAssistantService onReturnCall() Response Code: " + responseCode);
System.println("HomeAssistantService onReturnCall() Response Code: " + responseCode); // System.println("HomeAssistantService onReturnCall() Response Data: " + data);
System.println("HomeAssistantService onReturnCall() Response Data: " + data);
}
switch (responseCode) { switch (responseCode) {
case Communications.BLE_HOST_TIMEOUT: case Communications.BLE_HOST_TIMEOUT:
case Communications.BLE_CONNECTION_UNAVAILABLE: case Communications.BLE_CONNECTION_UNAVAILABLE:
if (Globals.scDebug) { // System.println("HomeAssistantService onReturnCall() Response Code: BLE_HOST_TIMEOUT or BLE_CONNECTION_UNAVAILABLE, Bluetooth connection severed.");
System.println("HomeAssistantService onReturnCall() Response Code: BLE_HOST_TIMEOUT or BLE_CONNECTION_UNAVAILABLE, Bluetooth connection severed.");
}
ErrorView.show(RezStrings.getNoPhone() + "."); ErrorView.show(RezStrings.getNoPhone() + ".");
break; break;
case Communications.BLE_QUEUE_FULL: case Communications.BLE_QUEUE_FULL:
if (Globals.scDebug) { // System.println("HomeAssistantService onReturnCall() Response Code: BLE_QUEUE_FULL, API calls too rapid.");
System.println("HomeAssistantService onReturnCall() Response Code: BLE_QUEUE_FULL, API calls too rapid.");
}
ErrorView.show(RezStrings.getApiFlood()); ErrorView.show(RezStrings.getApiFlood());
break; break;
case Communications.NETWORK_REQUEST_TIMED_OUT: case Communications.NETWORK_REQUEST_TIMED_OUT:
if (Globals.scDebug) { // System.println("HomeAssistantService onReturnCall() Response Code: NETWORK_REQUEST_TIMED_OUT, check Internet connection.");
System.println("HomeAssistantService onReturnCall() Response Code: NETWORK_REQUEST_TIMED_OUT, check Internet connection.");
}
ErrorView.show(RezStrings.getNoResponse()); ErrorView.show(RezStrings.getNoResponse());
break; break;
case Communications.NETWORK_RESPONSE_OUT_OF_MEMORY: case Communications.NETWORK_RESPONSE_OUT_OF_MEMORY:
if (Globals.scDebug) { // System.println("HomeAssistantService onReturnCall() Response Code: NETWORK_RESPONSE_OUT_OF_MEMORY, are we going too fast?");
System.println("HomeAssistantService onReturnCall() Response Code: NETWORK_RESPONSE_OUT_OF_MEMORY, are we going too fast?");
}
// Ignore and see if we can carry on // Ignore and see if we can carry on
break; break;
case Communications.INVALID_HTTP_BODY_IN_NETWORK_RESPONSE: case Communications.INVALID_HTTP_BODY_IN_NETWORK_RESPONSE:
if (Globals.scDebug) { // System.println("HomeAssistantService onReturnCall() Response Code: INVALID_HTTP_BODY_IN_NETWORK_RESPONSE, check JSON is returned.");
System.println("HomeAssistantService onReturnCall() Response Code: INVALID_HTTP_BODY_IN_NETWORK_RESPONSE, check JSON is returned.");
}
ErrorView.show(RezStrings.getNoJson()); ErrorView.show(RezStrings.getNoJson());
break; break;
case 404: case 404:
if (Globals.scDebug) { // System.println("HomeAssistantService onReturnCall() Response Code: 404, page not found. Check API URL setting.");
System.println("HomeAssistantService onReturnCall() Response Code: 404, page not found. Check API URL setting.");
}
ErrorView.show(RezStrings.getApiUrlNotFound()); ErrorView.show(RezStrings.getApiUrlNotFound());
break; break;
case 200: case 200:
if (Globals.scDebug) { // System.println("HomeAssistantService onReturnCall(): Service executed.");
System.println("HomeAssistantService onReturnCall(): Service executed.");
}
var d = data as Lang.Array; var d = data as Lang.Array;
var toast = RezStrings.getExecuted(); var toast = RezStrings.getExecuted();
for(var i = 0; i < d.size(); i++) { for(var i = 0; i < d.size(); i++) {
@ -117,9 +101,7 @@ class HomeAssistantService {
break; break;
default: default:
if (Globals.scDebug) { // System.println("HomeAssistantService onReturnCall(): Unhandled HTTP response code = " + responseCode);
System.println("HomeAssistantService onReturnCall(): Unhandled HTTP response code = " + responseCode);
}
ErrorView.show(RezStrings.getUnhandledHttpErr() + responseCode); ErrorView.show(RezStrings.getUnhandledHttpErr() + responseCode);
} }
} }
@ -129,22 +111,16 @@ class HomeAssistantService {
data as Lang.Dictionary or Null data as Lang.Dictionary or Null
) as Void { ) as Void {
if (! System.getDeviceSettings().phoneConnected) { if (! System.getDeviceSettings().phoneConnected) {
if (Globals.scDebug) { // System.println("HomeAssistantService call(): No Phone connection, skipping API call.");
System.println("HomeAssistantService call(): No Phone connection, skipping API call.");
}
ErrorView.show(RezStrings.getNoPhone() + "."); ErrorView.show(RezStrings.getNoPhone() + ".");
} else if (! System.getDeviceSettings().connectionAvailable) { } else if (! System.getDeviceSettings().connectionAvailable) {
if (Globals.scDebug) { // System.println("HomeAssistantService call(): No Internet connection, skipping API call.");
System.println("HomeAssistantService call(): No Internet connection, skipping API call.");
}
ErrorView.show(RezStrings.getNoInternet() + "."); ErrorView.show(RezStrings.getNoInternet() + ".");
} else { } else {
// Can't use null for substring() parameters due to API version level. // 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()); var url = Settings.getApiUrl() + "/services/" + service.substring(0, service.find(".")) + "/" + service.substring(service.find(".")+1, service.length());
if (Globals.scDebug) { // System.println("HomeAssistantService call() URL=" + url);
System.println("HomeAssistantService call() URL=" + url); // System.println("HomeAssistantService call() service=" + service);
System.println("HomeAssistantService call() service=" + service);
}
var entity_id = data.get("entity_id"); var entity_id = data.get("entity_id");
if (entity_id == null) { if (entity_id == null) {

View File

@ -84,46 +84,34 @@ class HomeAssistantTemplateMenuItem extends WatchUi.IconMenuItem {
// error. The ErrorView cancellation will resume the call chain. // error. The ErrorView cancellation will resume the call chain.
// //
function onReturnGetState(responseCode as Lang.Number, data as Lang.String) as Void { function onReturnGetState(responseCode as Lang.Number, data as Lang.String) as Void {
if (Globals.scDebug) { // System.println("HomeAssistantTemplateMenuItem onReturnGetState() Response Code: " + responseCode);
System.println("HomeAssistantTemplateMenuItem onReturnGetState() Response Code: " + responseCode); // System.println("HomeAssistantTemplateMenuItem onReturnGetState() Response Data: " + data);
System.println("HomeAssistantTemplateMenuItem onReturnGetState() Response Data: " + data);
}
var status = RezStrings.getUnavailable(); var status = RezStrings.getUnavailable();
switch (responseCode) { switch (responseCode) {
case Communications.BLE_HOST_TIMEOUT: case Communications.BLE_HOST_TIMEOUT:
case Communications.BLE_CONNECTION_UNAVAILABLE: case Communications.BLE_CONNECTION_UNAVAILABLE:
if (Globals.scDebug) { // System.println("HomeAssistantTemplateMenuItem onReturnGetState() Response Code: BLE_HOST_TIMEOUT or BLE_CONNECTION_UNAVAILABLE, Bluetooth connection severed.");
System.println("HomeAssistantTemplateMenuItem onReturnGetState() Response Code: BLE_HOST_TIMEOUT or BLE_CONNECTION_UNAVAILABLE, Bluetooth connection severed.");
}
ErrorView.show(RezStrings.getNoPhone() + "."); ErrorView.show(RezStrings.getNoPhone() + ".");
break; break;
case Communications.BLE_QUEUE_FULL: case Communications.BLE_QUEUE_FULL:
if (Globals.scDebug) { // System.println("HomeAssistantTemplateMenuItem onReturnGetState() Response Code: BLE_QUEUE_FULL, API calls too rapid.");
System.println("HomeAssistantTemplateMenuItem onReturnGetState() Response Code: BLE_QUEUE_FULL, API calls too rapid.");
}
ErrorView.show(RezStrings.getApiFlood()); ErrorView.show(RezStrings.getApiFlood());
break; break;
case Communications.NETWORK_REQUEST_TIMED_OUT: case Communications.NETWORK_REQUEST_TIMED_OUT:
if (Globals.scDebug) { // System.println("HomeAssistantTemplateMenuItem onReturnGetState() Response Code: NETWORK_REQUEST_TIMED_OUT, check Internet connection.");
System.println("HomeAssistantTemplateMenuItem onReturnGetState() Response Code: NETWORK_REQUEST_TIMED_OUT, check Internet connection.");
}
ErrorView.show(RezStrings.getNoResponse()); ErrorView.show(RezStrings.getNoResponse());
break; break;
case Communications.INVALID_HTTP_BODY_IN_NETWORK_RESPONSE: case Communications.INVALID_HTTP_BODY_IN_NETWORK_RESPONSE:
if (Globals.scDebug) { // System.println("HomeAssistantTemplateMenuItem onReturnGetState() Response Code: INVALID_HTTP_BODY_IN_NETWORK_RESPONSE, check JSON is returned.");
System.println("HomeAssistantTemplateMenuItem onReturnGetState() Response Code: INVALID_HTTP_BODY_IN_NETWORK_RESPONSE, check JSON is returned.");
}
ErrorView.show(RezStrings.getNoJson()); ErrorView.show(RezStrings.getNoJson());
break; break;
case Communications.NETWORK_RESPONSE_OUT_OF_MEMORY: case Communications.NETWORK_RESPONSE_OUT_OF_MEMORY:
if (Globals.scDebug) { // System.println("HomeAssistantTemplateMenuItem onReturnGetState() Response Code: NETWORK_RESPONSE_OUT_OF_MEMORY, are we going too fast?");
System.println("HomeAssistantTemplateMenuItem onReturnGetState() Response Code: NETWORK_RESPONSE_OUT_OF_MEMORY, are we going too fast?");
}
var myTimer = new Timer.Timer(); var myTimer = new Timer.Timer();
// Now this feels very "closely coupled" to the application, but it is the most reliable method instead of using a timer. // Now this feels very "closely coupled" to the application, but it is the most reliable method instead of using a timer.
myTimer.start(getApp().method(:updateNextMenuItem), Globals.scApiBackoff, false); myTimer.start(getApp().method(:updateNextMenuItem), Globals.scApiBackoff, false);
@ -132,16 +120,12 @@ class HomeAssistantTemplateMenuItem extends WatchUi.IconMenuItem {
break; break;
case 404: case 404:
if (Globals.scDebug) { // System.println("HomeAssistantTemplateMenuItem onReturnGetState() Response Code: 404, page not found. Check API URL setting.");
System.println("HomeAssistantTemplateMenuItem onReturnGetState() Response Code: 404, page not found. Check API URL setting.");
}
ErrorView.show(RezStrings.getApiUrlNotFound()); ErrorView.show(RezStrings.getApiUrlNotFound());
break; break;
case 400: case 400:
if (Globals.scDebug) { // System.println("HomeAssistantTemplateMenuItem onReturnGetState() Response Code: 400, bad request. Template error.");
System.println("HomeAssistantTemplateMenuItem onReturnGetState() Response Code: 400, bad request. Template error.");
}
ErrorView.show(RezStrings.getTemplateError()); ErrorView.show(RezStrings.getTemplateError());
break; break;
@ -154,9 +138,7 @@ class HomeAssistantTemplateMenuItem extends WatchUi.IconMenuItem {
break; break;
default: default:
if (Globals.scDebug) { // System.println("HomeAssistantTemplateMenuItem onReturnGetState(): Unhandled HTTP response code = " + responseCode);
System.println("HomeAssistantTemplateMenuItem onReturnGetState(): Unhandled HTTP response code = " + responseCode);
}
ErrorView.show(RezStrings.getUnhandledHttpErr() + responseCode); ErrorView.show(RezStrings.getUnhandledHttpErr() + responseCode);
} }
getApp().setApiStatus(status); getApp().setApiStatus(status);
@ -164,22 +146,16 @@ class HomeAssistantTemplateMenuItem extends WatchUi.IconMenuItem {
function getState() as Void { function getState() as Void {
if (! System.getDeviceSettings().phoneConnected) { if (! System.getDeviceSettings().phoneConnected) {
if (Globals.scDebug) { // System.println("HomeAssistantTemplateMenuItem getState(): No Phone connection, skipping API call.");
System.println("HomeAssistantTemplateMenuItem getState(): No Phone connection, skipping API call.");
}
ErrorView.show(RezStrings.getNoPhone() + "."); ErrorView.show(RezStrings.getNoPhone() + ".");
getApp().setApiStatus(RezStrings.getUnavailable()); getApp().setApiStatus(RezStrings.getUnavailable());
} else if (! System.getDeviceSettings().connectionAvailable) { } else if (! System.getDeviceSettings().connectionAvailable) {
if (Globals.scDebug) { // System.println("HomeAssistantTemplateMenuItem getState(): No Internet connection, skipping API call.");
System.println("HomeAssistantTemplateMenuItem getState(): No Internet connection, skipping API call.");
}
ErrorView.show(RezStrings.getNoInternet() + "."); ErrorView.show(RezStrings.getNoInternet() + ".");
getApp().setApiStatus(RezStrings.getUnavailable()); getApp().setApiStatus(RezStrings.getUnavailable());
} else { } else {
var url = Settings.getApiUrl() + "/template"; var url = Settings.getApiUrl() + "/template";
if (Globals.scDebug) { // System.println("HomeAssistantTemplateMenuItem getState() URL=" + url + ", Template='" + mTemplate + "'");
System.println("HomeAssistantTemplateMenuItem getState() URL=" + url + ", Template='" + mTemplate + "'");
}
Communications.makeWebRequest( Communications.makeWebRequest(
url, url,
{ "template" => mTemplate }, { "template" => mTemplate },

View File

@ -59,46 +59,34 @@ class HomeAssistantToggleMenuItem extends WatchUi.ToggleMenuItem {
// error. The ErrorView cancellation will resume the call chain. // error. The ErrorView cancellation will resume the call chain.
// //
function onReturnGetState(responseCode as Lang.Number, data as Null or Lang.Dictionary or Lang.String) as Void { function onReturnGetState(responseCode as Lang.Number, data as Null or Lang.Dictionary or Lang.String) as Void {
if (Globals.scDebug) { // System.println("HomeAssistantToggleMenuItem onReturnGetState() Response Code: " + responseCode);
System.println("HomeAssistantToggleMenuItem onReturnGetState() Response Code: " + responseCode); // System.println("HomeAssistantToggleMenuItem onReturnGetState() Response Data: " + data);
System.println("HomeAssistantToggleMenuItem onReturnGetState() Response Data: " + data);
}
var status = RezStrings.getUnavailable(); var status = RezStrings.getUnavailable();
switch (responseCode) { switch (responseCode) {
case Communications.BLE_HOST_TIMEOUT: case Communications.BLE_HOST_TIMEOUT:
case Communications.BLE_CONNECTION_UNAVAILABLE: case Communications.BLE_CONNECTION_UNAVAILABLE:
if (Globals.scDebug) { // System.println("HomeAssistantToggleMenuItem onReturnGetState() Response Code: BLE_HOST_TIMEOUT or BLE_CONNECTION_UNAVAILABLE, Bluetooth connection severed.");
System.println("HomeAssistantToggleMenuItem onReturnGetState() Response Code: BLE_HOST_TIMEOUT or BLE_CONNECTION_UNAVAILABLE, Bluetooth connection severed.");
}
ErrorView.show(RezStrings.getNoPhone() + "."); ErrorView.show(RezStrings.getNoPhone() + ".");
break; break;
case Communications.BLE_QUEUE_FULL: case Communications.BLE_QUEUE_FULL:
if (Globals.scDebug) { // System.println("HomeAssistantToggleMenuItem onReturnGetState() Response Code: BLE_QUEUE_FULL, API calls too rapid.");
System.println("HomeAssistantToggleMenuItem onReturnGetState() Response Code: BLE_QUEUE_FULL, API calls too rapid.");
}
ErrorView.show(RezStrings.getApiFlood()); ErrorView.show(RezStrings.getApiFlood());
break; break;
case Communications.NETWORK_REQUEST_TIMED_OUT: case Communications.NETWORK_REQUEST_TIMED_OUT:
if (Globals.scDebug) { // System.println("HomeAssistantToggleMenuItem onReturnGetState() Response Code: NETWORK_REQUEST_TIMED_OUT, check Internet connection.");
System.println("HomeAssistantToggleMenuItem onReturnGetState() Response Code: NETWORK_REQUEST_TIMED_OUT, check Internet connection.");
}
ErrorView.show(RezStrings.getNoResponse()); ErrorView.show(RezStrings.getNoResponse());
break; break;
case Communications.INVALID_HTTP_BODY_IN_NETWORK_RESPONSE: case Communications.INVALID_HTTP_BODY_IN_NETWORK_RESPONSE:
if (Globals.scDebug) { // System.println("HomeAssistantToggleMenuItem onReturnGetState() Response Code: INVALID_HTTP_BODY_IN_NETWORK_RESPONSE, check JSON is returned.");
System.println("HomeAssistantToggleMenuItem onReturnGetState() Response Code: INVALID_HTTP_BODY_IN_NETWORK_RESPONSE, check JSON is returned.");
}
ErrorView.show(RezStrings.getNoJson()); ErrorView.show(RezStrings.getNoJson());
break; break;
case Communications.NETWORK_RESPONSE_OUT_OF_MEMORY: case Communications.NETWORK_RESPONSE_OUT_OF_MEMORY:
if (Globals.scDebug) { // System.println("HomeAssistantToggleMenuItem onReturnGetState() Response Code: NETWORK_RESPONSE_OUT_OF_MEMORY, are we going too fast?");
System.println("HomeAssistantToggleMenuItem onReturnGetState() Response Code: NETWORK_RESPONSE_OUT_OF_MEMORY, are we going too fast?");
}
var myTimer = new Timer.Timer(); var myTimer = new Timer.Timer();
// Now this feels very "closely coupled" to the application, but it is the most reliable method instead of using a timer. // Now this feels very "closely coupled" to the application, but it is the most reliable method instead of using a timer.
myTimer.start(getApp().method(:updateNextMenuItem), Globals.scApiBackoff, false); myTimer.start(getApp().method(:updateNextMenuItem), Globals.scApiBackoff, false);
@ -113,22 +101,16 @@ class HomeAssistantToggleMenuItem extends WatchUi.ToggleMenuItem {
} }
if (msg != null) { if (msg != null) {
// Should be an HTTP 404 according to curl queries // Should be an HTTP 404 according to curl queries
if (Globals.scDebug) { // System.println("HomeAssistantToggleMenuItem onReturnGetState() Response Code: 404. " + mData.get("entity_id") + " " + msg);
System.println("HomeAssistantToggleMenuItem onReturnGetState() Response Code: 404. " + mData.get("entity_id") + " " + msg);
}
ErrorView.show("HTTP 404, " + mData.get("entity_id") + ". " + data.get("message")); ErrorView.show("HTTP 404, " + mData.get("entity_id") + ". " + data.get("message"));
} else { } else {
if (Globals.scDebug) { // System.println("HomeAssistantToggleMenuItem onReturnGetState() Response Code: 404, page not found. Check API URL setting.");
System.println("HomeAssistantToggleMenuItem onReturnGetState() Response Code: 404, page not found. Check API URL setting.");
}
ErrorView.show(RezStrings.getApiUrlNotFound()); ErrorView.show(RezStrings.getApiUrlNotFound());
} }
break; break;
case 405: case 405:
if (Globals.scDebug) { // System.println("HomeAssistantToggleMenuItem onReturnGetState() Response Code: 405. " + mData.get("entity_id") + " " + data.get("message"));
System.println("HomeAssistantToggleMenuItem onReturnGetState() Response Code: 405. " + mData.get("entity_id") + " " + data.get("message"));
}
ErrorView.show("HTTP 405, " + mData.get("entity_id") + ". " + data.get("message")); ErrorView.show("HTTP 405, " + mData.get("entity_id") + ". " + data.get("message"));
break; break;
@ -136,9 +118,7 @@ class HomeAssistantToggleMenuItem extends WatchUi.ToggleMenuItem {
case 200: case 200:
status = RezStrings.getAvailable(); status = RezStrings.getAvailable();
var state = data.get("state") as Lang.String; var state = data.get("state") as Lang.String;
if (Globals.scDebug) { // System.println((data.get("attributes") as Lang.Dictionary).get("friendly_name") + " State=" + state);
System.println((data.get("attributes") as Lang.Dictionary).get("friendly_name") + " State=" + state);
}
if (getLabel().equals("...")) { if (getLabel().equals("...")) {
setLabel((data.get("attributes") as Lang.Dictionary).get("friendly_name") as Lang.String); setLabel((data.get("attributes") as Lang.Dictionary).get("friendly_name") as Lang.String);
} }
@ -148,9 +128,7 @@ class HomeAssistantToggleMenuItem extends WatchUi.ToggleMenuItem {
break; break;
default: default:
if (Globals.scDebug) { // System.println("HomeAssistantToggleMenuItem onReturnGetState(): Unhandled HTTP response code = " + responseCode);
System.println("HomeAssistantToggleMenuItem onReturnGetState(): Unhandled HTTP response code = " + responseCode);
}
ErrorView.show(RezStrings.getUnhandledHttpErr() + responseCode); ErrorView.show(RezStrings.getUnhandledHttpErr() + responseCode);
} }
getApp().setApiStatus(status); getApp().setApiStatus(status);
@ -158,22 +136,16 @@ class HomeAssistantToggleMenuItem extends WatchUi.ToggleMenuItem {
function getState() as Void { function getState() as Void {
if (! System.getDeviceSettings().phoneConnected) { if (! System.getDeviceSettings().phoneConnected) {
if (Globals.scDebug) { // System.println("HomeAssistantToggleMenuItem getState(): No Phone connection, skipping API call.");
System.println("HomeAssistantToggleMenuItem getState(): No Phone connection, skipping API call.");
}
ErrorView.show(RezStrings.getNoPhone() + "."); ErrorView.show(RezStrings.getNoPhone() + ".");
getApp().setApiStatus(RezStrings.getUnavailable()); getApp().setApiStatus(RezStrings.getUnavailable());
} else if (! System.getDeviceSettings().connectionAvailable) { } else if (! System.getDeviceSettings().connectionAvailable) {
if (Globals.scDebug) { // System.println("HomeAssistantToggleMenuItem getState(): No Internet connection, skipping API call.");
System.println("HomeAssistantToggleMenuItem getState(): No Internet connection, skipping API call.");
}
ErrorView.show(RezStrings.getNoInternet() + "."); ErrorView.show(RezStrings.getNoInternet() + ".");
getApp().setApiStatus(RezStrings.getUnavailable()); getApp().setApiStatus(RezStrings.getUnavailable());
} else { } else {
var url = Settings.getApiUrl() + "/states/" + mData.get("entity_id"); var url = Settings.getApiUrl() + "/states/" + mData.get("entity_id");
if (Globals.scDebug) { // System.println("HomeAssistantToggleMenuItem getState() URL=" + url);
System.println("HomeAssistantToggleMenuItem getState() URL=" + url);
}
Communications.makeWebRequest( Communications.makeWebRequest(
url, url,
null, null,
@ -192,46 +164,34 @@ class HomeAssistantToggleMenuItem extends WatchUi.ToggleMenuItem {
// Callback function after completing the POST request to set the status. // Callback function after completing the POST request to set the status.
// //
function onReturnSetState(responseCode as Lang.Number, data as Null or Lang.Dictionary or Lang.String) as Void { function onReturnSetState(responseCode as Lang.Number, data as Null or Lang.Dictionary or Lang.String) as Void {
if (Globals.scDebug) { // System.println("HomeAssistantToggleMenuItem onReturnSetState() Response Code: " + responseCode);
System.println("HomeAssistantToggleMenuItem onReturnSetState() Response Code: " + responseCode); // System.println("HomeAssistantToggleMenuItem onReturnSetState() Response Data: " + data);
System.println("HomeAssistantToggleMenuItem onReturnSetState() Response Data: " + data);
}
var status = RezStrings.getUnavailable(); var status = RezStrings.getUnavailable();
switch (responseCode) { switch (responseCode) {
case Communications.BLE_HOST_TIMEOUT: case Communications.BLE_HOST_TIMEOUT:
case Communications.BLE_CONNECTION_UNAVAILABLE: case Communications.BLE_CONNECTION_UNAVAILABLE:
if (Globals.scDebug) { // System.println("HomeAssistantToggleMenuItem onReturnSetState() Response Code: BLE_HOST_TIMEOUT or BLE_CONNECTION_UNAVAILABLE, Bluetooth connection severed.");
System.println("HomeAssistantToggleMenuItem onReturnSetState() Response Code: BLE_HOST_TIMEOUT or BLE_CONNECTION_UNAVAILABLE, Bluetooth connection severed.");
}
ErrorView.show(RezStrings.getNoPhone() + "."); ErrorView.show(RezStrings.getNoPhone() + ".");
break; break;
case Communications.BLE_QUEUE_FULL: case Communications.BLE_QUEUE_FULL:
if (Globals.scDebug) { // System.println("HomeAssistantToggleMenuItem onReturnSetState() Response Code: BLE_QUEUE_FULL, API calls too rapid.");
System.println("HomeAssistantToggleMenuItem onReturnSetState() Response Code: BLE_QUEUE_FULL, API calls too rapid.");
}
ErrorView.show(RezStrings.getApiFlood()); ErrorView.show(RezStrings.getApiFlood());
break; break;
case Communications.NETWORK_REQUEST_TIMED_OUT: case Communications.NETWORK_REQUEST_TIMED_OUT:
if (Globals.scDebug) { // System.println("HomeAssistantToggleMenuItem onReturnSetState() Response Code: NETWORK_REQUEST_TIMED_OUT, check Internet connection.");
System.println("HomeAssistantToggleMenuItem onReturnSetState() Response Code: NETWORK_REQUEST_TIMED_OUT, check Internet connection.");
}
ErrorView.show(RezStrings.getNoResponse()); ErrorView.show(RezStrings.getNoResponse());
break; break;
case Communications.INVALID_HTTP_BODY_IN_NETWORK_RESPONSE: case Communications.INVALID_HTTP_BODY_IN_NETWORK_RESPONSE:
if (Globals.scDebug) { // System.println("HomeAssistantToggleMenuItem onReturnSetState() Response Code: INVALID_HTTP_BODY_IN_NETWORK_RESPONSE, check JSON is returned.");
System.println("HomeAssistantToggleMenuItem onReturnSetState() Response Code: INVALID_HTTP_BODY_IN_NETWORK_RESPONSE, check JSON is returned.");
}
ErrorView.show(RezStrings.getNoJson()); ErrorView.show(RezStrings.getNoJson());
break; break;
case 404: case 404:
if (Globals.scDebug) { // System.println("HomeAssistantToggleMenuItem onReturnSetState() Response Code: 404, page not found. Check API URL setting.");
System.println("HomeAssistantToggleMenuItem onReturnSetState() Response Code: 404, page not found. Check API URL setting.");
}
ErrorView.show(RezStrings.getApiUrlNotFound()); ErrorView.show(RezStrings.getApiUrlNotFound());
break; break;
@ -241,9 +201,7 @@ class HomeAssistantToggleMenuItem extends WatchUi.ToggleMenuItem {
for(var i = 0; i < d.size(); i++) { for(var i = 0; i < d.size(); i++) {
if ((d[i].get("entity_id") as Lang.String).equals(mData.get("entity_id"))) { if ((d[i].get("entity_id") as Lang.String).equals(mData.get("entity_id"))) {
state = d[i].get("state") as Lang.String; state = d[i].get("state") as Lang.String;
if (Globals.scDebug) { // System.println((d[i].get("attributes") as Lang.Dictionary).get("friendly_name") + " State=" + state);
System.println((d[i].get("attributes") as Lang.Dictionary).get("friendly_name") + " State=" + state);
}
setUiToggle(state); setUiToggle(state);
} }
} }
@ -251,9 +209,7 @@ class HomeAssistantToggleMenuItem extends WatchUi.ToggleMenuItem {
break; break;
default: default:
if (Globals.scDebug) { // System.println("HomeAssistantToggleMenuItem onReturnSetState(): Unhandled HTTP response code = " + responseCode);
System.println("HomeAssistantToggleMenuItem onReturnSetState(): Unhandled HTTP response code = " + responseCode);
}
ErrorView.show(RezStrings.getUnhandledHttpErr() + responseCode); ErrorView.show(RezStrings.getUnhandledHttpErr() + responseCode);
} }
getApp().setApiStatus(status); getApp().setApiStatus(status);
@ -261,16 +217,12 @@ class HomeAssistantToggleMenuItem extends WatchUi.ToggleMenuItem {
function setState(s as Lang.Boolean) as Void { function setState(s as Lang.Boolean) as Void {
if (! System.getDeviceSettings().phoneConnected) { if (! System.getDeviceSettings().phoneConnected) {
if (Globals.scDebug) { // System.println("HomeAssistantToggleMenuItem getState(): No Phone connection, skipping API call.");
System.println("HomeAssistantToggleMenuItem getState(): No Phone connection, skipping API call.");
}
// Toggle the UI back // Toggle the UI back
setEnabled(!isEnabled()); setEnabled(!isEnabled());
ErrorView.show(RezStrings.getNoPhone() + "."); ErrorView.show(RezStrings.getNoPhone() + ".");
} else if (! System.getDeviceSettings().connectionAvailable) { } else if (! System.getDeviceSettings().connectionAvailable) {
if (Globals.scDebug) { // System.println("HomeAssistantToggleMenuItem getState(): No Internet connection, skipping API call.");
System.println("HomeAssistantToggleMenuItem getState(): No Internet connection, skipping API call.");
}
// Toggle the UI back // Toggle the UI back
setEnabled(!isEnabled()); setEnabled(!isEnabled());
ErrorView.show(RezStrings.getNoInternet() + "."); ErrorView.show(RezStrings.getNoInternet() + ".");
@ -284,10 +236,8 @@ class HomeAssistantToggleMenuItem extends WatchUi.ToggleMenuItem {
} else { } else {
url = url + id.substring(0, id.find(".")) + "/turn_off"; url = url + id.substring(0, id.find(".")) + "/turn_off";
} }
if (Globals.scDebug) { // System.println("HomeAssistantToggleMenuItem setState() URL = " + url);
System.println("HomeAssistantToggleMenuItem setState() URL = " + url); // System.println("HomeAssistantToggleMenuItem setState() entity_id = " + id);
System.println("HomeAssistantToggleMenuItem setState() entity_id = " + id);
}
Communications.makeWebRequest( Communications.makeWebRequest(
url, url,
mData, mData,

View File

@ -146,32 +146,22 @@ class HomeAssistantViewDelegate extends WatchUi.Menu2InputDelegate {
mTimer.reset(); mTimer.reset();
if (item instanceof HomeAssistantToggleMenuItem) { if (item instanceof HomeAssistantToggleMenuItem) {
var haToggleItem = item as HomeAssistantToggleMenuItem; var haToggleItem = item as HomeAssistantToggleMenuItem;
if (Globals.scDebug) { // System.println(haToggleItem.getLabel() + " " + haToggleItem.getId() + " " + haToggleItem.isEnabled());
System.println(haToggleItem.getLabel() + " " + haToggleItem.getId() + " " + haToggleItem.isEnabled());
}
haToggleItem.callService(haToggleItem.isEnabled()); haToggleItem.callService(haToggleItem.isEnabled());
} else if (item instanceof HomeAssistantTapMenuItem) { } else if (item instanceof HomeAssistantTapMenuItem) {
var haItem = item as HomeAssistantTapMenuItem; var haItem = item as HomeAssistantTapMenuItem;
if (Globals.scDebug) { // System.println(haItem.getLabel() + " " + haItem.getId());
System.println(haItem.getLabel() + " " + haItem.getId());
}
haItem.callService(); haItem.callService();
} else if (item instanceof HomeAssistantTemplateMenuItem) { } else if (item instanceof HomeAssistantTemplateMenuItem) {
var haItem = item as HomeAssistantTemplateMenuItem; var haItem = item as HomeAssistantTemplateMenuItem;
if (Globals.scDebug) { // System.println(haItem.getLabel() + " " + haItem.getId());
System.println(haItem.getLabel() + " " + haItem.getId());
}
haItem.callService(); haItem.callService();
} else if (item instanceof HomeAssistantGroupMenuItem) { } else if (item instanceof HomeAssistantGroupMenuItem) {
var haMenuItem = item as HomeAssistantGroupMenuItem; var haMenuItem = item as HomeAssistantGroupMenuItem;
if (Globals.scDebug) { // System.println("IconMenu: " + haMenuItem.getLabel() + " " + haMenuItem.getId());
System.println("IconMenu: " + haMenuItem.getLabel() + " " + haMenuItem.getId());
}
WatchUi.pushView(haMenuItem.getMenuView(), new HomeAssistantViewDelegate(false), WatchUi.SLIDE_LEFT); WatchUi.pushView(haMenuItem.getMenuView(), new HomeAssistantViewDelegate(false), WatchUi.SLIDE_LEFT);
} else { } else {
if (Globals.scDebug) { // System.println(item.getLabel() + " " + item.getId());
System.println(item.getLabel() + " " + item.getId());
}
} }
} }

View File

@ -30,9 +30,7 @@ class QuitTimer extends Timer.Timer {
} }
function exitApp() as Void { function exitApp() as Void {
if (Globals.scDebug) { // System.println("QuitTimer exitApp(): Exiting");
System.println("QuitTimer exitApp(): Exiting");
}
// This will exit the system cleanly from any point within an app. // This will exit the system cleanly from any point within an app.
System.exit(); System.exit();
} }
@ -45,9 +43,7 @@ class QuitTimer extends Timer.Timer {
} }
function reset() { function reset() {
if (Globals.scDebug) { // System.println("QuitTimer reset(): Restarted quit timer");
System.println("QuitTimer reset(): Restarted quit timer");
}
stop(); stop();
begin(); begin();
} }

View File

@ -26,50 +26,42 @@ using Toybox.WatchUi;
class RezStrings { class RezStrings {
(:glance) (:glance)
private static var strAppName as Lang.String or Null; private static var strAppName as Lang.String or Null;
private static var strConfirm as Lang.String or Null; private static var strConfirm as Lang.String or Null;
private static var strExecuted as Lang.String or Null; private static var strExecuted as Lang.String or Null;
private static var strNoPhone as Lang.String or Null;
private static var strNoInternet as Lang.String or Null;
private static var strNoResponse as Lang.String or Null;
private static var strNoApiKey as Lang.String or Null;
private static var strNoApiUrl as Lang.String or Null;
private static var strNoConfigUrl as Lang.String or Null;
private static var strApiFlood as Lang.String or Null;
private static var strApiUrlNotFound as Lang.String or Null;
private static var strConfigUrlNotFound as Lang.String or Null;
private static var strNoJson as Lang.String or Null;
private static var strUnhandledHttpErr as Lang.String or Null;
private static var strTrailingSlashErr as Lang.String or Null;
private static var strWebhookFailed as Lang.String or Null;
private static var strTemplateError as Lang.String or Null;
(:glance) (:glance)
private static var strNoPhone as Lang.String or Null; private static var strAvailable as Lang.String or Null;
private static var strNoInternet as Lang.String or Null;
private static var strNoResponse as Lang.String or Null;
(:glance) (:glance)
private static var strNoApiKey as Lang.String or Null; private static var strChecking as Lang.String or Null;
(:glance) (:glance)
private static var strNoApiUrl as Lang.String or Null; private static var strUnavailable as Lang.String or Null;
(:glance) (:glance)
private static var strNoConfigUrl as Lang.String or Null; private static var strUnconfigured as Lang.String or Null;
private static var strApiFlood as Lang.String or Null;
private static var strApiUrlNotFound as Lang.String or Null;
private static var strConfigUrlNotFound as Lang.String or Null;
private static var strNoJson as Lang.String or Null;
private static var strUnhandledHttpErr as Lang.String or Null;
private static var strTrailingSlashErr as Lang.String or Null;
private static var strWebhookFailed as Lang.String or Null;
private static var strTemplateError as Lang.String or Null;
(:glance) (:glance)
private static var strAvailable as Lang.String or Null; private static var strCached as Lang.String or Null;
(:glance) (:glance)
private static var strChecking as Lang.String or Null; private static var strGlanceMenu as Lang.String or Null;
(:glance) private static var strMemory as Lang.String or Null;
private static var strUnavailable as Lang.String or Null;
(:glance)
private static var strUnconfigured as Lang.String or Null;
(:glance)
private static var strCached as Lang.String or Null;
(:glance)
private static var strGlanceMenu as Lang.String or Null;
private static var strMemory as Lang.String or Null;
// Can't initialise a constant directly, have to be initialised via a function // Can't initialise a constant directly, have to be initialised via a function
// for 'WatchUi.loadResource' to be available. // for 'WatchUi.loadResource' to be available.
(:glance) (:glance)
static function update_glance() { static function update_glance() {
strAppName = WatchUi.loadResource($.Rez.Strings.AppName); strAppName = WatchUi.loadResource($.Rez.Strings.AppName);
strNoPhone = WatchUi.loadResource($.Rez.Strings.NoPhone);
strNoApiKey = WatchUi.loadResource($.Rez.Strings.NoAPIKey);
strNoApiUrl = WatchUi.loadResource($.Rez.Strings.NoApiUrl);
strNoConfigUrl = WatchUi.loadResource($.Rez.Strings.NoConfigUrl);
strAvailable = WatchUi.loadResource($.Rez.Strings.Available); strAvailable = WatchUi.loadResource($.Rez.Strings.Available);
strChecking = WatchUi.loadResource($.Rez.Strings.Checking); strChecking = WatchUi.loadResource($.Rez.Strings.Checking);
strUnavailable = WatchUi.loadResource($.Rez.Strings.Unavailable); strUnavailable = WatchUi.loadResource($.Rez.Strings.Unavailable);
@ -81,7 +73,7 @@ class RezStrings {
// Can't initialise a constant directly, have to be initialised via a function // Can't initialise a constant directly, have to be initialised via a function
// for 'WatchUi.loadResource' to be available. // for 'WatchUi.loadResource' to be available.
static function update() { static function update() {
strAppName = WatchUi.loadResource($.Rez.Strings.AppName); update_glance();
strConfirm = WatchUi.loadResource($.Rez.Strings.Confirm); strConfirm = WatchUi.loadResource($.Rez.Strings.Confirm);
strExecuted = WatchUi.loadResource($.Rez.Strings.Executed); strExecuted = WatchUi.loadResource($.Rez.Strings.Executed);
strNoPhone = WatchUi.loadResource($.Rez.Strings.NoPhone); strNoPhone = WatchUi.loadResource($.Rez.Strings.NoPhone);
@ -98,15 +90,10 @@ class RezStrings {
strTrailingSlashErr = WatchUi.loadResource($.Rez.Strings.TrailingSlashErr); strTrailingSlashErr = WatchUi.loadResource($.Rez.Strings.TrailingSlashErr);
strWebhookFailed = WatchUi.loadResource($.Rez.Strings.WebhookFailed); strWebhookFailed = WatchUi.loadResource($.Rez.Strings.WebhookFailed);
strTemplateError = WatchUi.loadResource($.Rez.Strings.TemplateError); strTemplateError = WatchUi.loadResource($.Rez.Strings.TemplateError);
strAvailable = WatchUi.loadResource($.Rez.Strings.Available);
strChecking = WatchUi.loadResource($.Rez.Strings.Checking);
strUnavailable = WatchUi.loadResource($.Rez.Strings.Unavailable);
strUnconfigured = WatchUi.loadResource($.Rez.Strings.Unconfigured);
strCached = WatchUi.loadResource($.Rez.Strings.Cached);
strGlanceMenu = WatchUi.loadResource($.Rez.Strings.GlanceMenu);
strMemory = WatchUi.loadResource($.Rez.Strings.Memory); strMemory = WatchUi.loadResource($.Rez.Strings.Memory);
} }
(:glance)
static function getAppName() as Lang.String { static function getAppName() as Lang.String {
return strAppName; return strAppName;
} }
@ -175,26 +162,32 @@ class RezStrings {
return strTemplateError; return strTemplateError;
} }
(:glance)
static function getAvailable() as Lang.String { static function getAvailable() as Lang.String {
return strAvailable; return strAvailable;
} }
(:glance)
static function getChecking() as Lang.String { static function getChecking() as Lang.String {
return strChecking; return strChecking;
} }
(:glance)
static function getUnavailable() as Lang.String { static function getUnavailable() as Lang.String {
return strUnavailable; return strUnavailable;
} }
(:glance)
static function getUnconfigured() as Lang.String { static function getUnconfigured() as Lang.String {
return strUnconfigured; return strUnconfigured;
} }
(:glance)
static function getCached() as Lang.String { static function getCached() as Lang.String {
return strCached; return strCached;
} }
(:glance)
static function getGlanceMenu() as Lang.String { static function getGlanceMenu() as Lang.String {
return strGlanceMenu; return strGlanceMenu;
} }

View File

@ -86,14 +86,12 @@ class Settings {
unsetWebhookId(); unsetWebhookId();
} }
} }
if (Globals.scDebug) { // System.println("Settings update(): getTemporalEventRegisteredTime() = " + Background.getTemporalEventRegisteredTime());
System.println("Settings update(): getTemporalEventRegisteredTime() = " + Background.getTemporalEventRegisteredTime()); // if (Background.getTemporalEventRegisteredTime() != null) {
if (Background.getTemporalEventRegisteredTime() != null) { // System.println("Settings update(): getTemporalEventRegisteredTime().value() = " + Background.getTemporalEventRegisteredTime().value().format("%d") + " seconds");
System.println("Settings update(): getTemporalEventRegisteredTime().value() = " + Background.getTemporalEventRegisteredTime().value().format("%d") + " seconds"); // } else {
} else { // System.println("Settings update(): getTemporalEventRegisteredTime() = null");
System.println("Settings update(): getTemporalEventRegisteredTime() = null"); // }
}
}
} }
static function getApiKey() as Lang.String { static function getApiKey() as Lang.String {

View File

@ -78,9 +78,7 @@ class WebLog {
var myTime = System.getClockTime(); var myTime = System.getClockTime();
buffer += myTime.hour.format("%02d") + ":" + myTime.min.format("%02d") + ":" + myTime.sec.format("%02d") + " " + str; buffer += myTime.hour.format("%02d") + ":" + myTime.min.format("%02d") + ":" + myTime.sec.format("%02d") + " " + str;
numCalls++; numCalls++;
if (Globals.scDebug) { // System.println("WebLog print() str = " + str);
System.println("WebLog print() str = " + str);
}
if (numCalls >= callsbuffer) { if (numCalls >= callsbuffer) {
doPrint(); doPrint();
} }
@ -97,9 +95,7 @@ class WebLog {
// submission level set by 'callsbuffer'. // submission level set by 'callsbuffer'.
// //
function flush() { function flush() {
if (Globals.scDebug) { // System.println("WebLog flush()");
System.println("WebLog flush()");
}
if (numCalls > 0) { if (numCalls > 0) {
doPrint(); doPrint();
} }
@ -108,10 +104,8 @@ class WebLog {
// Perform the submission to the online logger. // Perform the submission to the online logger.
// //
function doPrint() { function doPrint() {
if (Globals.scDebug) { // System.println("WebLog doPrint()");
System.println("WebLog doPrint()"); // System.println(buffer);
System.println(buffer);
}
Communications.makeWebRequest( Communications.makeWebRequest(
ClientId.webLogUrl, ClientId.webLogUrl,
{ {
@ -134,9 +128,7 @@ class WebLog {
// execution. // execution.
// //
function clear() { function clear() {
if (Globals.scDebug) { // System.println("WebLog clear()");
System.println("WebLog clear()");
}
Communications.makeWebRequest( Communications.makeWebRequest(
ClientId.webLogClearUrl, ClientId.webLogClearUrl,
{}, {},
@ -156,24 +148,20 @@ class WebLog {
// Callback function to print the outcome of a doPrint() method. // Callback function to print the outcome of a doPrint() method.
// //
function onLog(responseCode as Lang.Number, data as Null or Lang.Dictionary or Lang.String) as Void { function onLog(responseCode as Lang.Number, data as Null or Lang.Dictionary or Lang.String) as Void {
if (Globals.scDebug) { // if (responseCode != 200) {
if (responseCode != 200) { // System.println("WebLog onLog() Failed");
System.println("WebLog onLog() Failed"); // System.println("WebLog onLog() Response Code: " + responseCode);
System.println("WebLog onLog() Response Code: " + responseCode); // System.println("WebLog onLog() Response Data: " + data);
System.println("WebLog onLog() Response Data: " + data); // }
}
}
} }
// Callback function to print the outcome of a clear() method. // Callback function to print the outcome of a clear() method.
// //
function onClear(responseCode as Lang.Number, data as Null or Lang.Dictionary or Lang.String) as Void { function onClear(responseCode as Lang.Number, data as Null or Lang.Dictionary or Lang.String) as Void {
if (Globals.scDebug) { // if (responseCode != 200) {
if (responseCode != 200) { // System.println("WebLog onClear() Failed");
System.println("WebLog onClear() Failed"); // System.println("WebLog onClear() Response Code: " + responseCode);
System.println("WebLog onClear() Response Code: " + responseCode); // System.println("WebLog onClear() Response Data: " + data);
System.println("WebLog onClear() Response Data: " + data); // }
}
}
} }
} }

View File

@ -32,44 +32,32 @@ class WebhookManager {
switch (responseCode) { switch (responseCode) {
case Communications.BLE_HOST_TIMEOUT: case Communications.BLE_HOST_TIMEOUT:
case Communications.BLE_CONNECTION_UNAVAILABLE: case Communications.BLE_CONNECTION_UNAVAILABLE:
if (Globals.scDebug) { // System.println("WebhookManager onReturnRequestWebhookId() Response Code: BLE_HOST_TIMEOUT or BLE_CONNECTION_UNAVAILABLE, Bluetooth connection severed.");
System.println("WebhookManager onReturnRequestWebhookId() Response Code: BLE_HOST_TIMEOUT or BLE_CONNECTION_UNAVAILABLE, Bluetooth connection severed.");
}
ErrorView.show(RezStrings.getWebhookFailed() + "\n" + RezStrings.getNoPhone() + "."); ErrorView.show(RezStrings.getWebhookFailed() + "\n" + RezStrings.getNoPhone() + ".");
break; break;
case Communications.BLE_QUEUE_FULL: case Communications.BLE_QUEUE_FULL:
if (Globals.scDebug) { // System.println("WebhookManager onReturnRequestWebhookId() Response Code: BLE_QUEUE_FULL, API calls too rapid.");
System.println("WebhookManager onReturnRequestWebhookId() Response Code: BLE_QUEUE_FULL, API calls too rapid.");
}
ErrorView.show(RezStrings.getWebhookFailed() + "\n" + RezStrings.getApiFlood()); ErrorView.show(RezStrings.getWebhookFailed() + "\n" + RezStrings.getApiFlood());
break; break;
case Communications.NETWORK_REQUEST_TIMED_OUT: case Communications.NETWORK_REQUEST_TIMED_OUT:
if (Globals.scDebug) { // System.println("WebhookManager onReturnRequestWebhookId() Response Code: NETWORK_REQUEST_TIMED_OUT, check Internet connection.");
System.println("WebhookManager onReturnRequestWebhookId() Response Code: NETWORK_REQUEST_TIMED_OUT, check Internet connection.");
}
ErrorView.show(RezStrings.getWebhookFailed() + "\n" + RezStrings.getNoResponse()); ErrorView.show(RezStrings.getWebhookFailed() + "\n" + RezStrings.getNoResponse());
break; break;
case Communications.NETWORK_RESPONSE_OUT_OF_MEMORY: case Communications.NETWORK_RESPONSE_OUT_OF_MEMORY:
if (Globals.scDebug) { // System.println("WebhookManager onReturnRequestWebhookId() Response Code: NETWORK_RESPONSE_OUT_OF_MEMORY, are we going too fast?");
System.println("WebhookManager onReturnRequestWebhookId() Response Code: NETWORK_RESPONSE_OUT_OF_MEMORY, are we going too fast?");
}
// Ignore and see if we can carry on // Ignore and see if we can carry on
break; break;
case Communications.INVALID_HTTP_BODY_IN_NETWORK_RESPONSE: case Communications.INVALID_HTTP_BODY_IN_NETWORK_RESPONSE:
if (Globals.scDebug) { // System.println("WebhookManager onReturnRequestWebhookId() Response Code: INVALID_HTTP_BODY_IN_NETWORK_RESPONSE, check JSON is returned.");
System.println("WebhookManager onReturnRequestWebhookId() Response Code: INVALID_HTTP_BODY_IN_NETWORK_RESPONSE, check JSON is returned.");
}
Settings.unsetIsBatteryLevelEnabled(); Settings.unsetIsBatteryLevelEnabled();
ErrorView.show(RezStrings.getWebhookFailed() + "\n" + RezStrings.getNoJson()); ErrorView.show(RezStrings.getWebhookFailed() + "\n" + RezStrings.getNoJson());
break; break;
case 404: case 404:
if (Globals.scDebug) { // System.println("WebhookManager onReturnRequestWebhookId() Response Code: 404, page not found. Check API URL setting.");
System.println("WebhookManager onReturnRequestWebhookId() Response Code: 404, page not found. Check API URL setting.");
}
Settings.unsetIsBatteryLevelEnabled(); Settings.unsetIsBatteryLevelEnabled();
ErrorView.show(RezStrings.getWebhookFailed() + "\n" + RezStrings.getApiUrlNotFound()); ErrorView.show(RezStrings.getWebhookFailed() + "\n" + RezStrings.getApiUrlNotFound());
break; break;
@ -99,27 +87,21 @@ class WebhookManager {
"disabled" => false "disabled" => false
}); });
} else { } else {
if (Globals.scDebug) { // System.println("WebhookManager onReturnRequestWebhookId(): No webhook id in response data.");
System.println("WebhookManager onReturnRequestWebhookId(): No webhook id in response data.");
}
Settings.unsetIsBatteryLevelEnabled(); Settings.unsetIsBatteryLevelEnabled();
ErrorView.show(RezStrings.getWebhookFailed()); ErrorView.show(RezStrings.getWebhookFailed());
} }
break; break;
default: default:
if (Globals.scDebug) { // System.println("WebhookManager onReturnRequestWebhookId(): Unhandled HTTP response code = " + responseCode);
System.println("WebhookManager onReturnRequestWebhookId(): Unhandled HTTP response code = " + responseCode);
}
Settings.unsetIsBatteryLevelEnabled(); Settings.unsetIsBatteryLevelEnabled();
ErrorView.show(RezStrings.getWebhookFailed() + "\n" + RezStrings.getUnhandledHttpErr() + responseCode); ErrorView.show(RezStrings.getWebhookFailed() + "\n" + RezStrings.getUnhandledHttpErr() + responseCode);
} }
} }
function requestWebhookId() { function requestWebhookId() {
if (Globals.scDebug) { // System.println("WebhookManager requestWebhookId(): Requesting webhook id");
System.println("WebhookManager requestWebhookId(): Requesting webhook id");
}
Communications.makeWebRequest( Communications.makeWebRequest(
Settings.getApiUrl() + "/mobile_app/registrations", Settings.getApiUrl() + "/mobile_app/registrations",
{ {
@ -151,63 +133,48 @@ class WebhookManager {
switch (responseCode) { switch (responseCode) {
case Communications.BLE_HOST_TIMEOUT: case Communications.BLE_HOST_TIMEOUT:
case Communications.BLE_CONNECTION_UNAVAILABLE: case Communications.BLE_CONNECTION_UNAVAILABLE:
if (Globals.scDebug) { // System.println("WebhookManager onReturnRegisterWebhookSensor() Response Code: BLE_HOST_TIMEOUT or BLE_CONNECTION_UNAVAILABLE, Bluetooth connection severed.");
System.println("WebhookManager onReturnRegisterWebhookSensor() Response Code: BLE_HOST_TIMEOUT or BLE_CONNECTION_UNAVAILABLE, Bluetooth connection severed.");
}
Settings.unsetWebhookId(); Settings.unsetWebhookId();
ErrorView.show(RezStrings.getWebhookFailed() + "\n" + RezStrings.getNoPhone() + "."); ErrorView.show(RezStrings.getWebhookFailed() + "\n" + RezStrings.getNoPhone() + ".");
break; break;
case Communications.BLE_QUEUE_FULL: case Communications.BLE_QUEUE_FULL:
if (Globals.scDebug) { // System.println("WebhookManager onReturnRegisterWebhookSensor() Response Code: BLE_QUEUE_FULL, API calls too rapid.");
System.println("WebhookManager onReturnRegisterWebhookSensor() Response Code: BLE_QUEUE_FULL, API calls too rapid.");
}
Settings.unsetWebhookId(); Settings.unsetWebhookId();
ErrorView.show(RezStrings.getWebhookFailed() + "\n" + RezStrings.getApiFlood()); ErrorView.show(RezStrings.getWebhookFailed() + "\n" + RezStrings.getApiFlood());
break; break;
case Communications.NETWORK_REQUEST_TIMED_OUT: case Communications.NETWORK_REQUEST_TIMED_OUT:
if (Globals.scDebug) { // System.println("WebhookManager onReturnRegisterWebhookSensor() Response Code: NETWORK_REQUEST_TIMED_OUT, check Internet connection.");
System.println("WebhookManager onReturnRegisterWebhookSensor() Response Code: NETWORK_REQUEST_TIMED_OUT, check Internet connection.");
}
Settings.unsetWebhookId(); Settings.unsetWebhookId();
ErrorView.show(RezStrings.getWebhookFailed() + "\n" + RezStrings.getNoResponse()); ErrorView.show(RezStrings.getWebhookFailed() + "\n" + RezStrings.getNoResponse());
break; break;
case Communications.NETWORK_RESPONSE_OUT_OF_MEMORY: case Communications.NETWORK_RESPONSE_OUT_OF_MEMORY:
if (Globals.scDebug) { // System.println("WebhookManager onReturnRegisterWebhookSensor() Response Code: NETWORK_RESPONSE_OUT_OF_MEMORY, are we going too fast?");
System.println("WebhookManager onReturnRegisterWebhookSensor() Response Code: NETWORK_RESPONSE_OUT_OF_MEMORY, are we going too fast?");
}
Settings.unsetWebhookId(); Settings.unsetWebhookId();
// Ignore and see if we can carry on // Ignore and see if we can carry on
break; break;
case Communications.INVALID_HTTP_BODY_IN_NETWORK_RESPONSE: case Communications.INVALID_HTTP_BODY_IN_NETWORK_RESPONSE:
if (Globals.scDebug) { // System.println("WebhookManager onReturnRegisterWebhookSensor() Response Code: INVALID_HTTP_BODY_IN_NETWORK_RESPONSE, check JSON is returned.");
System.println("WebhookManager onReturnRegisterWebhookSensor() Response Code: INVALID_HTTP_BODY_IN_NETWORK_RESPONSE, check JSON is returned.");
}
Settings.unsetWebhookId(); Settings.unsetWebhookId();
Settings.unsetIsBatteryLevelEnabled(); Settings.unsetIsBatteryLevelEnabled();
ErrorView.show(RezStrings.getWebhookFailed() + "\n" + RezStrings.getNoJson()); ErrorView.show(RezStrings.getWebhookFailed() + "\n" + RezStrings.getNoJson());
break; break;
case 404: case 404:
if (Globals.scDebug) { // System.println("WebhookManager onReturnRequestWebhookId() Response Code: 404, page not found. Check API URL setting.");
System.println("WebhookManager onReturnRequestWebhookId() Response Code: 404, page not found. Check API URL setting.");
}
Settings.unsetWebhookId(); Settings.unsetWebhookId();
Settings.unsetIsBatteryLevelEnabled(); Settings.unsetIsBatteryLevelEnabled();
ErrorView.show(RezStrings.getWebhookFailed() + "\n" + RezStrings.getApiUrlNotFound()); ErrorView.show(RezStrings.getWebhookFailed() + "\n" + RezStrings.getApiUrlNotFound());
break; break;
case 201: case 201:
if ((data.get("success") as Lang.Boolean or Null) == true) { if ((data.get("success") as Lang.Boolean or Null) != true) {
if (Globals.scDebug) { // When uncommenting, invert the condition above.
System.println("WebhookManager onReturnRegisterWebhookSensor(): Success"); // System.println("WebhookManager onReturnRegisterWebhookSensor(): Success");
} // } else {
} else { // System.println("WebhookManager onReturnRegisterWebhookSensor(): Failure");
if (Globals.scDebug) {
System.println("WebhookManager onReturnRegisterWebhookSensor(): Failure");
}
Settings.unsetWebhookId(); Settings.unsetWebhookId();
Settings.unsetIsBatteryLevelEnabled(); Settings.unsetIsBatteryLevelEnabled();
ErrorView.show(RezStrings.getWebhookFailed()); ErrorView.show(RezStrings.getWebhookFailed());
@ -215,9 +182,7 @@ class WebhookManager {
break; break;
default: default:
if (Globals.scDebug) { // System.println("WebhookManager onReturnRequestWebhookId(): Unhandled HTTP response code = " + responseCode);
System.println("WebhookManager onReturnRequestWebhookId(): Unhandled HTTP response code = " + responseCode);
}
Settings.unsetWebhookId(); Settings.unsetWebhookId();
Settings.unsetIsBatteryLevelEnabled(); Settings.unsetIsBatteryLevelEnabled();
ErrorView.show(RezStrings.getWebhookFailed() + "\n" + RezStrings.getUnhandledHttpErr() + responseCode); ErrorView.show(RezStrings.getWebhookFailed() + "\n" + RezStrings.getUnhandledHttpErr() + responseCode);
@ -225,9 +190,7 @@ class WebhookManager {
} }
function registerWebhookSensor(sensor as Lang.Object) { function registerWebhookSensor(sensor as Lang.Object) {
if (Globals.scDebug) { // System.println("WebhookManager registerWebhookSensor(): Registering webhook sensor: " + sensor.toString());
System.println("WebhookManager registerWebhookSensor(): Registering webhook sensor: " + sensor.toString());
}
Communications.makeWebRequest( Communications.makeWebRequest(
Settings.getApiUrl() + "/webhook/" + Settings.getWebhookId(), Settings.getApiUrl() + "/webhook/" + Settings.getWebhookId(),
{ {