mirror of
https://github.com/house-of-abbey/GarminHomeAssistant.git
synced 2025-06-15 10:58:40 +00:00
add "pin": true
JSON config property, add default pin, add pin confirmation to toggle, adjust JSON schema
This commit is contained in:
@ -37,6 +37,9 @@
|
|||||||
"properties": {
|
"properties": {
|
||||||
"confirm": {
|
"confirm": {
|
||||||
"$ref": "#/$defs/confirm"
|
"$ref": "#/$defs/confirm"
|
||||||
|
},
|
||||||
|
"pin": {
|
||||||
|
"$ref": "#/$defs/pin"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"additionalProperties": false
|
"additionalProperties": false
|
||||||
@ -213,6 +216,9 @@
|
|||||||
"confirm": {
|
"confirm": {
|
||||||
"$ref": "#/$defs/confirm"
|
"$ref": "#/$defs/confirm"
|
||||||
},
|
},
|
||||||
|
"pin": {
|
||||||
|
"$ref": "#/$defs/pin"
|
||||||
|
},
|
||||||
"data": {
|
"data": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"title": "Your services's parameters",
|
"title": "Your services's parameters",
|
||||||
@ -230,6 +236,12 @@
|
|||||||
"default": false,
|
"default": false,
|
||||||
"title": "Confirmation",
|
"title": "Confirmation",
|
||||||
"description": "Optional confirmation of the action before execution as a precaution."
|
"description": "Optional confirmation of the action before execution as a precaution."
|
||||||
|
},
|
||||||
|
"pin": {
|
||||||
|
"type": "boolean",
|
||||||
|
"default": false,
|
||||||
|
"title": "PIN Confirmation",
|
||||||
|
"description": "Optional PIN confirmation of the action before execution as a precaution. Has precedence over 'confirm': true if both are set."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -66,10 +66,10 @@
|
|||||||
<property id="confirm_timeout" type="number">3</property>
|
<property id="confirm_timeout" type="number">3</property>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
PIN to be used for confirmation. If a PIN is set, every action with 'confirm': true
|
PIN to be used for confirmation. Used for actions with 'pin': true
|
||||||
will show the PIN confirmation dialog.
|
which will show the PIN confirmation dialog.
|
||||||
-->
|
-->
|
||||||
<property id="pin" type="string"></property>
|
<property id="pin" type="string">0000</property>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
Left to right or right to left text. Language dependent.
|
Left to right or right to left text. Language dependent.
|
||||||
|
@ -68,12 +68,14 @@ class HomeAssistantMenuItemFactory {
|
|||||||
label as Lang.String or Lang.Symbol,
|
label as Lang.String or Lang.Symbol,
|
||||||
entity_id as Lang.String or Null,
|
entity_id as Lang.String or Null,
|
||||||
template as Lang.String or Null,
|
template as Lang.String or Null,
|
||||||
confirm as Lang.Boolean
|
confirm as Lang.Boolean,
|
||||||
|
pin as Lang.Boolean
|
||||||
) as WatchUi.MenuItem {
|
) as WatchUi.MenuItem {
|
||||||
return new HomeAssistantToggleMenuItem(
|
return new HomeAssistantToggleMenuItem(
|
||||||
label,
|
label,
|
||||||
template,
|
template,
|
||||||
confirm,
|
confirm,
|
||||||
|
pin,
|
||||||
{ "entity_id" => entity_id },
|
{ "entity_id" => entity_id },
|
||||||
mMenuItemOptions
|
mMenuItemOptions
|
||||||
);
|
);
|
||||||
@ -85,6 +87,7 @@ class HomeAssistantMenuItemFactory {
|
|||||||
template as Lang.String or Null,
|
template as Lang.String or Null,
|
||||||
service as Lang.String or Null,
|
service as Lang.String or Null,
|
||||||
confirm as Lang.Boolean,
|
confirm as Lang.Boolean,
|
||||||
|
pin as Lang.Boolean,
|
||||||
data as Lang.Dictionary or Null
|
data as Lang.Dictionary or Null
|
||||||
) as WatchUi.MenuItem {
|
) as WatchUi.MenuItem {
|
||||||
if (entity != null) {
|
if (entity != null) {
|
||||||
@ -100,6 +103,7 @@ class HomeAssistantMenuItemFactory {
|
|||||||
template,
|
template,
|
||||||
service,
|
service,
|
||||||
confirm,
|
confirm,
|
||||||
|
pin,
|
||||||
data,
|
data,
|
||||||
mTapTypeIcon,
|
mTapTypeIcon,
|
||||||
mMenuItemOptions,
|
mMenuItemOptions,
|
||||||
@ -111,6 +115,7 @@ class HomeAssistantMenuItemFactory {
|
|||||||
template,
|
template,
|
||||||
service,
|
service,
|
||||||
confirm,
|
confirm,
|
||||||
|
pin,
|
||||||
data,
|
data,
|
||||||
mInfoTypeIcon,
|
mInfoTypeIcon,
|
||||||
mMenuItemOptions,
|
mMenuItemOptions,
|
||||||
|
@ -27,6 +27,7 @@ class HomeAssistantTapMenuItem extends WatchUi.IconMenuItem {
|
|||||||
private var mTemplate as Lang.String;
|
private var mTemplate as Lang.String;
|
||||||
private var mService as Lang.String or Null;
|
private var mService as Lang.String or Null;
|
||||||
private var mConfirm as Lang.Boolean;
|
private var mConfirm as Lang.Boolean;
|
||||||
|
private var mPin as Lang.Boolean;
|
||||||
private var mData as Lang.Dictionary or Null;
|
private var mData as Lang.Dictionary or Null;
|
||||||
|
|
||||||
function initialize(
|
function initialize(
|
||||||
@ -34,6 +35,7 @@ class HomeAssistantTapMenuItem extends WatchUi.IconMenuItem {
|
|||||||
template as Lang.String,
|
template as Lang.String,
|
||||||
service as Lang.String or Null,
|
service as Lang.String or Null,
|
||||||
confirm as Lang.Boolean,
|
confirm as Lang.Boolean,
|
||||||
|
pin as Lang.Boolean,
|
||||||
data as Lang.Dictionary or Null,
|
data as Lang.Dictionary or Null,
|
||||||
icon as Graphics.BitmapType or WatchUi.Drawable,
|
icon as Graphics.BitmapType or WatchUi.Drawable,
|
||||||
options as {
|
options as {
|
||||||
@ -53,6 +55,7 @@ class HomeAssistantTapMenuItem extends WatchUi.IconMenuItem {
|
|||||||
mTemplate = template;
|
mTemplate = template;
|
||||||
mService = service;
|
mService = service;
|
||||||
mConfirm = confirm;
|
mConfirm = confirm;
|
||||||
|
mPin = pin;
|
||||||
mData = data;
|
mData = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,27 +87,25 @@ class HomeAssistantTapMenuItem extends WatchUi.IconMenuItem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function callService() as Void {
|
function callService() as Void {
|
||||||
if (mConfirm) {
|
var hasTouchScreen = System.getDeviceSettings().isTouchScreen;
|
||||||
var hasTouchScreen = System.getDeviceSettings().isTouchScreen;
|
if (mPin && hasTouchScreen) {
|
||||||
var pin = Settings.getPin();
|
var pin = Settings.getPin();
|
||||||
if (!hasTouchScreen || "".equals(pin)) {
|
if (pin.toNumber() == null || pin.length() != 4) {
|
||||||
WatchUi.pushView(
|
ErrorView.show(WatchUi.loadResource($.Rez.Strings.SettingsPinError) as Lang.String);
|
||||||
new HomeAssistantConfirmation(),
|
return;
|
||||||
new HomeAssistantConfirmationDelegate(method(:onConfirm), false),
|
|
||||||
WatchUi.SLIDE_IMMEDIATE
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
if (pin.toNumber() == null || pin.length() != 4) {
|
|
||||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.SettingsPinError) as Lang.String);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
var pinConfirmationView = new HomeAssistantPinConfirmationView();
|
|
||||||
WatchUi.pushView(
|
|
||||||
pinConfirmationView,
|
|
||||||
new HomeAssistantPinConfirmationDelegate(method(:onConfirm), false, pin, pinConfirmationView),
|
|
||||||
WatchUi.SLIDE_IMMEDIATE
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
var pinConfirmationView = new HomeAssistantPinConfirmationView();
|
||||||
|
WatchUi.pushView(
|
||||||
|
pinConfirmationView,
|
||||||
|
new HomeAssistantPinConfirmationDelegate(method(:onConfirm), false, pin, pinConfirmationView),
|
||||||
|
WatchUi.SLIDE_IMMEDIATE
|
||||||
|
);
|
||||||
|
} else if (mConfirm) {
|
||||||
|
WatchUi.pushView(
|
||||||
|
new HomeAssistantConfirmation(),
|
||||||
|
new HomeAssistantConfirmationDelegate(method(:onConfirm), false),
|
||||||
|
WatchUi.SLIDE_IMMEDIATE
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
onConfirm(false);
|
onConfirm(false);
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,7 @@ using Toybox.Timer;
|
|||||||
|
|
||||||
class HomeAssistantToggleMenuItem extends WatchUi.ToggleMenuItem {
|
class HomeAssistantToggleMenuItem extends WatchUi.ToggleMenuItem {
|
||||||
private var mConfirm as Lang.Boolean;
|
private var mConfirm as Lang.Boolean;
|
||||||
|
private var mPin as Lang.Boolean;
|
||||||
private var mData as Lang.Dictionary;
|
private var mData as Lang.Dictionary;
|
||||||
private var mTemplate as Lang.String;
|
private var mTemplate as Lang.String;
|
||||||
private var mHasVibrate as Lang.Boolean = false;
|
private var mHasVibrate as Lang.Boolean = false;
|
||||||
@ -34,6 +35,7 @@ class HomeAssistantToggleMenuItem extends WatchUi.ToggleMenuItem {
|
|||||||
label as Lang.String or Lang.Symbol,
|
label as Lang.String or Lang.Symbol,
|
||||||
template as Lang.String,
|
template as Lang.String,
|
||||||
confirm as Lang.Boolean,
|
confirm as Lang.Boolean,
|
||||||
|
pin as Lang.Boolean,
|
||||||
data as Lang.Dictionary or Null,
|
data as Lang.Dictionary or Null,
|
||||||
options as {
|
options as {
|
||||||
:alignment as WatchUi.MenuItem.Alignment,
|
:alignment as WatchUi.MenuItem.Alignment,
|
||||||
@ -45,6 +47,7 @@ class HomeAssistantToggleMenuItem extends WatchUi.ToggleMenuItem {
|
|||||||
mHasVibrate = true;
|
mHasVibrate = true;
|
||||||
}
|
}
|
||||||
mConfirm = confirm;
|
mConfirm = confirm;
|
||||||
|
mPin = pin;
|
||||||
mData = data;
|
mData = data;
|
||||||
mTemplate = template;
|
mTemplate = template;
|
||||||
}
|
}
|
||||||
@ -213,14 +216,27 @@ class HomeAssistantToggleMenuItem extends WatchUi.ToggleMenuItem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function callService(b as Lang.Boolean) as Void {
|
function callService(b as Lang.Boolean) as Void {
|
||||||
if (mConfirm) {
|
var hasTouchScreen = System.getDeviceSettings().isTouchScreen;
|
||||||
|
if (mPin && hasTouchScreen) {
|
||||||
|
var pin = Settings.getPin();
|
||||||
|
if (pin.toNumber() == null || pin.length() != 4) {
|
||||||
|
ErrorView.show(WatchUi.loadResource($.Rez.Strings.SettingsPinError) as Lang.String);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var pinConfirmationView = new HomeAssistantPinConfirmationView();
|
||||||
|
WatchUi.pushView(
|
||||||
|
pinConfirmationView,
|
||||||
|
new HomeAssistantPinConfirmationDelegate(method(:onConfirm), b, pin, pinConfirmationView),
|
||||||
|
WatchUi.SLIDE_IMMEDIATE
|
||||||
|
);
|
||||||
|
} else if (mConfirm) {
|
||||||
WatchUi.pushView(
|
WatchUi.pushView(
|
||||||
new HomeAssistantConfirmation(),
|
new HomeAssistantConfirmation(),
|
||||||
new HomeAssistantConfirmationDelegate(method(:onConfirm), b),
|
new HomeAssistantConfirmationDelegate(method(:onConfirm), b),
|
||||||
WatchUi.SLIDE_IMMEDIATE
|
WatchUi.SLIDE_IMMEDIATE
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
setState(b);
|
onConfirm(b);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -228,4 +244,5 @@ class HomeAssistantToggleMenuItem extends WatchUi.ToggleMenuItem {
|
|||||||
setState(b);
|
setState(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -51,10 +51,12 @@ class HomeAssistantView extends WatchUi.Menu2 {
|
|||||||
var tap_action = items[i].get("tap_action") as Lang.Dictionary or Null;
|
var tap_action = items[i].get("tap_action") as Lang.Dictionary or Null;
|
||||||
var service = items[i].get("service") as Lang.String or Null; // Deprecated schema
|
var service = items[i].get("service") as Lang.String or Null; // Deprecated schema
|
||||||
var confirm = false as Lang.Boolean or Null;
|
var confirm = false as Lang.Boolean or Null;
|
||||||
|
var pin = false as Lang.Boolean or Null;
|
||||||
var data = null as Lang.Dictionary or Null;
|
var data = null as Lang.Dictionary or Null;
|
||||||
if (tap_action != null) {
|
if (tap_action != null) {
|
||||||
service = tap_action.get("service");
|
service = tap_action.get("service");
|
||||||
confirm = tap_action.get("confirm"); // Optional
|
confirm = tap_action.get("confirm"); // Optional
|
||||||
|
pin = tap_action.get("pin"); // Optional
|
||||||
data = tap_action.get("data"); // Optional
|
data = tap_action.get("data"); // Optional
|
||||||
if (confirm == null) {
|
if (confirm == null) {
|
||||||
confirm = false;
|
confirm = false;
|
||||||
@ -62,9 +64,9 @@ class HomeAssistantView extends WatchUi.Menu2 {
|
|||||||
}
|
}
|
||||||
if (type != null && name != null) {
|
if (type != null && name != null) {
|
||||||
if (type.equals("toggle") && entity != null) {
|
if (type.equals("toggle") && entity != null) {
|
||||||
addItem(HomeAssistantMenuItemFactory.create().toggle(name, entity, content, confirm));
|
addItem(HomeAssistantMenuItemFactory.create().toggle(name, entity, content, confirm, pin));
|
||||||
} else if ((type.equals("tap") && service != null) || (type.equals("template") && content != null)) {
|
} else if ((type.equals("tap") && service != null) || (type.equals("template") && content != null)) {
|
||||||
addItem(HomeAssistantMenuItemFactory.create().tap(name, entity, content, service, confirm, data));
|
addItem(HomeAssistantMenuItemFactory.create().tap(name, entity, content, service, confirm, pin, data));
|
||||||
} else if (type.equals("group")) {
|
} else if (type.equals("group")) {
|
||||||
addItem(HomeAssistantMenuItemFactory.create().group(items[i], content));
|
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 mAppTimeout as Lang.Number = 0; // seconds
|
||||||
private static var mPollDelay 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 mConfirmTimeout as Lang.Number = 3; // seconds
|
||||||
private static var mPin as Lang.String = "";
|
private static var mPin as Lang.String = "0000";
|
||||||
private static var mMenuAlignment as Lang.Number = WatchUi.MenuItem.MENU_ITEM_LABEL_ALIGN_LEFT;
|
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 mIsSensorsLevelEnabled as Lang.Boolean = false;
|
||||||
private static var mBatteryRefreshRate as Lang.Number = 15; // minutes
|
private static var mBatteryRefreshRate as Lang.Number = 15; // minutes
|
||||||
|
Reference in New Issue
Block a user