mirror of
https://github.com/house-of-abbey/GarminHomeAssistant.git
synced 2025-06-17 03:48:32 +00:00
Renamed class variables
There's a Monkey C convention to have class variable names start with 'm', then be camel case. 'm' for 'member' according to https://developer.garmin.com/connect-iq/reference-guides/monkey-c-reference/.
This commit is contained in:
@ -14,7 +14,7 @@
|
||||
//
|
||||
// Description:
|
||||
//
|
||||
// Application root for GarminHomeAssistant.
|
||||
// Application root for GarminHomeAssistant
|
||||
//
|
||||
//-----------------------------------------------------------------------------------
|
||||
|
||||
@ -25,16 +25,16 @@ using Toybox.Application.Properties;
|
||||
using Toybox.Timer;
|
||||
|
||||
class HomeAssistantApp extends Application.AppBase {
|
||||
hidden var haMenu;
|
||||
hidden var mHaMenu;
|
||||
hidden var strNoApiKey as Lang.String;
|
||||
hidden var strNoApiUrl as Lang.String;
|
||||
hidden var strNoConfigUrl as Lang.String;
|
||||
hidden var strNoInternet as Lang.String;
|
||||
hidden var strNoMenu as Lang.String;
|
||||
hidden var strApiFlood as Lang.String;
|
||||
hidden var timer as Timer.Timer;
|
||||
hidden var itemsToUpdate; // Array initialised by onReturnFetchMenuConfig()
|
||||
hidden var nextItemToUpdate = 0; // Index into the above array
|
||||
hidden var mTimer as Timer.Timer;
|
||||
hidden var mItemsToUpdate; // Array initialised by onReturnFetchMenuConfig()
|
||||
hidden var mNextItemToUpdate = 0; // Index into the above array
|
||||
|
||||
function initialize() {
|
||||
AppBase.initialize();
|
||||
@ -44,7 +44,7 @@ class HomeAssistantApp extends Application.AppBase {
|
||||
strNoInternet = WatchUi.loadResource($.Rez.Strings.NoInternet);
|
||||
strNoMenu = WatchUi.loadResource($.Rez.Strings.NoMenu);
|
||||
strApiFlood = WatchUi.loadResource($.Rez.Strings.ApiFlood);
|
||||
timer = new Timer.Timer();
|
||||
mTimer = new Timer.Timer();
|
||||
}
|
||||
|
||||
// onStart() is called on application start up
|
||||
@ -53,25 +53,25 @@ class HomeAssistantApp extends Application.AppBase {
|
||||
|
||||
// onStop() is called when your application is exiting
|
||||
function onStop(state as Lang.Dictionary?) as Void {
|
||||
if (timer != null) {
|
||||
timer.stop();
|
||||
if (mTimer != null) {
|
||||
mTimer.stop();
|
||||
}
|
||||
}
|
||||
|
||||
// Return the initial view of your application here
|
||||
function getInitialView() as Lang.Array<WatchUi.Views or WatchUi.InputDelegates>? {
|
||||
if ((Properties.getValue("api_key") as Lang.String).length() == 0) {
|
||||
if (Globals.debug) {
|
||||
if (Globals.scDebug) {
|
||||
System.println("HomeAssistantMenuItem Note - execScript(): No API key in the application settings.");
|
||||
}
|
||||
return [new ErrorView(strNoApiKey + "."), new ErrorDelegate()] as Lang.Array<WatchUi.Views or WatchUi.InputDelegates>;
|
||||
} else if ((Properties.getValue("api_url") as Lang.String).length() == 0) {
|
||||
if (Globals.debug) {
|
||||
if (Globals.scDebug) {
|
||||
System.println("HomeAssistantMenuItem Note - execScript(): No API URL in the application settings.");
|
||||
}
|
||||
return [new ErrorView(strNoApiUrl + "."), new ErrorDelegate()] as Lang.Array<WatchUi.Views or WatchUi.InputDelegates>;
|
||||
} else if ((Properties.getValue("config_url") as Lang.String).length() == 0) {
|
||||
if (Globals.debug) {
|
||||
if (Globals.scDebug) {
|
||||
System.println("HomeAssistantMenuItem Note - execScript(): No configuration URL in the application settings.");
|
||||
}
|
||||
return [new ErrorView(strNoConfigUrl + "."), new ErrorDelegate()] as Lang.Array<WatchUi.Views or WatchUi.InputDelegates>;
|
||||
@ -79,7 +79,7 @@ class HomeAssistantApp extends Application.AppBase {
|
||||
fetchMenuConfig();
|
||||
return [new WatchUi.View(), new WatchUi.BehaviorDelegate()] as Lang.Array<WatchUi.Views or WatchUi.InputDelegates>;
|
||||
} else {
|
||||
if (Globals.debug) {
|
||||
if (Globals.scDebug) {
|
||||
System.println("HomeAssistantApp Note - fetchMenuConfig(): No Internet connection, skipping API call.");
|
||||
}
|
||||
return [new ErrorView(strNoInternet + "."), new ErrorDelegate()] as Lang.Array<WatchUi.Views or WatchUi.InputDelegates>;
|
||||
@ -89,12 +89,12 @@ class HomeAssistantApp extends Application.AppBase {
|
||||
// Callback function after completing the GET request to fetch the configuration menu.
|
||||
//
|
||||
function onReturnFetchMenuConfig(responseCode as Lang.Number, data as Null or Lang.Dictionary or Lang.String) as Void {
|
||||
if (Globals.debug) {
|
||||
if (Globals.scDebug) {
|
||||
System.println("HomeAssistantApp onReturnFetchMenuConfig() Response Code: " + responseCode);
|
||||
System.println("HomeAssistantApp onReturnFetchMenuConfig() Response Data: " + data);
|
||||
}
|
||||
if (responseCode == Communications.BLE_QUEUE_FULL) {
|
||||
if (Globals.debug) {
|
||||
if (Globals.scDebug) {
|
||||
System.println("HomeAssistantApp onReturnFetchMenuConfig() Response Code: BLE_QUEUE_FULL, API calls too rapid.");
|
||||
}
|
||||
var cw = WatchUi.getCurrentView();
|
||||
@ -103,21 +103,21 @@ class HomeAssistantApp extends Application.AppBase {
|
||||
WatchUi.pushView(new ErrorView(strApiFlood), new ErrorDelegate(), WatchUi.SLIDE_UP);
|
||||
}
|
||||
} else if (responseCode == 200) {
|
||||
haMenu = new HomeAssistantView(data, null);
|
||||
WatchUi.switchToView(haMenu, new HomeAssistantViewDelegate(), WatchUi.SLIDE_IMMEDIATE);
|
||||
itemsToUpdate = haMenu.getItemsToUpdate();
|
||||
timer.start(
|
||||
mHaMenu = new HomeAssistantView(data, null);
|
||||
WatchUi.switchToView(mHaMenu, new HomeAssistantViewDelegate(), WatchUi.SLIDE_IMMEDIATE);
|
||||
mItemsToUpdate = mHaMenu.getItemsToUpdate();
|
||||
mTimer.start(
|
||||
method(:updateNextMenuItem),
|
||||
Globals.menuItemUpdateInterval,
|
||||
Globals.scMenuItemUpdateInterval,
|
||||
true
|
||||
);
|
||||
} else if (responseCode == -300) {
|
||||
if (Globals.debug) {
|
||||
if (Globals.scDebug) {
|
||||
System.println("HomeAssistantApp Note - onReturnFetchMenuConfig(): Network request timeout.");
|
||||
}
|
||||
WatchUi.pushView(new ErrorView(strNoMenu + ". " + strNoInternet + "?"), new ErrorDelegate(), WatchUi.SLIDE_UP);
|
||||
} else {
|
||||
if (Globals.debug) {
|
||||
if (Globals.scDebug) {
|
||||
System.println("HomeAssistantApp Note - onReturnFetchMenuConfig(): Configuration not found or potential validation issue.");
|
||||
}
|
||||
WatchUi.pushView(new ErrorView(strNoMenu + " code=" + responseCode ), new ErrorDelegate(), WatchUi.SLIDE_UP);
|
||||
@ -140,9 +140,9 @@ class HomeAssistantApp extends Application.AppBase {
|
||||
// We need to spread out the API calls so as not to overload the results queue and cause Communications.BLE_QUEUE_FULL (-101) error.
|
||||
// This function is called by a timer every Globals.menuItemUpdateInterval ms.
|
||||
function updateNextMenuItem() as Void {
|
||||
var itu = itemsToUpdate as Lang.Array<HomeAssistantToggleMenuItem>;
|
||||
itu[nextItemToUpdate].getState();
|
||||
nextItemToUpdate = (nextItemToUpdate + 1) % itu.size();
|
||||
var itu = mItemsToUpdate as Lang.Array<HomeAssistantToggleMenuItem>;
|
||||
itu[mNextItemToUpdate].getState();
|
||||
mNextItemToUpdate = (mNextItemToUpdate + 1) % itu.size();
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user