mirror of
https://github.com/house-of-abbey/GarminHomeAssistant.git
synced 2025-05-01 21:22:40 +00:00
1) Removed WatchUi.getCurrentView() API call in favour of a new method of ensuring only one ErrorView is pushed at a time. 2) Any error view will be cancelled when responses start working again, e.g. watch gets in Bluetooth range of the phone again. 3) Added error message decoding for misspelled entities. Co-Authored-By: Joseph Abbey <me@josephabbey.dev>
66 lines
2.0 KiB
MonkeyC
66 lines
2.0 KiB
MonkeyC
//-----------------------------------------------------------------------------------
|
|
//
|
|
// 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 & SomeoneOnEarth, 19 November 2023
|
|
//
|
|
//
|
|
// Description:
|
|
//
|
|
// Calling a Home Assistant confirmation dialogue view.
|
|
//
|
|
//-----------------------------------------------------------------------------------
|
|
|
|
using Toybox.Lang;
|
|
// Required for callback method definition
|
|
typedef Method as Toybox.Lang.Method;
|
|
using Toybox.WatchUi;
|
|
using Toybox.Timer;
|
|
using Toybox.Application.Properties;
|
|
|
|
class HomeAssistantConfirmation extends WatchUi.Confirmation {
|
|
|
|
function initialize() {
|
|
WatchUi.Confirmation.initialize(WatchUi.loadResource($.Rez.Strings.Confirm));
|
|
}
|
|
|
|
}
|
|
|
|
class HomeAssistantConfirmationDelegate extends WatchUi.ConfirmationDelegate {
|
|
private var mConfirmMethod;
|
|
private var mTimer;
|
|
|
|
function initialize(callback as Method() as Void) {
|
|
WatchUi.ConfirmationDelegate.initialize();
|
|
mConfirmMethod = callback;
|
|
var timeoutSeconds = Properties.getValue("confirm_timeout") as Lang.Number;
|
|
if (timeoutSeconds > 0) {
|
|
mTimer = new Timer.Timer();
|
|
mTimer.start(method(:onTimeout), timeoutSeconds * 1000, true);
|
|
}
|
|
}
|
|
|
|
function onResponse(response) as Lang.Boolean {
|
|
getApp().getQuitTimer().reset();
|
|
if (mTimer) {
|
|
mTimer.stop();
|
|
}
|
|
if (response == WatchUi.CONFIRM_YES) {
|
|
mConfirmMethod.invoke();
|
|
}
|
|
return true;
|
|
}
|
|
|
|
function onTimeout() as Void {
|
|
mTimer.stop();
|
|
WatchUi.popView(WatchUi.SLIDE_RIGHT);
|
|
}
|
|
}
|