Update HomeAssistantToggleMenuItem.mc

Prevent multiple toggles for initiating one action. Only set the state when the called service returns with the confirmed value.
This commit is contained in:
Philip Abbey
2024-08-28 23:01:28 +01:00
parent 47a8a6e4e6
commit bbd9119a07

View File

@ -164,15 +164,14 @@ class HomeAssistantToggleMenuItem extends WatchUi.ToggleMenuItem {
}
function setState(s as Lang.Boolean) as Void {
// Toggle the UI back, we'll wait for confirmation from the Home Assistant
setEnabled(!isEnabled());
if (! System.getDeviceSettings().phoneConnected) {
// System.println("HomeAssistantToggleMenuItem getState(): No Phone connection, skipping API call.");
// Toggle the UI back
setEnabled(!isEnabled());
ErrorView.show(WatchUi.loadResource($.Rez.Strings.NoPhone) as Lang.String + ".");
} else if (! System.getDeviceSettings().connectionAvailable) {
// System.println("HomeAssistantToggleMenuItem getState(): No Internet connection, skipping API call.");
// Toggle the UI back
setEnabled(!isEnabled());
ErrorView.show(WatchUi.loadResource($.Rez.Strings.NoInternet) as Lang.String + ".");
} else {
// Updated SDK and got a new error