mirror of
https://github.com/house-of-abbey/GarminHomeAssistant.git
synced 2025-06-18 20:38:39 +00:00
remove transcoding, move pin to settings, remove pin from schema
This commit is contained in:
@ -85,8 +85,7 @@ class HomeAssistantMenuItemFactory {
|
||||
template as Lang.String or Null,
|
||||
service as Lang.String or Null,
|
||||
confirm as Lang.Boolean,
|
||||
data as Lang.Dictionary or Null,
|
||||
pin as Lang.String or Null
|
||||
data as Lang.Dictionary or Null
|
||||
) as WatchUi.MenuItem {
|
||||
if (entity != null) {
|
||||
if (data == null) {
|
||||
@ -101,7 +100,6 @@ class HomeAssistantMenuItemFactory {
|
||||
template,
|
||||
service,
|
||||
confirm,
|
||||
pin,
|
||||
data,
|
||||
mTapTypeIcon,
|
||||
mMenuItemOptions,
|
||||
@ -113,7 +111,6 @@ class HomeAssistantMenuItemFactory {
|
||||
template,
|
||||
service,
|
||||
confirm,
|
||||
pin,
|
||||
data,
|
||||
mInfoTypeIcon,
|
||||
mMenuItemOptions,
|
||||
|
@ -111,7 +111,7 @@ class HomeAssistantPinConfirmationDelegate extends WatchUi.BehaviorDelegate {
|
||||
if (mFailures.isLocked()) {
|
||||
WatchUi.showToast("PIN input locked for " + mFailures.getLockedUntilSeconds() + " seconds", {});
|
||||
}
|
||||
mPin = pin.toCharArray();
|
||||
mPin = pin.toCharArray();
|
||||
mCurrentIndex = 0;
|
||||
mConfirmMethod = callback;
|
||||
mState = state;
|
||||
@ -127,7 +127,7 @@ class HomeAssistantPinConfirmationDelegate extends WatchUi.BehaviorDelegate {
|
||||
if (Attention has :vibrate && Settings.getVibrate()) {
|
||||
Attention.vibrate([new Attention.VibeProfile(25, 25)]);
|
||||
}
|
||||
var currentDigit = getTranscodedCurrentDigit();
|
||||
var currentDigit = mPin[mCurrentIndex].toString().toNumber(); // this is ugly, but apparently the only way for char<->number conversions
|
||||
if (currentDigit != null && currentDigit == instance.getDigit()) {
|
||||
// System.println("Pin digit " + (mCurrentIndex+1) + " matches");
|
||||
if (mCurrentIndex == mPin.size()-1) {
|
||||
@ -150,19 +150,6 @@ class HomeAssistantPinConfirmationDelegate extends WatchUi.BehaviorDelegate {
|
||||
return true;
|
||||
}
|
||||
|
||||
function getTranscodedCurrentDigit() as Number or Null {
|
||||
var currentDigit = mPin[mCurrentIndex].toString().toNumber(); // this is ugly, but apparently the only way for char<->number conversions
|
||||
if (currentDigit == null) {
|
||||
return null;
|
||||
}
|
||||
var pinMask = Settings.getPinMask();
|
||||
var maskDigit = pinMask.substring(mCurrentIndex, mCurrentIndex+1).toNumber();
|
||||
if (maskDigit == null) {
|
||||
return currentDigit;
|
||||
}
|
||||
return ((currentDigit + maskDigit - 1) % 4) + 1;
|
||||
}
|
||||
|
||||
function resetTimer() {
|
||||
var timeout = Settings.getConfirmTimeout(); // ms
|
||||
if (timeout > 0) {
|
||||
|
@ -28,14 +28,12 @@ class HomeAssistantTapMenuItem extends WatchUi.IconMenuItem {
|
||||
private var mService as Lang.String or Null;
|
||||
private var mConfirm as Lang.Boolean;
|
||||
private var mData as Lang.Dictionary or Null;
|
||||
private var mPin as Lang.String or Null;
|
||||
|
||||
function initialize(
|
||||
label as Lang.String or Lang.Symbol,
|
||||
template as Lang.String,
|
||||
service as Lang.String or Null,
|
||||
confirm as Lang.Boolean,
|
||||
pin as Lang.String or Null,
|
||||
data as Lang.Dictionary or Null,
|
||||
icon as Graphics.BitmapType or WatchUi.Drawable,
|
||||
options as {
|
||||
@ -56,7 +54,6 @@ class HomeAssistantTapMenuItem extends WatchUi.IconMenuItem {
|
||||
mService = service;
|
||||
mConfirm = confirm;
|
||||
mData = data;
|
||||
mPin = pin;
|
||||
}
|
||||
|
||||
function hasTemplate() as Lang.Boolean {
|
||||
@ -87,19 +84,23 @@ class HomeAssistantTapMenuItem extends WatchUi.IconMenuItem {
|
||||
}
|
||||
|
||||
function callService() as Void {
|
||||
var hasTouchScreen = System.getDeviceSettings().isTouchScreen;
|
||||
if (mPin != null && hasTouchScreen) {
|
||||
WatchUi.pushView(
|
||||
new HomeAssistantPinConfirmationView(),
|
||||
new HomeAssistantPinConfirmationDelegate(method(:onConfirm), false, mPin),
|
||||
WatchUi.SLIDE_IMMEDIATE
|
||||
);
|
||||
} else if (mConfirm || (mPin!=null && !hasTouchScreen)) {
|
||||
WatchUi.pushView(
|
||||
new HomeAssistantConfirmation(),
|
||||
new HomeAssistantConfirmationDelegate(method(:onConfirm), false),
|
||||
WatchUi.SLIDE_IMMEDIATE
|
||||
);
|
||||
if (mConfirm) {
|
||||
var hasTouchScreen = System.getDeviceSettings().isTouchScreen;
|
||||
var pin = Settings.getPin();
|
||||
System.println("HomeAsistantTemplateMenuItem callService() pin = '" + pin + "'");
|
||||
if (!hasTouchScreen || "".equals(pin)) {
|
||||
WatchUi.pushView(
|
||||
new HomeAssistantConfirmation(),
|
||||
new HomeAssistantConfirmationDelegate(method(:onConfirm), false),
|
||||
WatchUi.SLIDE_IMMEDIATE
|
||||
);
|
||||
} else {
|
||||
WatchUi.pushView(
|
||||
new HomeAssistantPinConfirmationView(),
|
||||
new HomeAssistantPinConfirmationDelegate(method(:onConfirm), false, pin),
|
||||
WatchUi.SLIDE_IMMEDIATE
|
||||
);
|
||||
}
|
||||
} else {
|
||||
onConfirm(false);
|
||||
}
|
||||
|
@ -52,12 +52,10 @@ class HomeAssistantView extends WatchUi.Menu2 {
|
||||
var service = items[i].get("service") as Lang.String or Null; // Deprecated schema
|
||||
var confirm = false as Lang.Boolean or Null;
|
||||
var data = null as Lang.Dictionary or Null;
|
||||
var pin = null as Lang.String or Null;
|
||||
if (tap_action != null) {
|
||||
service = tap_action.get("service");
|
||||
confirm = tap_action.get("confirm"); // Optional
|
||||
data = tap_action.get("data"); // Optional
|
||||
pin = tap_action.get("pin"); // Optional
|
||||
if (confirm == null) {
|
||||
confirm = false;
|
||||
}
|
||||
@ -66,7 +64,7 @@ class HomeAssistantView extends WatchUi.Menu2 {
|
||||
if (type.equals("toggle") && entity != null) {
|
||||
addItem(HomeAssistantMenuItemFactory.create().toggle(name, entity, content, confirm));
|
||||
} else if ((type.equals("tap") && service != null) || (type.equals("template") && content != null)) {
|
||||
addItem(HomeAssistantMenuItemFactory.create().tap(name, entity, content, service, confirm, data, pin));
|
||||
addItem(HomeAssistantMenuItemFactory.create().tap(name, entity, content, service, confirm, data));
|
||||
} else if (type.equals("group")) {
|
||||
addItem(HomeAssistantMenuItemFactory.create().group(items[i], content));
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ class Settings {
|
||||
private static var mAppTimeout as Lang.Number = 0; // seconds
|
||||
private static var mPollDelay as Lang.Number = 0; // seconds
|
||||
private static var mConfirmTimeout as Lang.Number = 3; // seconds
|
||||
private static var mPinMask as Lang.String = "";
|
||||
private static var mPin as Lang.String = "";
|
||||
private static var mMenuAlignment as Lang.Number = WatchUi.MenuItem.MENU_ITEM_LABEL_ALIGN_LEFT;
|
||||
private static var mIsSensorsLevelEnabled as Lang.Boolean = false;
|
||||
private static var mBatteryRefreshRate as Lang.Number = 15; // minutes
|
||||
@ -60,7 +60,7 @@ class Settings {
|
||||
mAppTimeout = Properties.getValue("app_timeout");
|
||||
mPollDelay = Properties.getValue("poll_delay_combined");
|
||||
mConfirmTimeout = Properties.getValue("confirm_timeout");
|
||||
mPinMask = Properties.getValue("pin_mask");
|
||||
mPin = Properties.getValue("pin");
|
||||
mMenuAlignment = Properties.getValue("menu_alignment");
|
||||
mIsSensorsLevelEnabled = Properties.getValue("enable_battery_level");
|
||||
mBatteryRefreshRate = Properties.getValue("battery_level_refresh_rate");
|
||||
@ -166,8 +166,8 @@ class Settings {
|
||||
return mConfirmTimeout * 1000; // Convert to milliseconds
|
||||
}
|
||||
|
||||
static function getPinMask() as Lang.String {
|
||||
return mPinMask;
|
||||
static function getPin() as Lang.String {
|
||||
return mPin;
|
||||
}
|
||||
|
||||
static function getMenuAlignment() as Lang.Number {
|
||||
|
Reference in New Issue
Block a user