mirror of
				https://github.com/house-of-abbey/GarminHomeAssistant.git
				synced 2025-11-04 08:58:13 +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": {
 | 
			
		||||
            "confirm": {
 | 
			
		||||
              "$ref": "#/$defs/confirm"
 | 
			
		||||
            },
 | 
			
		||||
            "pin": {
 | 
			
		||||
              "$ref": "#/$defs/pin"
 | 
			
		||||
            }
 | 
			
		||||
          },
 | 
			
		||||
          "additionalProperties": false
 | 
			
		||||
@@ -213,6 +216,9 @@
 | 
			
		||||
        "confirm": {
 | 
			
		||||
          "$ref": "#/$defs/confirm"
 | 
			
		||||
        },
 | 
			
		||||
        "pin": {
 | 
			
		||||
          "$ref": "#/$defs/pin"
 | 
			
		||||
        },
 | 
			
		||||
        "data": {
 | 
			
		||||
          "type": "object",
 | 
			
		||||
          "title": "Your services's parameters",
 | 
			
		||||
@@ -230,6 +236,12 @@
 | 
			
		||||
      "default": false,
 | 
			
		||||
      "title": "Confirmation",
 | 
			
		||||
      "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>
 | 
			
		||||
 | 
			
		||||
  <!--
 | 
			
		||||
    PIN to be used for confirmation. If a PIN is set, every action with 'confirm': true
 | 
			
		||||
    will show the PIN confirmation dialog.
 | 
			
		||||
    PIN to be used for confirmation. Used for actions with 'pin': true
 | 
			
		||||
    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.
 | 
			
		||||
 
 | 
			
		||||
@@ -68,12 +68,14 @@ class HomeAssistantMenuItemFactory {
 | 
			
		||||
        label     as Lang.String or Lang.Symbol,
 | 
			
		||||
        entity_id 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 {
 | 
			
		||||
        return new HomeAssistantToggleMenuItem(
 | 
			
		||||
            label,
 | 
			
		||||
            template,
 | 
			
		||||
            confirm,
 | 
			
		||||
            pin,
 | 
			
		||||
            { "entity_id" => entity_id },
 | 
			
		||||
            mMenuItemOptions
 | 
			
		||||
        );
 | 
			
		||||
@@ -85,6 +87,7 @@ class HomeAssistantMenuItemFactory {
 | 
			
		||||
        template as Lang.String or Null,
 | 
			
		||||
        service  as Lang.String or Null,
 | 
			
		||||
        confirm  as Lang.Boolean,
 | 
			
		||||
        pin      as Lang.Boolean,
 | 
			
		||||
        data     as Lang.Dictionary or Null
 | 
			
		||||
    ) as WatchUi.MenuItem {
 | 
			
		||||
        if (entity != null) {
 | 
			
		||||
@@ -100,6 +103,7 @@ class HomeAssistantMenuItemFactory {
 | 
			
		||||
                template,
 | 
			
		||||
                service,
 | 
			
		||||
                confirm,
 | 
			
		||||
                pin,
 | 
			
		||||
                data,
 | 
			
		||||
                mTapTypeIcon,
 | 
			
		||||
                mMenuItemOptions,
 | 
			
		||||
@@ -111,6 +115,7 @@ class HomeAssistantMenuItemFactory {
 | 
			
		||||
                template,
 | 
			
		||||
                service,
 | 
			
		||||
                confirm,
 | 
			
		||||
                pin,
 | 
			
		||||
                data,
 | 
			
		||||
                mInfoTypeIcon,
 | 
			
		||||
                mMenuItemOptions,
 | 
			
		||||
 
 | 
			
		||||
@@ -27,6 +27,7 @@ class HomeAssistantTapMenuItem extends WatchUi.IconMenuItem {
 | 
			
		||||
    private var mTemplate             as Lang.String;
 | 
			
		||||
    private var mService              as Lang.String or Null;
 | 
			
		||||
    private var mConfirm              as Lang.Boolean;
 | 
			
		||||
    private var mPin                  as Lang.Boolean;
 | 
			
		||||
    private var mData                 as Lang.Dictionary or Null;
 | 
			
		||||
 | 
			
		||||
    function initialize(
 | 
			
		||||
@@ -34,6 +35,7 @@ class HomeAssistantTapMenuItem extends WatchUi.IconMenuItem {
 | 
			
		||||
        template  as Lang.String,
 | 
			
		||||
        service   as Lang.String or Null,
 | 
			
		||||
        confirm   as Lang.Boolean,
 | 
			
		||||
        pin       as Lang.Boolean,
 | 
			
		||||
        data      as Lang.Dictionary or Null,
 | 
			
		||||
        icon      as Graphics.BitmapType or WatchUi.Drawable,
 | 
			
		||||
        options   as {
 | 
			
		||||
@@ -53,6 +55,7 @@ class HomeAssistantTapMenuItem extends WatchUi.IconMenuItem {
 | 
			
		||||
        mTemplate             = template;
 | 
			
		||||
        mService              = service;
 | 
			
		||||
        mConfirm              = confirm;
 | 
			
		||||
        mPin                  = pin;
 | 
			
		||||
        mData                 = data;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -84,16 +87,9 @@ class HomeAssistantTapMenuItem extends WatchUi.IconMenuItem {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    function callService() as Void {
 | 
			
		||||
        if (mConfirm) {
 | 
			
		||||
        var hasTouchScreen = System.getDeviceSettings().isTouchScreen;
 | 
			
		||||
        if (mPin && hasTouchScreen) {
 | 
			
		||||
            var pin = Settings.getPin();
 | 
			
		||||
            if (!hasTouchScreen || "".equals(pin)) {
 | 
			
		||||
                WatchUi.pushView(
 | 
			
		||||
                    new HomeAssistantConfirmation(),
 | 
			
		||||
                    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;
 | 
			
		||||
@@ -104,7 +100,12 @@ class HomeAssistantTapMenuItem extends WatchUi.IconMenuItem {
 | 
			
		||||
                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 {
 | 
			
		||||
            onConfirm(false);
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
@@ -26,6 +26,7 @@ using Toybox.Timer;
 | 
			
		||||
 | 
			
		||||
class HomeAssistantToggleMenuItem extends WatchUi.ToggleMenuItem {
 | 
			
		||||
    private var mConfirm    as Lang.Boolean;
 | 
			
		||||
    private var mPin        as Lang.Boolean;
 | 
			
		||||
    private var mData       as Lang.Dictionary;
 | 
			
		||||
    private var mTemplate   as Lang.String;
 | 
			
		||||
    private var mHasVibrate as Lang.Boolean = false;
 | 
			
		||||
@@ -34,6 +35,7 @@ class HomeAssistantToggleMenuItem extends WatchUi.ToggleMenuItem {
 | 
			
		||||
        label    as Lang.String or Lang.Symbol,
 | 
			
		||||
        template as Lang.String,
 | 
			
		||||
        confirm  as Lang.Boolean,
 | 
			
		||||
        pin      as Lang.Boolean,
 | 
			
		||||
        data     as Lang.Dictionary or Null,
 | 
			
		||||
        options  as {
 | 
			
		||||
            :alignment as WatchUi.MenuItem.Alignment,
 | 
			
		||||
@@ -45,6 +47,7 @@ class HomeAssistantToggleMenuItem extends WatchUi.ToggleMenuItem {
 | 
			
		||||
            mHasVibrate = true;
 | 
			
		||||
        }
 | 
			
		||||
        mConfirm  = confirm;
 | 
			
		||||
        mPin      = pin;
 | 
			
		||||
        mData     = data;
 | 
			
		||||
        mTemplate = template;
 | 
			
		||||
    }
 | 
			
		||||
@@ -213,14 +216,27 @@ class HomeAssistantToggleMenuItem extends WatchUi.ToggleMenuItem {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    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(
 | 
			
		||||
                new HomeAssistantConfirmation(),
 | 
			
		||||
                new HomeAssistantConfirmationDelegate(method(:onConfirm), b),
 | 
			
		||||
                WatchUi.SLIDE_IMMEDIATE
 | 
			
		||||
            );
 | 
			
		||||
        } else {
 | 
			
		||||
            setState(b);
 | 
			
		||||
            onConfirm(b);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -228,4 +244,5 @@ class HomeAssistantToggleMenuItem extends WatchUi.ToggleMenuItem {
 | 
			
		||||
        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 service    = items[i].get("service")    as Lang.String     or Null; // Deprecated schema
 | 
			
		||||
                var confirm    = false                      as Lang.Boolean    or Null;
 | 
			
		||||
                var pin        = false                      as Lang.Boolean    or Null;
 | 
			
		||||
                var data       = null                       as Lang.Dictionary or Null;
 | 
			
		||||
                if (tap_action != null) {
 | 
			
		||||
                    service = tap_action.get("service");
 | 
			
		||||
                    confirm = tap_action.get("confirm"); // Optional
 | 
			
		||||
                    pin     = tap_action.get("pin");    // Optional
 | 
			
		||||
                    data    = tap_action.get("data");    // Optional
 | 
			
		||||
                    if (confirm == null) {
 | 
			
		||||
                        confirm = false;
 | 
			
		||||
@@ -62,9 +64,9 @@ class HomeAssistantView extends WatchUi.Menu2 {
 | 
			
		||||
                }
 | 
			
		||||
                if (type != null && name != 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)) {
 | 
			
		||||
                        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")) {
 | 
			
		||||
                        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 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 mIsSensorsLevelEnabled as Lang.Boolean = false;
 | 
			
		||||
    private static var mBatteryRefreshRate    as Lang.Number  = 15; // minutes
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user