mirror of
https://github.com/house-of-abbey/GarminHomeAssistant.git
synced 2025-08-02 01:48:32 +00:00
simplify delegate, toggle switch for empty response body
This commit is contained in:
@ -141,7 +141,7 @@ class HomeAssistantService {
|
||||
:service => service,
|
||||
:data => data,
|
||||
:exit => exit,
|
||||
}, null),
|
||||
}),
|
||||
WatchUi.SLIDE_LEFT
|
||||
);
|
||||
} else if (! phoneConnected) {
|
||||
|
@ -61,7 +61,7 @@ class HomeAssistantSyncDelegate extends Communications.SyncDelegate {
|
||||
"Content-Type" => Communications.REQUEST_CONTENT_TYPE_JSON,
|
||||
"Authorization" => "Bearer " + Settings.getApiKey()
|
||||
},
|
||||
:responseType => Communications.HTTP_RESPONSE_CONTENT_TYPE_JSON
|
||||
:responseType => Communications.HTTP_RESPONSE_CONTENT_TYPE_JSON,
|
||||
},
|
||||
method(:haCallback)
|
||||
);
|
||||
@ -107,6 +107,5 @@ class HomeAssistantSyncDelegate extends Communications.SyncDelegate {
|
||||
|
||||
Communications.cancelAllRequests();
|
||||
Communications.notifySyncComplete(syncError);
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -218,6 +218,12 @@ class HomeAssistantToggleMenuItem extends WatchUi.ToggleMenuItem {
|
||||
//! @param data An array of dictionaries, each representing a Home Assistant entity state.
|
||||
//
|
||||
function setToggleStateWithData(data as Lang.Array) {
|
||||
// if there's no response body, let's assume that what we did, happened, and flip the toggle
|
||||
if (data.size() == 0) {
|
||||
setEnabled(!isEnabled());
|
||||
}
|
||||
|
||||
else {
|
||||
for(var i = 0; i < data.size(); i++) {
|
||||
if ((data[i].get("entity_id") as Lang.String).equals(mData.get("entity_id"))) {
|
||||
var state = data[i].get("state") as Lang.String;
|
||||
@ -227,6 +233,7 @@ class HomeAssistantToggleMenuItem extends WatchUi.ToggleMenuItem {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//! Set the state of the toggle menu item.
|
||||
//!
|
||||
@ -268,9 +275,6 @@ class HomeAssistantToggleMenuItem extends WatchUi.ToggleMenuItem {
|
||||
:data => mData,
|
||||
:callback => method(:setToggleStateWithData),
|
||||
:exit => mExit,
|
||||
}, {
|
||||
:confirmMethod => method(:onConfirm),
|
||||
:state => !isEnabled(),
|
||||
}),
|
||||
WatchUi.SLIDE_LEFT
|
||||
);
|
||||
|
@ -16,12 +16,9 @@ class WifiLteExecutionConfirmDelegate extends WatchUi.ConfirmationDelegate {
|
||||
:exit as Lang.Boolean
|
||||
};
|
||||
|
||||
private var mToggleMethod as Method(b as Lang.Boolean) as Void or Null;
|
||||
private var mToggleState as Lang.Boolean or Null;
|
||||
private var mHasToast as Lang.Boolean = false;
|
||||
private var mTimer as Timer.Timer or Null;
|
||||
|
||||
|
||||
//! Initializes a confirmation delegate to confirm a Wi-Fi or LTE command exection
|
||||
//!
|
||||
//! @param options A dictionary describing the command to be executed:
|
||||
@ -31,10 +28,6 @@ class WifiLteExecutionConfirmDelegate extends WatchUi.ConfirmationDelegate {
|
||||
//! - callback: (For type `"entity"`) A callback method (Method<data as Dictionary>) to handle the response.
|
||||
//! - data: (Optional) A dictionary of data to send with the request.
|
||||
//! = exit: Boolean: true to exit after running command.
|
||||
//!
|
||||
//! @param toggleItem Optional toggle state information:
|
||||
//! - confirmMethod: A method to call after confirmation.
|
||||
//! - state: The state (boolean) that will be passed to the confirmMethod.
|
||||
function initialize(cOptions as {
|
||||
:type as Lang.String,
|
||||
:service as Lang.String or Null,
|
||||
@ -42,10 +35,7 @@ class WifiLteExecutionConfirmDelegate extends WatchUi.ConfirmationDelegate {
|
||||
:url as Lang.String or Null,
|
||||
:callback as Lang.Method or Null,
|
||||
:exit as Lang.Boolean,
|
||||
}, toggleItem as {
|
||||
:confirmMethod as Lang.Method,
|
||||
:state as Lang.Boolean
|
||||
} or Null) {
|
||||
}) {
|
||||
ConfirmationDelegate.initialize();
|
||||
|
||||
if (WatchUi has :showToast) {
|
||||
@ -60,10 +50,6 @@ class WifiLteExecutionConfirmDelegate extends WatchUi.ConfirmationDelegate {
|
||||
:callback => cOptions[:callback],
|
||||
:exit => cOptions[:exit]
|
||||
};
|
||||
if (toggleItem != null) {
|
||||
mToggleMethod = toggleItem[:confirmMethod];
|
||||
mToggleState = toggleItem[:state];
|
||||
}
|
||||
|
||||
var timeout = Settings.getConfirmTimeout(); // ms
|
||||
if (timeout > 0) {
|
||||
@ -83,9 +69,6 @@ class WifiLteExecutionConfirmDelegate extends WatchUi.ConfirmationDelegate {
|
||||
}
|
||||
|
||||
if (response == WatchUi.CONFIRM_YES) {
|
||||
if (mToggleMethod != null) {
|
||||
mToggleMethod.invoke(mToggleState);
|
||||
}
|
||||
trySync();
|
||||
}
|
||||
return true;
|
||||
@ -93,7 +76,6 @@ class WifiLteExecutionConfirmDelegate extends WatchUi.ConfirmationDelegate {
|
||||
|
||||
//! Initiates a bulk sync process to execute a command, if connections are available
|
||||
private function trySync() as Void {
|
||||
WatchUi.popView(WatchUi.SLIDE_IMMEDIATE);
|
||||
var connectionInfo = System.getDeviceSettings().connectionInfo;
|
||||
var keys = connectionInfo.keys();
|
||||
var possibleConnection = false;
|
||||
|
Reference in New Issue
Block a user