remove transcoding, move pin to settings, remove pin from schema

This commit is contained in:
Matthias Oesterheld
2024-11-11 20:06:35 +01:00
parent cd5ed317c5
commit fb2bb7f566
11 changed files with 32 additions and 61 deletions

View File

@ -217,9 +217,6 @@
"type": "object",
"title": "Your services's parameters",
"description": "The object containing the parameters and their values to be passed to the entity. No schema checking can be done here, you are on your own! On application crash, remove the parameters."
},
"pin": {
"$ref": "#/$defs/pin"
}
},
"required": ["service"]
@ -233,12 +230,6 @@
"default": false,
"title": "Confirmation",
"description": "Optional confirmation of the action before execution as a precaution."
},
"pin": {
"title": "Confirmation PIN",
"type": "string",
"pattern": "^[1-4]+$",
"description": "Optional confirmation PIN to be entered before execution as a simple security measure."
}
}
}

View File

@ -39,7 +39,7 @@
des Geräts zu schonen.</string>
<string id="SettingsConfirmTimeout">Nach dieser Zeit (in Sekunden) wird der Bestätigungsdialog einer Aktion geschlossen und die
Aktion abgebrochen. Auf 0 setzen, um den Timeout zu deaktivieren.</string>
<string id="SettingsPinMask">Schablone um die PIN aus der Dashboard Config zu transkodieren.</string>
<string id="SettingsPin">PIN für alle Actions mit 'confirm': true.</string>
<string id="SettingsWidgetStart">(Nur Widget) Anwendung automatisch über das Widget starten ohne drauftippen zu müssen.</string>
<string id="SettingsEnableBatteryLevel">Hintergrunddienst aktivieren, um den Ladezustand der Batterie an HomeAssistant zu senden.</string>
<string id="SettingsBatteryLevelRefreshRate">Die Aktualisierungsrate (in Minuten) mit der der Ladezustand der Batterie

View File

@ -60,7 +60,6 @@
<string id="SettingsPollDelay">Zusätzliche Abfrageverzögerung (in Sekunden). Fügt eine Verzögerung zwischen der Statusaktualisierung aller Menüelemente hinzu.</string>
<string id="SettingsConfirmTimeout">Nach dieser Zeit (in Sekunden) wird der Bestätigungsdialog einer Aktion geschlossen und die
Aktion abgebrochen. Auf 0 setzen, um den Timeout zu deaktivieren.</string>
<string id="SettingsPinMask">Schablone um die PIN aus der Dashboard Config zu transkodieren.</string>
<string id="SettingsTextAlign">Menüausrichtung links (aus) oder rechts (ein).</string>
<string id="LeftToRight">Links nach rechts</string>
<string id="RightToLeft">Rechts nach links</string>

View File

@ -66,12 +66,10 @@
<property id="confirm_timeout" type="number">3</property>
<!--
This mask transcodes the plain text PIN from the public dashboard config.
Every digit is used to increase the corresponding digit at this position
in the PIN by the value given, starting at 1 if a value bigger than 4 has
been reached.
PIN to be used for confirmation. If a PIN is set, every action with 'confirm': true
will show the PIN confirmation dialog.
-->
<property id="pin_mask" type="string"></property>
<property id="pin" type="string"></property>
<!--
Left to right or right to left text. Language dependent.

View File

@ -80,8 +80,8 @@
</setting>
<setting
propertyKey="@Properties.pin_mask"
title="@Strings.SettingsPinMask"
propertyKey="@Properties.pin"
title="@Strings.SettingsPin"
>
<settingConfig type="alphaNumeric" />
</setting>

View File

@ -53,7 +53,7 @@
<string id="SettingsAppTimeout">Timeout in seconds. Exit the application after this period of inactivity to save the device battery.</string>
<string id="SettingsPollDelay">Additional poll delay (in seconds). Adds a delay between the status update of all menu items.</string>
<string id="SettingsConfirmTimeout">After this time (in seconds), a confirmation dialog for an action is automatically closed and the action is cancelled. Set to 0 to disable the timeout.</string>
<string id="SettingsPinMask">Integer Mask to transcode the plain text PIN from the public dashboard config.</string>
<string id="SettingsPin">PIN to be used for all actions that require confirmation.</string>
<string id="SettingsTextAlign">Left (off) or Right (on) Menu Alignment.</string>
<string id="LeftToRight">Left to right</string>
<string id="RightToLeft">Right to Left</string>

View File

@ -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,

View File

@ -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) {

View File

@ -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);
}

View File

@ -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));
}

View File

@ -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 {