mirror of
https://github.com/house-of-abbey/GarminHomeAssistant.git
synced 2025-06-17 11:58:30 +00:00
Compare commits
14 Commits
80-example
...
restyled/8
Author | SHA1 | Date | |
---|---|---|---|
a95736ebed | |||
9c001f3402 | |||
7786efd883 | |||
0b80e4546d | |||
6e67c4cf2a | |||
b80227e484 | |||
d9b345e5b8 | |||
fc7302ad3b | |||
d9ecaf34ee | |||
62b8f0fccf | |||
26954cbc60 | |||
a5b2af81bc | |||
1448f6b0c2 | |||
5620ea6695 |
@ -137,6 +137,7 @@
|
|||||||
},
|
},
|
||||||
"items": {
|
"items": {
|
||||||
"type": "array",
|
"type": "array",
|
||||||
|
"maxItems": 16,
|
||||||
"items": {
|
"items": {
|
||||||
"oneOf": [
|
"oneOf": [
|
||||||
{
|
{
|
||||||
|
@ -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(
|
||||||
@ -56,13 +50,13 @@ class BackgroundServiceDelegate extends System.ServiceDelegate {
|
|||||||
"type" => "update_sensor_states",
|
"type" => "update_sensor_states",
|
||||||
"data" => [
|
"data" => [
|
||||||
{
|
{
|
||||||
"state" => System.getSystemStats().battery,
|
"state" => System.getSystemStats().battery,
|
||||||
"type" => "sensor",
|
"type" => "sensor",
|
||||||
"unique_id" => "battery_level"
|
"unique_id" => "battery_level"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"state" => System.getSystemStats().charging,
|
"state" => System.getSystemStats().charging,
|
||||||
"type" => "binary_sensor",
|
"type" => "binary_sensor",
|
||||||
"unique_id" => "battery_is_charging"
|
"unique_id" => "battery_is_charging"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@ -70,7 +64,7 @@ class BackgroundServiceDelegate extends System.ServiceDelegate {
|
|||||||
{
|
{
|
||||||
:method => Communications.HTTP_REQUEST_METHOD_POST,
|
:method => Communications.HTTP_REQUEST_METHOD_POST,
|
||||||
:headers => {
|
:headers => {
|
||||||
"Content-Type" => Communications.REQUEST_CONTENT_TYPE_JSON
|
"Content-Type" => Communications.REQUEST_CONTENT_TYPE_JSON
|
||||||
},
|
},
|
||||||
:responseType => Communications.HTTP_RESPONSE_CONTENT_TYPE_JSON
|
:responseType => Communications.HTTP_RESPONSE_CONTENT_TYPE_JSON
|
||||||
},
|
},
|
||||||
|
@ -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.
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
|
|
||||||
@ -88,41 +89,29 @@ class HomeAssistantApp extends Application.AppBase {
|
|||||||
function getInitialView() as Lang.Array<WatchUi.Views or WatchUi.InputDelegates>? {
|
function getInitialView() as Lang.Array<WatchUi.Views or WatchUi.InputDelegates>? {
|
||||||
mIsApp = true;
|
mIsApp = true;
|
||||||
mQuitTimer = new QuitTimer();
|
mQuitTimer = new QuitTimer();
|
||||||
RezStrings.update();
|
// RezStrings.update();
|
||||||
mApiStatus = RezStrings.getChecking();
|
mApiStatus = WatchUi.loadResource($.Rez.Strings.Checking) as Lang.String;
|
||||||
mMenuStatus = RezStrings.getChecking();
|
mMenuStatus = WatchUi.loadResource($.Rez.Strings.Checking) as Lang.String;
|
||||||
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(WatchUi.loadResource($.Rez.Strings.NoAPIKey) as Lang.String + ".");
|
||||||
}
|
|
||||||
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(WatchUi.loadResource($.Rez.Strings.NoApiUrl) as Lang.String + ".");
|
||||||
}
|
|
||||||
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(WatchUi.loadResource($.Rez.Strings.TrailingSlashErr) as Lang.String + ".");
|
||||||
}
|
|
||||||
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(WatchUi.loadResource($.Rez.Strings.NoConfigUrl) as Lang.String + ".");
|
||||||
}
|
|
||||||
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(WatchUi.loadResource($.Rez.Strings.NoPhone) as Lang.String + ".");
|
||||||
}
|
|
||||||
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(WatchUi.loadResource($.Rez.Strings.NoInternet) as Lang.String + ".");
|
||||||
}
|
|
||||||
return ErrorView.create(RezStrings.getNoInternet() + ".");
|
|
||||||
} else {
|
} else {
|
||||||
var isCached = fetchMenuConfig();
|
var isCached = fetchMenuConfig();
|
||||||
fetchApiStatus();
|
fetchApiStatus();
|
||||||
@ -142,65 +131,53 @@ 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 = WatchUi.loadResource($.Rez.Strings.Unavailable) as Lang.String;
|
||||||
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(WatchUi.loadResource($.Rez.Strings.NoPhone) as Lang.String + ".");
|
||||||
}
|
}
|
||||||
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(WatchUi.loadResource($.Rez.Strings.ApiFlood) as Lang.String);
|
||||||
}
|
}
|
||||||
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(WatchUi.loadResource($.Rez.Strings.NoResponse) as Lang.String);
|
||||||
}
|
}
|
||||||
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(WatchUi.loadResource($.Rez.Strings.NoJson) as Lang.String);
|
||||||
}
|
}
|
||||||
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(WatchUi.loadResource($.Rez.Strings.ConfigUrlNotFound) as Lang.String);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 200:
|
case 200:
|
||||||
if (Settings.getCacheConfig()) {
|
if (Settings.getCacheConfig()) {
|
||||||
Storage.setValue("menu", data as Lang.Dictionary);
|
Storage.setValue("menu", data as Lang.Dictionary);
|
||||||
mMenuStatus = RezStrings.getCached();
|
mMenuStatus = WatchUi.loadResource($.Rez.Strings.Cached) as Lang.String;
|
||||||
} else {
|
} else {
|
||||||
mMenuStatus = RezStrings.getAvailable();
|
mMenuStatus = WatchUi.loadResource($.Rez.Strings.Available) as Lang.String;
|
||||||
}
|
}
|
||||||
if (!mIsGlance) {
|
if (!mIsGlance) {
|
||||||
buildMenu(data);
|
buildMenu(data);
|
||||||
@ -211,11 +188,9 @@ 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(WatchUi.loadResource($.Rez.Strings.UnhandledHttpErr) as Lang.String + responseCode);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -227,7 +202,7 @@ class HomeAssistantApp extends Application.AppBase {
|
|||||||
(:glance)
|
(:glance)
|
||||||
function fetchMenuConfig() as Lang.Boolean {
|
function fetchMenuConfig() as Lang.Boolean {
|
||||||
if (Settings.getConfigUrl().equals("")) {
|
if (Settings.getConfigUrl().equals("")) {
|
||||||
mMenuStatus = RezStrings.getUnconfigured();
|
mMenuStatus = WatchUi.loadResource($.Rez.Strings.Unconfigured) as Lang.String;
|
||||||
WatchUi.requestUpdate();
|
WatchUi.requestUpdate();
|
||||||
} else {
|
} else {
|
||||||
var menu = Storage.getValue("menu") as Lang.Dictionary;
|
var menu = Storage.getValue("menu") as Lang.Dictionary;
|
||||||
@ -238,25 +213,21 @@ 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 {
|
||||||
ErrorView.show(RezStrings.getNoPhone() + ".");
|
ErrorView.show(WatchUi.loadResource($.Rez.Strings.NoPhone) as Lang.String + ".");
|
||||||
}
|
}
|
||||||
mMenuStatus = RezStrings.getUnavailable();
|
mMenuStatus = WatchUi.loadResource($.Rez.Strings.Unavailable) as Lang.String;
|
||||||
} 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 {
|
||||||
ErrorView.show(RezStrings.getNoInternet() + ".");
|
ErrorView.show(WatchUi.loadResource($.Rez.Strings.NoInternet) as Lang.String + ".");
|
||||||
}
|
}
|
||||||
mMenuStatus = RezStrings.getUnavailable();
|
mMenuStatus = WatchUi.loadResource($.Rez.Strings.Unavailable) as Lang.String;
|
||||||
} else {
|
} else {
|
||||||
Communications.makeWebRequest(
|
Communications.makeWebRequest(
|
||||||
Settings.getConfigUrl(),
|
Settings.getConfigUrl(),
|
||||||
@ -269,7 +240,7 @@ class HomeAssistantApp extends Application.AppBase {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
mMenuStatus = RezStrings.getCached();
|
mMenuStatus = WatchUi.loadResource($.Rez.Strings.Cached) as Lang.String;
|
||||||
WatchUi.requestUpdate();
|
WatchUi.requestUpdate();
|
||||||
if (!mIsGlance) {
|
if (!mIsGlance) {
|
||||||
buildMenu(menu);
|
buildMenu(menu);
|
||||||
@ -301,56 +272,44 @@ 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 = WatchUi.loadResource($.Rez.Strings.Unavailable) as Lang.String;
|
||||||
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(WatchUi.loadResource($.Rez.Strings.NoPhone) as Lang.String + ".");
|
||||||
}
|
}
|
||||||
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(WatchUi.loadResource($.Rez.Strings.ApiFlood) as Lang.String);
|
||||||
}
|
}
|
||||||
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(WatchUi.loadResource($.Rez.Strings.NoResponse) as Lang.String);
|
||||||
}
|
}
|
||||||
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(WatchUi.loadResource($.Rez.Strings.NoJson) as Lang.String);
|
||||||
}
|
}
|
||||||
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(WatchUi.loadResource($.Rez.Strings.ConfigUrlNotFound) as Lang.String);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -360,7 +319,7 @@ class HomeAssistantApp extends Application.AppBase {
|
|||||||
msg = data.get("message");
|
msg = data.get("message");
|
||||||
}
|
}
|
||||||
if (msg.equals("API running.")) {
|
if (msg.equals("API running.")) {
|
||||||
mApiStatus = RezStrings.getAvailable();
|
mApiStatus = WatchUi.loadResource($.Rez.Strings.Available) as Lang.String;
|
||||||
} else {
|
} else {
|
||||||
if (!mIsGlance) {
|
if (!mIsGlance) {
|
||||||
ErrorView.show("API " + mApiStatus + ".");
|
ErrorView.show("API " + mApiStatus + ".");
|
||||||
@ -369,11 +328,9 @@ 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(WatchUi.loadResource($.Rez.Strings.UnhandledHttpErr) as Lang.String + responseCode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
WatchUi.requestUpdate();
|
WatchUi.requestUpdate();
|
||||||
@ -382,28 +339,24 @@ class HomeAssistantApp extends Application.AppBase {
|
|||||||
(:glance)
|
(:glance)
|
||||||
function fetchApiStatus() as Void {
|
function fetchApiStatus() as Void {
|
||||||
if (Settings.getApiUrl().equals("")) {
|
if (Settings.getApiUrl().equals("")) {
|
||||||
mApiStatus = RezStrings.getUnconfigured();
|
mApiStatus = WatchUi.loadResource($.Rez.Strings.Unconfigured) as Lang.String;
|
||||||
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 = WatchUi.loadResource($.Rez.Strings.Unavailable) as Lang.String;
|
||||||
}
|
|
||||||
mApiStatus = RezStrings.getUnavailable();
|
|
||||||
if (mIsGlance) {
|
if (mIsGlance) {
|
||||||
WatchUi.requestUpdate();
|
WatchUi.requestUpdate();
|
||||||
} else {
|
} else {
|
||||||
ErrorView.show(RezStrings.getNoPhone() + ".");
|
ErrorView.show(WatchUi.loadResource($.Rez.Strings.NoPhone) as Lang.String + ".");
|
||||||
}
|
}
|
||||||
} 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 = WatchUi.loadResource($.Rez.Strings.Unavailable) as Lang.String;
|
||||||
}
|
|
||||||
mApiStatus = RezStrings.getUnavailable();
|
|
||||||
if (mIsGlance) {
|
if (mIsGlance) {
|
||||||
WatchUi.requestUpdate();
|
WatchUi.requestUpdate();
|
||||||
} else {
|
} else {
|
||||||
ErrorView.show(RezStrings.getNoInternet() + ".");
|
ErrorView.show(WatchUi.loadResource($.Rez.Strings.NoInternet) as Lang.String + ".");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Communications.makeWebRequest(
|
Communications.makeWebRequest(
|
||||||
@ -449,11 +402,9 @@ 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(WatchUi.loadResource($.Rez.Strings.ConfigUrlNotFound) as Lang.String);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
itu[mNextItemToUpdate].getState();
|
itu[mNextItemToUpdate].getState();
|
||||||
@ -467,9 +418,9 @@ class HomeAssistantApp extends Application.AppBase {
|
|||||||
|
|
||||||
function getGlanceView() as Lang.Array<WatchUi.GlanceView or WatchUi.GlanceViewDelegate> or Null {
|
function getGlanceView() as Lang.Array<WatchUi.GlanceView or WatchUi.GlanceViewDelegate> or Null {
|
||||||
mIsGlance = true;
|
mIsGlance = true;
|
||||||
RezStrings.update_glance();
|
// RezStrings.update_glance();
|
||||||
mApiStatus = RezStrings.getChecking();
|
mApiStatus = WatchUi.loadResource($.Rez.Strings.Checking) as Lang.String;
|
||||||
mMenuStatus = RezStrings.getChecking();
|
mMenuStatus = WatchUi.loadResource($.Rez.Strings.Checking) as Lang.String;
|
||||||
updateStatus();
|
updateStatus();
|
||||||
Settings.update();
|
Settings.update();
|
||||||
mTimer = new Timer.Timer();
|
mTimer = new Timer.Timer();
|
||||||
@ -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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ using Toybox.Application.Properties;
|
|||||||
class HomeAssistantConfirmation extends WatchUi.Confirmation {
|
class HomeAssistantConfirmation extends WatchUi.Confirmation {
|
||||||
|
|
||||||
function initialize() {
|
function initialize() {
|
||||||
WatchUi.Confirmation.initialize(RezStrings.getConfirm());
|
WatchUi.Confirmation.initialize(WatchUi.loadResource($.Rez.Strings.Confirm) as Lang.String);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -44,10 +44,10 @@ class HomeAssistantGlanceView extends WatchUi.GlanceView {
|
|||||||
|
|
||||||
function onLayout(dc as Graphics.Dc) as Void {
|
function onLayout(dc as Graphics.Dc) as Void {
|
||||||
var h = dc.getHeight();
|
var h = dc.getHeight();
|
||||||
var tw = dc.getTextWidthInPixels(RezStrings.getGlanceMenu(), Graphics.FONT_XTINY);
|
var tw = dc.getTextWidthInPixels(WatchUi.loadResource($.Rez.Strings.GlanceMenu) as Lang.String, Graphics.FONT_XTINY);
|
||||||
|
|
||||||
mTitle = new WatchUi.Text({
|
mTitle = new WatchUi.Text({
|
||||||
:text => RezStrings.getAppName(),
|
:text => WatchUi.loadResource($.Rez.Strings.AppName) as Lang.String,
|
||||||
:color => Graphics.COLOR_WHITE,
|
:color => Graphics.COLOR_WHITE,
|
||||||
:font => Graphics.FONT_TINY,
|
:font => Graphics.FONT_TINY,
|
||||||
:justification => Graphics.TEXT_JUSTIFY_LEFT | Graphics.TEXT_JUSTIFY_VCENTER,
|
:justification => Graphics.TEXT_JUSTIFY_LEFT | Graphics.TEXT_JUSTIFY_VCENTER,
|
||||||
@ -64,7 +64,7 @@ class HomeAssistantGlanceView extends WatchUi.GlanceView {
|
|||||||
:locY => 3 * h / 6
|
:locY => 3 * h / 6
|
||||||
});
|
});
|
||||||
mApiStatus = new WatchUi.Text({
|
mApiStatus = new WatchUi.Text({
|
||||||
:text => RezStrings.getChecking(),
|
:text => WatchUi.loadResource($.Rez.Strings.Checking) as Lang.String,
|
||||||
:color => Graphics.COLOR_WHITE,
|
:color => Graphics.COLOR_WHITE,
|
||||||
:font => Graphics.FONT_XTINY,
|
:font => Graphics.FONT_XTINY,
|
||||||
:justification => Graphics.TEXT_JUSTIFY_LEFT | Graphics.TEXT_JUSTIFY_VCENTER,
|
:justification => Graphics.TEXT_JUSTIFY_LEFT | Graphics.TEXT_JUSTIFY_VCENTER,
|
||||||
@ -72,7 +72,7 @@ class HomeAssistantGlanceView extends WatchUi.GlanceView {
|
|||||||
:locY => 3 * h / 6
|
:locY => 3 * h / 6
|
||||||
});
|
});
|
||||||
mMenuText = new WatchUi.Text({
|
mMenuText = new WatchUi.Text({
|
||||||
:text => RezStrings.getGlanceMenu() + ":",
|
:text => WatchUi.loadResource($.Rez.Strings.GlanceMenu) as Lang.String + ":",
|
||||||
:color => Graphics.COLOR_WHITE,
|
:color => Graphics.COLOR_WHITE,
|
||||||
:font => Graphics.FONT_XTINY,
|
:font => Graphics.FONT_XTINY,
|
||||||
:justification => Graphics.TEXT_JUSTIFY_LEFT | Graphics.TEXT_JUSTIFY_VCENTER,
|
:justification => Graphics.TEXT_JUSTIFY_LEFT | Graphics.TEXT_JUSTIFY_VCENTER,
|
||||||
@ -80,7 +80,7 @@ class HomeAssistantGlanceView extends WatchUi.GlanceView {
|
|||||||
:locY => 5 * h / 6
|
:locY => 5 * h / 6
|
||||||
});
|
});
|
||||||
mMenuStatus = new WatchUi.Text({
|
mMenuStatus = new WatchUi.Text({
|
||||||
:text => RezStrings.getChecking(),
|
:text => WatchUi.loadResource($.Rez.Strings.Checking) as Lang.String,
|
||||||
:color => Graphics.COLOR_WHITE,
|
:color => Graphics.COLOR_WHITE,
|
||||||
:font => Graphics.FONT_XTINY,
|
:font => Graphics.FONT_XTINY,
|
||||||
:justification => Graphics.TEXT_JUSTIFY_LEFT | Graphics.TEXT_JUSTIFY_VCENTER,
|
:justification => Graphics.TEXT_JUSTIFY_LEFT | Graphics.TEXT_JUSTIFY_VCENTER,
|
||||||
|
@ -44,60 +44,44 @@ 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(WatchUi.loadResource($.Rez.Strings.NoPhone) as Lang.String + ".");
|
||||||
}
|
|
||||||
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(WatchUi.loadResource($.Rez.Strings.ApiFlood) as Lang.String);
|
||||||
}
|
|
||||||
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(WatchUi.loadResource($.Rez.Strings.NoResponse) as Lang.String);
|
||||||
}
|
|
||||||
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(WatchUi.loadResource($.Rez.Strings.NoJson) as Lang.String);
|
||||||
}
|
|
||||||
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(WatchUi.loadResource($.Rez.Strings.ApiUrlNotFound) as Lang.String);
|
||||||
}
|
|
||||||
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 = WatchUi.loadResource($.Rez.Strings.Executed) as Lang.String;
|
||||||
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(entity_id)) {
|
if ((d[i].get("entity_id") as Lang.String).equals(entity_id)) {
|
||||||
toast = (d[i].get("attributes") as Lang.Dictionary).get("friendly_name") as Lang.String;
|
toast = (d[i].get("attributes") as Lang.Dictionary).get("friendly_name") as Lang.String;
|
||||||
@ -117,10 +101,8 @@ 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(WatchUi.loadResource($.Rez.Strings.UnhandledHttpErr) as Lang.String + 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(WatchUi.loadResource($.Rez.Strings.NoPhone) as Lang.String + ".");
|
||||||
}
|
|
||||||
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(WatchUi.loadResource($.Rez.Strings.NoInternet) as Lang.String + ".");
|
||||||
}
|
|
||||||
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) {
|
||||||
|
@ -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 = WatchUi.loadResource($.Rez.Strings.Unavailable) as Lang.String;
|
||||||
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(WatchUi.loadResource($.Rez.Strings.NoPhone) as Lang.String + ".");
|
||||||
}
|
|
||||||
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(WatchUi.loadResource($.Rez.Strings.ApiFlood) as Lang.String);
|
||||||
}
|
|
||||||
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(WatchUi.loadResource($.Rez.Strings.NoResponse) as Lang.String);
|
||||||
}
|
|
||||||
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(WatchUi.loadResource($.Rez.Strings.NoJson) as Lang.String);
|
||||||
}
|
|
||||||
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,21 +120,17 @@ 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(WatchUi.loadResource($.Rez.Strings.ApiUrlNotFound) as Lang.String);
|
||||||
}
|
|
||||||
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(WatchUi.loadResource($.Rez.Strings.TemplateError) as Lang.String);
|
||||||
}
|
|
||||||
ErrorView.show(RezStrings.getTemplateError());
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 200:
|
case 200:
|
||||||
status = RezStrings.getAvailable();
|
status = WatchUi.loadResource($.Rez.Strings.Available) as Lang.String;
|
||||||
setSubLabel(data);
|
setSubLabel(data);
|
||||||
requestUpdate();
|
requestUpdate();
|
||||||
// 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.
|
||||||
@ -154,32 +138,24 @@ 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(WatchUi.loadResource($.Rez.Strings.UnhandledHttpErr) as Lang.String + responseCode);
|
||||||
}
|
|
||||||
ErrorView.show(RezStrings.getUnhandledHttpErr() + responseCode);
|
|
||||||
}
|
}
|
||||||
getApp().setApiStatus(status);
|
getApp().setApiStatus(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
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(WatchUi.loadResource($.Rez.Strings.NoPhone) as Lang.String + ".");
|
||||||
}
|
getApp().setApiStatus(WatchUi.loadResource($.Rez.Strings.Unavailable) as Lang.String);
|
||||||
ErrorView.show(RezStrings.getNoPhone() + ".");
|
|
||||||
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(WatchUi.loadResource($.Rez.Strings.NoInternet) as Lang.String + ".");
|
||||||
}
|
getApp().setApiStatus(WatchUi.loadResource($.Rez.Strings.Unavailable) as Lang.String);
|
||||||
ErrorView.show(RezStrings.getNoInternet() + ".");
|
|
||||||
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 },
|
||||||
|
@ -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 = WatchUi.loadResource($.Rez.Strings.Unavailable) as Lang.String;
|
||||||
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(WatchUi.loadResource($.Rez.Strings.NoPhone) as Lang.String + ".");
|
||||||
}
|
|
||||||
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(WatchUi.loadResource($.Rez.Strings.ApiFlood) as Lang.String);
|
||||||
}
|
|
||||||
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(WatchUi.loadResource($.Rez.Strings.NoResponse) as Lang.String);
|
||||||
}
|
|
||||||
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(WatchUi.loadResource($.Rez.Strings.NoJson) as Lang.String);
|
||||||
}
|
|
||||||
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,32 +101,24 @@ 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(WatchUi.loadResource($.Rez.Strings.ApiUrlNotFound) as Lang.String);
|
||||||
}
|
|
||||||
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;
|
||||||
|
|
||||||
case 200:
|
case 200:
|
||||||
status = RezStrings.getAvailable();
|
status = WatchUi.loadResource($.Rez.Strings.Available) as Lang.String;
|
||||||
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,32 +128,24 @@ 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(WatchUi.loadResource($.Rez.Strings.UnhandledHttpErr) as Lang.String + responseCode);
|
||||||
}
|
|
||||||
ErrorView.show(RezStrings.getUnhandledHttpErr() + responseCode);
|
|
||||||
}
|
}
|
||||||
getApp().setApiStatus(status);
|
getApp().setApiStatus(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
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(WatchUi.loadResource($.Rez.Strings.NoPhone) as Lang.String + ".");
|
||||||
}
|
getApp().setApiStatus(WatchUi.loadResource($.Rez.Strings.Unavailable) as Lang.String);
|
||||||
ErrorView.show(RezStrings.getNoPhone() + ".");
|
|
||||||
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(WatchUi.loadResource($.Rez.Strings.NoInternet) as Lang.String + ".");
|
||||||
}
|
getApp().setApiStatus(WatchUi.loadResource($.Rez.Strings.Unavailable) as Lang.String);
|
||||||
ErrorView.show(RezStrings.getNoInternet() + ".");
|
|
||||||
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,47 +164,35 @@ 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 = WatchUi.loadResource($.Rez.Strings.Unavailable) as Lang.String;
|
||||||
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(WatchUi.loadResource($.Rez.Strings.NoPhone) as Lang.String + ".");
|
||||||
}
|
|
||||||
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(WatchUi.loadResource($.Rez.Strings.ApiFlood) as Lang.String);
|
||||||
}
|
|
||||||
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(WatchUi.loadResource($.Rez.Strings.NoResponse) as Lang.String);
|
||||||
}
|
|
||||||
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(WatchUi.loadResource($.Rez.Strings.NoJson) as Lang.String);
|
||||||
}
|
|
||||||
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(WatchUi.loadResource($.Rez.Strings.ApiUrlNotFound) as Lang.String);
|
||||||
}
|
|
||||||
ErrorView.show(RezStrings.getApiUrlNotFound());
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 200:
|
case 200:
|
||||||
@ -241,39 +201,31 @@ 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
status = RezStrings.getAvailable();
|
status = WatchUi.loadResource($.Rez.Strings.Available) as Lang.String;
|
||||||
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(WatchUi.loadResource($.Rez.Strings.UnhandledHttpErr) as Lang.String + responseCode);
|
||||||
}
|
|
||||||
ErrorView.show(RezStrings.getUnhandledHttpErr() + responseCode);
|
|
||||||
}
|
}
|
||||||
getApp().setApiStatus(status);
|
getApp().setApiStatus(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
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(WatchUi.loadResource($.Rez.Strings.NoPhone) as Lang.String + ".");
|
||||||
} 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(WatchUi.loadResource($.Rez.Strings.NoInternet) as Lang.String + ".");
|
||||||
} else {
|
} else {
|
||||||
// Updated SDK and got a new error
|
// Updated SDK and got a new error
|
||||||
// ERROR: venu: Cannot find symbol ':substring' on type 'PolyType<Null or $.Toybox.Lang.Object>'.
|
// ERROR: venu: Cannot find symbol ':substring' on type 'PolyType<Null or $.Toybox.Lang.Object>'.
|
||||||
@ -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,
|
||||||
|
@ -34,11 +34,8 @@ class HomeAssistantView extends WatchUi.Menu2 {
|
|||||||
:theme as WatchUi.MenuTheme or Null
|
:theme as WatchUi.MenuTheme or Null
|
||||||
} or Null
|
} or Null
|
||||||
) {
|
) {
|
||||||
|
|
||||||
if (options == null) {
|
if (options == null) {
|
||||||
options = {
|
options = { :title => definition.get("title") as Lang.String };
|
||||||
:title => definition.get("title") as Lang.String
|
|
||||||
};
|
|
||||||
} else {
|
} else {
|
||||||
options.put(:title, definition.get("title") as Lang.String);
|
options.put(:title, definition.get("title") as Lang.String);
|
||||||
}
|
}
|
||||||
@ -146,32 +143,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());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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();
|
||||||
}
|
}
|
||||||
|
@ -1,206 +0,0 @@
|
|||||||
//-----------------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Distributed under MIT Licence
|
|
||||||
// See https://github.com/house-of-abbey/GarminHomeAssistant/blob/main/LICENSE.
|
|
||||||
//
|
|
||||||
//-----------------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// GarminHomeAssistant is a Garmin IQ application written in Monkey C and routinely
|
|
||||||
// tested on a Venu 2 device. The source code is provided at:
|
|
||||||
// https://github.com/house-of-abbey/GarminHomeAssistant.
|
|
||||||
//
|
|
||||||
// P A Abbey & J D Abbey & Someone0nEarth, 31 October 2023
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// Description:
|
|
||||||
//
|
|
||||||
// Load the strings centrally once rather than initialising locally within separate
|
|
||||||
// classes. This is to solve a problem with out of memory errors in some devices,
|
|
||||||
// e.g. Vivoactive 3.
|
|
||||||
//
|
|
||||||
//-----------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
using Toybox.Lang;
|
|
||||||
using Toybox.WatchUi;
|
|
||||||
|
|
||||||
class RezStrings {
|
|
||||||
|
|
||||||
(:glance)
|
|
||||||
private static var strAppName as Lang.String or Null;
|
|
||||||
private static var strConfirm as Lang.String or Null;
|
|
||||||
private static var strExecuted as Lang.String or Null;
|
|
||||||
(:glance)
|
|
||||||
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;
|
|
||||||
(:glance)
|
|
||||||
private static var strNoApiKey as Lang.String or Null;
|
|
||||||
(:glance)
|
|
||||||
private static var strNoApiUrl as Lang.String or Null;
|
|
||||||
(:glance)
|
|
||||||
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)
|
|
||||||
private static var strAvailable as Lang.String or Null;
|
|
||||||
(:glance)
|
|
||||||
private static var strChecking as Lang.String or Null;
|
|
||||||
(:glance)
|
|
||||||
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
|
|
||||||
// for 'WatchUi.loadResource' to be available.
|
|
||||||
(:glance)
|
|
||||||
static function update_glance() {
|
|
||||||
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);
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Can't initialise a constant directly, have to be initialised via a function
|
|
||||||
// for 'WatchUi.loadResource' to be available.
|
|
||||||
static function update() {
|
|
||||||
strAppName = WatchUi.loadResource($.Rez.Strings.AppName);
|
|
||||||
strConfirm = WatchUi.loadResource($.Rez.Strings.Confirm);
|
|
||||||
strExecuted = WatchUi.loadResource($.Rez.Strings.Executed);
|
|
||||||
strNoPhone = WatchUi.loadResource($.Rez.Strings.NoPhone);
|
|
||||||
strNoInternet = WatchUi.loadResource($.Rez.Strings.NoInternet);
|
|
||||||
strNoResponse = WatchUi.loadResource($.Rez.Strings.NoResponse);
|
|
||||||
strNoApiKey = WatchUi.loadResource($.Rez.Strings.NoAPIKey);
|
|
||||||
strNoApiUrl = WatchUi.loadResource($.Rez.Strings.NoApiUrl);
|
|
||||||
strNoConfigUrl = WatchUi.loadResource($.Rez.Strings.NoConfigUrl);
|
|
||||||
strApiFlood = WatchUi.loadResource($.Rez.Strings.ApiFlood);
|
|
||||||
strApiUrlNotFound = WatchUi.loadResource($.Rez.Strings.ApiUrlNotFound);
|
|
||||||
strConfigUrlNotFound = WatchUi.loadResource($.Rez.Strings.ConfigUrlNotFound);
|
|
||||||
strNoJson = WatchUi.loadResource($.Rez.Strings.NoJson);
|
|
||||||
strUnhandledHttpErr = WatchUi.loadResource($.Rez.Strings.UnhandledHttpErr);
|
|
||||||
strTrailingSlashErr = WatchUi.loadResource($.Rez.Strings.TrailingSlashErr);
|
|
||||||
strWebhookFailed = WatchUi.loadResource($.Rez.Strings.WebhookFailed);
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
static function getAppName() as Lang.String {
|
|
||||||
return strAppName;
|
|
||||||
}
|
|
||||||
|
|
||||||
static function getConfirm() as Lang.String {
|
|
||||||
return strConfirm;
|
|
||||||
}
|
|
||||||
|
|
||||||
static function getExecuted() as Lang.String {
|
|
||||||
return strExecuted;
|
|
||||||
}
|
|
||||||
|
|
||||||
static function getNoPhone() as Lang.String {
|
|
||||||
return strNoPhone;
|
|
||||||
}
|
|
||||||
|
|
||||||
static function getNoInternet() as Lang.String {
|
|
||||||
return strNoInternet;
|
|
||||||
}
|
|
||||||
|
|
||||||
static function getNoResponse() as Lang.String {
|
|
||||||
return strNoResponse;
|
|
||||||
}
|
|
||||||
|
|
||||||
static function getNoApiKey() as Lang.String {
|
|
||||||
return strNoApiKey;
|
|
||||||
}
|
|
||||||
|
|
||||||
static function getNoApiUrl() as Lang.String {
|
|
||||||
return strNoApiUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
static function getNoConfigUrl() as Lang.String {
|
|
||||||
return strNoConfigUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
static function getApiFlood() as Lang.String {
|
|
||||||
return strApiFlood;
|
|
||||||
}
|
|
||||||
|
|
||||||
static function getApiUrlNotFound() as Lang.String {
|
|
||||||
return strApiUrlNotFound;
|
|
||||||
}
|
|
||||||
|
|
||||||
static function getConfigUrlNotFound() as Lang.String {
|
|
||||||
return strConfigUrlNotFound;
|
|
||||||
}
|
|
||||||
|
|
||||||
static function getNoJson() as Lang.String {
|
|
||||||
return strNoJson;
|
|
||||||
}
|
|
||||||
|
|
||||||
static function getUnhandledHttpErr() as Lang.String {
|
|
||||||
return strUnhandledHttpErr;
|
|
||||||
}
|
|
||||||
|
|
||||||
static function getTrailingSlashErr() as Lang.String {
|
|
||||||
return strTrailingSlashErr;
|
|
||||||
}
|
|
||||||
|
|
||||||
static function getWebhookFailed() as Lang.String {
|
|
||||||
return strWebhookFailed;
|
|
||||||
}
|
|
||||||
|
|
||||||
static function getTemplateError() as Lang.String {
|
|
||||||
return strTemplateError;
|
|
||||||
}
|
|
||||||
|
|
||||||
static function getAvailable() as Lang.String {
|
|
||||||
return strAvailable;
|
|
||||||
}
|
|
||||||
|
|
||||||
static function getChecking() as Lang.String {
|
|
||||||
return strChecking;
|
|
||||||
}
|
|
||||||
|
|
||||||
static function getUnavailable() as Lang.String {
|
|
||||||
return strUnavailable;
|
|
||||||
}
|
|
||||||
|
|
||||||
static function getUnconfigured() as Lang.String {
|
|
||||||
return strUnconfigured;
|
|
||||||
}
|
|
||||||
|
|
||||||
static function getCached() as Lang.String {
|
|
||||||
return strCached;
|
|
||||||
}
|
|
||||||
|
|
||||||
static function getGlanceMenu() as Lang.String {
|
|
||||||
return strGlanceMenu;
|
|
||||||
}
|
|
||||||
|
|
||||||
static function getMemory() as Lang.String {
|
|
||||||
return strMemory;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -61,7 +61,7 @@ class RootView extends ScalableView {
|
|||||||
var w = dc.getWidth();
|
var w = dc.getWidth();
|
||||||
|
|
||||||
mTitle = new WatchUi.Text({
|
mTitle = new WatchUi.Text({
|
||||||
:text => RezStrings.getAppName(),
|
:text => WatchUi.loadResource($.Rez.Strings.AppName) as Lang.String,
|
||||||
:color => Graphics.COLOR_WHITE,
|
:color => Graphics.COLOR_WHITE,
|
||||||
:font => Graphics.FONT_TINY,
|
:font => Graphics.FONT_TINY,
|
||||||
:justification => Graphics.TEXT_JUSTIFY_CENTER | Graphics.TEXT_JUSTIFY_VCENTER,
|
:justification => Graphics.TEXT_JUSTIFY_CENTER | Graphics.TEXT_JUSTIFY_VCENTER,
|
||||||
@ -78,7 +78,7 @@ class RootView extends ScalableView {
|
|||||||
:locY => pixelsForScreen(50.0)
|
:locY => pixelsForScreen(50.0)
|
||||||
});
|
});
|
||||||
mApiStatus = new WatchUi.Text({
|
mApiStatus = new WatchUi.Text({
|
||||||
:text => RezStrings.getChecking(),
|
:text => WatchUi.loadResource($.Rez.Strings.Checking) as Lang.String,
|
||||||
:color => Graphics.COLOR_WHITE,
|
:color => Graphics.COLOR_WHITE,
|
||||||
:font => Graphics.FONT_XTINY,
|
:font => Graphics.FONT_XTINY,
|
||||||
:justification => Graphics.TEXT_JUSTIFY_LEFT | Graphics.TEXT_JUSTIFY_VCENTER,
|
:justification => Graphics.TEXT_JUSTIFY_LEFT | Graphics.TEXT_JUSTIFY_VCENTER,
|
||||||
@ -86,7 +86,7 @@ class RootView extends ScalableView {
|
|||||||
:locY => pixelsForScreen(50.0)
|
:locY => pixelsForScreen(50.0)
|
||||||
});
|
});
|
||||||
mMenuText = new WatchUi.Text({
|
mMenuText = new WatchUi.Text({
|
||||||
:text => RezStrings.getGlanceMenu() + ":",
|
:text => WatchUi.loadResource($.Rez.Strings.GlanceMenu) as Lang.String + ":",
|
||||||
:color => Graphics.COLOR_WHITE,
|
:color => Graphics.COLOR_WHITE,
|
||||||
:font => Graphics.FONT_XTINY,
|
:font => Graphics.FONT_XTINY,
|
||||||
:justification => Graphics.TEXT_JUSTIFY_RIGHT | Graphics.TEXT_JUSTIFY_VCENTER,
|
:justification => Graphics.TEXT_JUSTIFY_RIGHT | Graphics.TEXT_JUSTIFY_VCENTER,
|
||||||
@ -94,7 +94,7 @@ class RootView extends ScalableView {
|
|||||||
:locY => pixelsForScreen(60.0)
|
:locY => pixelsForScreen(60.0)
|
||||||
});
|
});
|
||||||
mMenuStatus = new WatchUi.Text({
|
mMenuStatus = new WatchUi.Text({
|
||||||
:text => RezStrings.getChecking(),
|
:text => WatchUi.loadResource($.Rez.Strings.Checking) as Lang.String,
|
||||||
:color => Graphics.COLOR_WHITE,
|
:color => Graphics.COLOR_WHITE,
|
||||||
:font => Graphics.FONT_XTINY,
|
:font => Graphics.FONT_XTINY,
|
||||||
:justification => Graphics.TEXT_JUSTIFY_LEFT | Graphics.TEXT_JUSTIFY_VCENTER,
|
:justification => Graphics.TEXT_JUSTIFY_LEFT | Graphics.TEXT_JUSTIFY_VCENTER,
|
||||||
@ -102,7 +102,7 @@ class RootView extends ScalableView {
|
|||||||
:locY => pixelsForScreen(60.0)
|
:locY => pixelsForScreen(60.0)
|
||||||
});
|
});
|
||||||
mMemText = new WatchUi.Text({
|
mMemText = new WatchUi.Text({
|
||||||
:text => RezStrings.getMemory() + ":",
|
:text => WatchUi.loadResource($.Rez.Strings.Memory) as Lang.String + ":",
|
||||||
:color => Graphics.COLOR_WHITE,
|
:color => Graphics.COLOR_WHITE,
|
||||||
:font => Graphics.FONT_XTINY,
|
:font => Graphics.FONT_XTINY,
|
||||||
:justification => Graphics.TEXT_JUSTIFY_RIGHT | Graphics.TEXT_JUSTIFY_VCENTER,
|
:justification => Graphics.TEXT_JUSTIFY_RIGHT | Graphics.TEXT_JUSTIFY_VCENTER,
|
||||||
@ -110,7 +110,7 @@ class RootView extends ScalableView {
|
|||||||
:locY => pixelsForScreen(70.0)
|
:locY => pixelsForScreen(70.0)
|
||||||
});
|
});
|
||||||
mMemStatus = new WatchUi.Text({
|
mMemStatus = new WatchUi.Text({
|
||||||
:text => RezStrings.getChecking(),
|
:text => WatchUi.loadResource($.Rez.Strings.Checking) as Lang.String,
|
||||||
:color => Graphics.COLOR_WHITE,
|
:color => Graphics.COLOR_WHITE,
|
||||||
:font => Graphics.FONT_XTINY,
|
:font => Graphics.FONT_XTINY,
|
||||||
:justification => Graphics.TEXT_JUSTIFY_LEFT | Graphics.TEXT_JUSTIFY_VCENTER,
|
:justification => Graphics.TEXT_JUSTIFY_LEFT | Graphics.TEXT_JUSTIFY_VCENTER,
|
||||||
@ -139,7 +139,7 @@ class RootView extends ScalableView {
|
|||||||
mMenuStatus.draw(dc);
|
mMenuStatus.draw(dc);
|
||||||
mMemText.draw(dc);
|
mMemText.draw(dc);
|
||||||
var stats = System.getSystemStats();
|
var stats = System.getSystemStats();
|
||||||
var memUsed = (100 * stats.usedMemory) / stats.totalMemory;
|
var memUsed = (100f * stats.usedMemory) / stats.totalMemory;
|
||||||
mMemStatus.setText(memUsed.format("%.1f") + "%");
|
mMemStatus.setText(memUsed.format("%.1f") + "%");
|
||||||
if (stats.usedMemory > Globals.scLowMem * stats.totalMemory) {
|
if (stats.usedMemory > Globals.scLowMem * stats.totalMemory) {
|
||||||
mMemStatus.setColor(Graphics.COLOR_RED);
|
mMemStatus.setColor(Graphics.COLOR_RED);
|
||||||
|
@ -42,7 +42,6 @@ class Settings {
|
|||||||
private static var mBatteryRefreshRate as Lang.Number = 15; // minutes
|
private static var mBatteryRefreshRate as Lang.Number = 15; // minutes
|
||||||
private static var mIsApp as Lang.Boolean = false;
|
private static var mIsApp as Lang.Boolean = false;
|
||||||
private static var mHasService as Lang.Boolean = false;
|
private static var mHasService as Lang.Boolean = false;
|
||||||
|
|
||||||
// Must keep the object so it doesn't get garbage collected.
|
// Must keep the object so it doesn't get garbage collected.
|
||||||
private static var mWebhookManager as WebhookManager or Null;
|
private static var mWebhookManager as WebhookManager or Null;
|
||||||
|
|
||||||
@ -75,7 +74,8 @@ class Settings {
|
|||||||
} else if (
|
} else if (
|
||||||
mHasService and
|
mHasService and
|
||||||
((Background.getTemporalEventRegisteredTime() == null) or
|
((Background.getTemporalEventRegisteredTime() == null) or
|
||||||
(Background.getTemporalEventRegisteredTime() != (mBatteryRefreshRate * 60)))) {
|
(Background.getTemporalEventRegisteredTime() != (mBatteryRefreshRate * 60)))
|
||||||
|
) {
|
||||||
Background.registerForTemporalEvent(new Time.Duration(mBatteryRefreshRate * 60)); // Convert to seconds
|
Background.registerForTemporalEvent(new Time.Duration(mBatteryRefreshRate * 60)); // Convert to seconds
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -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 {
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
// larger submissions in order to prevent overflow of the blue tooth stack.
|
// larger submissions in order to prevent overflow of the blue tooth stack.
|
||||||
//
|
//
|
||||||
//-----------------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
// Usage:
|
// Usage:
|
||||||
// wl = new WebLog();
|
// wl = new WebLog();
|
||||||
// wl.clear();
|
// wl.clear();
|
||||||
@ -28,7 +28,7 @@
|
|||||||
// wl.flush();
|
// wl.flush();
|
||||||
//
|
//
|
||||||
// https://domain.name/path/log.php
|
// https://domain.name/path/log.php
|
||||||
//
|
//
|
||||||
// <?php
|
// <?php
|
||||||
// $myfile = fopen("log", "a");
|
// $myfile = fopen("log", "a");
|
||||||
// $queries = array();
|
// $queries = array();
|
||||||
@ -36,11 +36,11 @@
|
|||||||
// fwrite($myfile, $queries['log']);
|
// fwrite($myfile, $queries['log']);
|
||||||
// print "Success";
|
// print "Success";
|
||||||
// ?>
|
// ?>
|
||||||
//
|
//
|
||||||
// Logs published to: https://domain.name/path/log
|
// Logs published to: https://domain.name/path/log
|
||||||
//
|
//
|
||||||
// https://domain.name/path/log_clear.php
|
// https://domain.name/path/log_clear.php
|
||||||
//
|
//
|
||||||
// <?php
|
// <?php
|
||||||
// $myfile = fopen("log", "w");
|
// $myfile = fopen("log", "w");
|
||||||
// fwrite($myfile, "");
|
// fwrite($myfile, "");
|
||||||
@ -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,15 +104,11 @@ 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,
|
||||||
{
|
{ "log" => buffer },
|
||||||
"log" => buffer
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
:method => Communications.HTTP_REQUEST_METHOD_GET,
|
:method => Communications.HTTP_REQUEST_METHOD_GET,
|
||||||
:headers => {
|
:headers => {
|
||||||
@ -134,9 +126,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 +146,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);
|
// }
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,46 +32,34 @@ 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(WatchUi.loadResource($.Rez.Strings.WebhookFailed) as Lang.String + "\n" + WatchUi.loadResource($.Rez.Strings.NoPhone) as Lang.String + ".");
|
||||||
}
|
|
||||||
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(WatchUi.loadResource($.Rez.Strings.WebhookFailed) as Lang.String + "\n" + WatchUi.loadResource($.Rez.Strings.ApiFlood) as Lang.String);
|
||||||
}
|
|
||||||
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(WatchUi.loadResource($.Rez.Strings.WebhookFailed) as Lang.String + "\n" + WatchUi.loadResource($.Rez.Strings.NoResponse) as Lang.String);
|
||||||
}
|
|
||||||
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(WatchUi.loadResource($.Rez.Strings.WebhookFailed) as Lang.String + "\n" + WatchUi.loadResource($.Rez.Strings.NoJson) as Lang.String);
|
||||||
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(WatchUi.loadResource($.Rez.Strings.WebhookFailed) as Lang.String + "\n" + WatchUi.loadResource($.Rez.Strings.ApiUrlNotFound) as Lang.String);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 201:
|
case 201:
|
||||||
@ -99,33 +87,27 @@ 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(WatchUi.loadResource($.Rez.Strings.WebhookFailed) as Lang.String);
|
||||||
}
|
}
|
||||||
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(WatchUi.loadResource($.Rez.Strings.WebhookFailed) as Lang.String + "\n" + WatchUi.loadResource($.Rez.Strings.UnhandledHttpErr) as Lang.String + 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",
|
||||||
{
|
{
|
||||||
"device_id" => System.getDeviceSettings().uniqueIdentifier,
|
"device_id" => System.getDeviceSettings().uniqueIdentifier,
|
||||||
"app_id" => "garmin_home_assistant",
|
"app_id" => "garmin_home_assistant",
|
||||||
"app_name" => RezStrings.getAppName(),
|
"app_name" => WatchUi.loadResource($.Rez.Strings.AppName) as Lang.String,
|
||||||
"app_version" => "",
|
"app_version" => "",
|
||||||
"device_name" => "Garmin Watch",
|
"device_name" => "Garmin Watch",
|
||||||
"manufacturer" => "Garmin",
|
"manufacturer" => "Garmin",
|
||||||
@ -151,83 +133,64 @@ 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(WatchUi.loadResource($.Rez.Strings.WebhookFailed) as Lang.String + "\n" + WatchUi.loadResource($.Rez.Strings.NoPhone) as Lang.String + ".");
|
||||||
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(WatchUi.loadResource($.Rez.Strings.WebhookFailed) as Lang.String + "\n" + WatchUi.loadResource($.Rez.Strings.ApiFlood) as Lang.String);
|
||||||
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(WatchUi.loadResource($.Rez.Strings.WebhookFailed) as Lang.String + "\n" + WatchUi.loadResource($.Rez.Strings.NoResponse) as Lang.String);
|
||||||
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(WatchUi.loadResource($.Rez.Strings.WebhookFailed) as Lang.String + "\n" + WatchUi.loadResource($.Rez.Strings.NoJson) as Lang.String);
|
||||||
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(WatchUi.loadResource($.Rez.Strings.WebhookFailed) as Lang.String + "\n" + WatchUi.loadResource($.Rez.Strings.ApiUrlNotFound) as Lang.String);
|
||||||
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(WatchUi.loadResource($.Rez.Strings.WebhookFailed) as Lang.String);
|
||||||
}
|
}
|
||||||
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(WatchUi.loadResource($.Rez.Strings.WebhookFailed) as Lang.String + "\n" + WatchUi.loadResource($.Rez.Strings.UnhandledHttpErr) as Lang.String + responseCode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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(),
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user