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

@ -44,58 +44,42 @@ class HomeAssistantService {
context as Lang.Object
) as Void {
var entity_id = context as Lang.String or Null;
if (Globals.scDebug) {
System.println("HomeAssistantService onReturnCall() Response Code: " + responseCode);
System.println("HomeAssistantService onReturnCall() Response Data: " + data);
}
// System.println("HomeAssistantService onReturnCall() Response Code: " + responseCode);
// System.println("HomeAssistantService onReturnCall() Response Data: " + data);
switch (responseCode) {
case Communications.BLE_HOST_TIMEOUT:
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() + ".");
break;
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());
break;
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());
break;
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
break;
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());
break;
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());
break;
case 200:
if (Globals.scDebug) {
System.println("HomeAssistantService onReturnCall(): Service executed.");
}
// System.println("HomeAssistantService onReturnCall(): Service executed.");
var d = data as Lang.Array;
var toast = RezStrings.getExecuted();
for(var i = 0; i < d.size(); i++) {
@ -117,9 +101,7 @@ class HomeAssistantService {
break;
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);
}
}
@ -129,22 +111,16 @@ class HomeAssistantService {
data as Lang.Dictionary or Null
) as Void {
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() + ".");
} 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() + ".");
} 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());
if (Globals.scDebug) {
System.println("HomeAssistantService call() URL=" + url);
System.println("HomeAssistantService call() service=" + service);
}
// System.println("HomeAssistantService call() URL=" + url);
// System.println("HomeAssistantService call() service=" + service);
var entity_id = data.get("entity_id");
if (entity_id == null) {