mirror of
				https://github.com/house-of-abbey/GarminHomeAssistant.git
				synced 2025-11-04 08:58:13 +00:00 
			
		
		
		
	Initial Solution
This commit is contained in:
		@@ -2,12 +2,8 @@
 | 
				
			|||||||
  "$schema": "https://json-schema.org/draft/2020-12/schema",
 | 
					  "$schema": "https://json-schema.org/draft/2020-12/schema",
 | 
				
			||||||
  "type": "object",
 | 
					  "type": "object",
 | 
				
			||||||
  "properties": {
 | 
					  "properties": {
 | 
				
			||||||
    "title": {
 | 
					    "title": { "type": "string" },
 | 
				
			||||||
      "type": "string"
 | 
					    "items": { "$ref": "#/$defs/items" },
 | 
				
			||||||
    },
 | 
					 | 
				
			||||||
    "items": {
 | 
					 | 
				
			||||||
      "$ref": "#/$defs/items"
 | 
					 | 
				
			||||||
    },
 | 
					 | 
				
			||||||
    "required": ["title", "items"],
 | 
					    "required": ["title", "items"],
 | 
				
			||||||
    "additionalProperties": false
 | 
					    "additionalProperties": false
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
@@ -15,17 +11,19 @@
 | 
				
			|||||||
    "toggle": {
 | 
					    "toggle": {
 | 
				
			||||||
      "type": "object",
 | 
					      "type": "object",
 | 
				
			||||||
      "properties": {
 | 
					      "properties": {
 | 
				
			||||||
        "entity": {
 | 
					        "entity": { "$ref": "#/$defs/entity" },
 | 
				
			||||||
          "$ref": "#/$defs/entity"
 | 
					        "name": { "title": "Your familiar name", "type": "string" },
 | 
				
			||||||
        },
 | 
					 | 
				
			||||||
        "name": {
 | 
					 | 
				
			||||||
          "title": "Your familiar name",
 | 
					 | 
				
			||||||
          "type": "string"
 | 
					 | 
				
			||||||
        },
 | 
					 | 
				
			||||||
        "type": {
 | 
					        "type": {
 | 
				
			||||||
          "title": "Menu item type",
 | 
					          "title": "Menu item type",
 | 
				
			||||||
          "description": "One of 'tap', 'template', 'toggle' or 'group'.",
 | 
					          "description": "One of 'tap', 'template', 'toggle' or 'group'.",
 | 
				
			||||||
          "const": "toggle"
 | 
					          "const": "toggle"
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        "tap_action": {
 | 
				
			||||||
 | 
					          "type": "object",
 | 
				
			||||||
 | 
					          "properties": {
 | 
				
			||||||
 | 
					            "confirm": { "$ref": "#/$defs/confirm" }
 | 
				
			||||||
 | 
					          },
 | 
				
			||||||
 | 
					          "additionalProperties": false
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
      },
 | 
					      },
 | 
				
			||||||
      "required": ["entity", "name", "type"],
 | 
					      "required": ["entity", "name", "type"],
 | 
				
			||||||
@@ -34,39 +32,24 @@
 | 
				
			|||||||
    "template": {
 | 
					    "template": {
 | 
				
			||||||
      "type": "object",
 | 
					      "type": "object",
 | 
				
			||||||
      "properties": {
 | 
					      "properties": {
 | 
				
			||||||
        "entity": {
 | 
					        "entity": { "$ref": "#/$defs/entity" },
 | 
				
			||||||
          "$ref": "#/$defs/entity"
 | 
					        "name": { "title": "Your familiar name", "type": "string" },
 | 
				
			||||||
        },
 | 
					        "content": { "title": "What to display (template)", "type": "string" },
 | 
				
			||||||
        "name": {
 | 
					 | 
				
			||||||
          "title": "Your familiar name",
 | 
					 | 
				
			||||||
          "type": "string"
 | 
					 | 
				
			||||||
        },
 | 
					 | 
				
			||||||
        "content": {
 | 
					 | 
				
			||||||
          "title": "What to display (template)",
 | 
					 | 
				
			||||||
          "type": "string"
 | 
					 | 
				
			||||||
        },
 | 
					 | 
				
			||||||
        "type": {
 | 
					        "type": {
 | 
				
			||||||
          "title": "Menu item type",
 | 
					          "title": "Menu item type",
 | 
				
			||||||
          "description": "One of 'tap', 'template', 'toggle' or 'group'.",
 | 
					          "description": "One of 'tap', 'template', 'toggle' or 'group'.",
 | 
				
			||||||
          "const": "template"
 | 
					          "const": "template"
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        "tap_action": {
 | 
					        "tap_action": { "$ref": "#/$defs/tap_action" }
 | 
				
			||||||
          "$ref": "#/$defs/action"
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
      },
 | 
					      },
 | 
				
			||||||
      "required": ["name", "entity", "content", "type"],
 | 
					      "required": ["name", "content", "type"],
 | 
				
			||||||
      "additionalProperties": false
 | 
					      "additionalProperties": false
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    "tap": {
 | 
					    "tap": {
 | 
				
			||||||
      "type": "object",
 | 
					      "type": "object",
 | 
				
			||||||
      "properties": {
 | 
					      "properties": {
 | 
				
			||||||
        "entity": {
 | 
					        "entity": { "$ref": "#/$defs/entity" },
 | 
				
			||||||
          "$ref": "#/$defs/entity"
 | 
					        "name": { "title": "Your familiar name", "type": "string" },
 | 
				
			||||||
        },
 | 
					 | 
				
			||||||
        "name": {
 | 
					 | 
				
			||||||
          "title": "Your familiar name",
 | 
					 | 
				
			||||||
          "type": "string"
 | 
					 | 
				
			||||||
        },
 | 
					 | 
				
			||||||
        "type": {
 | 
					        "type": {
 | 
				
			||||||
          "title": "Menu item type",
 | 
					          "title": "Menu item type",
 | 
				
			||||||
          "description": "One of 'tap', 'template', 'toggle' or 'group'.",
 | 
					          "description": "One of 'tap', 'template', 'toggle' or 'group'.",
 | 
				
			||||||
@@ -78,61 +61,43 @@
 | 
				
			|||||||
          "title": "Schema change:",
 | 
					          "title": "Schema change:",
 | 
				
			||||||
          "description": "Use 'tap_action' instead to mirror Home Assistant."
 | 
					          "description": "Use 'tap_action' instead to mirror Home Assistant."
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        "tap_action": {
 | 
					        "tap_action": { "$ref": "#/$defs/tap_action" }
 | 
				
			||||||
          "$ref": "#/$defs/action"
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
      },
 | 
					      },
 | 
				
			||||||
      "oneOf": [
 | 
					      "oneOf": [
 | 
				
			||||||
        {
 | 
					        { "required": ["name", "type", "service"] },
 | 
				
			||||||
          "required": ["entity", "name", "type", "service"]
 | 
					        { "required": ["name", "type", "tap_action"] }
 | 
				
			||||||
        },
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
          "required": ["entity", "name", "type", "tap_action"]
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
      ],
 | 
					      ],
 | 
				
			||||||
      "additionalProperties": false
 | 
					      "additionalProperties": false
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    "menu": {
 | 
					    "group": {
 | 
				
			||||||
      "type": "object",
 | 
					      "type": "object",
 | 
				
			||||||
      "properties": {
 | 
					      "properties": {
 | 
				
			||||||
        "entity": {
 | 
					        "entity": {
 | 
				
			||||||
          "$ref": "#/$defs/entity"
 | 
					          "$ref": "#/$defs/entity",
 | 
				
			||||||
        },
 | 
					          "deprecated": true,
 | 
				
			||||||
        "name": {
 | 
					          "title": "Schema change:",
 | 
				
			||||||
          "title": "Your familiar name",
 | 
					          "description": "'entity' is no longer necessary and should be removed."
 | 
				
			||||||
          "type": "string"
 | 
					 | 
				
			||||||
        },
 | 
					 | 
				
			||||||
        "title": {
 | 
					 | 
				
			||||||
          "type": "string"
 | 
					 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
 | 
					        "name": { "title": "Your familiar name", "type": "string" },
 | 
				
			||||||
 | 
					        "title": { "type": "string" },
 | 
				
			||||||
        "type": {
 | 
					        "type": {
 | 
				
			||||||
          "title": "Menu item type",
 | 
					          "title": "Menu item type",
 | 
				
			||||||
          "description": "One of 'tap', 'template', 'toggle' or 'group'.",
 | 
					          "description": "One of 'tap', 'template', 'toggle' or 'group'.",
 | 
				
			||||||
          "const": "group"
 | 
					          "const": "group"
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        "items": {
 | 
					        "items": { "$ref": "#/$defs/items" }
 | 
				
			||||||
          "$ref": "#/$defs/items"
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
      },
 | 
					      },
 | 
				
			||||||
      "required": ["entity", "name", "title", "type", "items"],
 | 
					      "required": ["name", "title", "type", "items"],
 | 
				
			||||||
      "additionalProperties": false
 | 
					      "additionalProperties": false
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    "items": {
 | 
					    "items": {
 | 
				
			||||||
      "type": "array",
 | 
					      "type": "array",
 | 
				
			||||||
      "items": {
 | 
					      "items": {
 | 
				
			||||||
        "oneOf": [
 | 
					        "oneOf": [
 | 
				
			||||||
          {
 | 
					          { "$ref": "#/$defs/toggle" },
 | 
				
			||||||
            "$ref": "#/$defs/toggle"
 | 
					          { "$ref": "#/$defs/template" },
 | 
				
			||||||
          },
 | 
					          { "$ref": "#/$defs/tap" },
 | 
				
			||||||
          {
 | 
					          { "$ref": "#/$defs/group" }
 | 
				
			||||||
            "$ref": "#/$defs/template"
 | 
					 | 
				
			||||||
          },
 | 
					 | 
				
			||||||
          {
 | 
					 | 
				
			||||||
            "$ref": "#/$defs/tap"
 | 
					 | 
				
			||||||
          },
 | 
					 | 
				
			||||||
          {
 | 
					 | 
				
			||||||
            "$ref": "#/$defs/menu"
 | 
					 | 
				
			||||||
          }
 | 
					 | 
				
			||||||
        ]
 | 
					        ]
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
@@ -141,21 +106,24 @@
 | 
				
			|||||||
      "type": "string",
 | 
					      "type": "string",
 | 
				
			||||||
      "pattern": "^[^.]+\\.[^.]+$"
 | 
					      "pattern": "^[^.]+\\.[^.]+$"
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    "action": {
 | 
					    "tap_action": {
 | 
				
			||||||
      "title": "Action",
 | 
					      "title": "Action",
 | 
				
			||||||
      "description": "'confirm' field is optional.",
 | 
					      "description": "'confirm' field is optional.",
 | 
				
			||||||
      "type": "object",
 | 
					      "type": "object",
 | 
				
			||||||
      "properties": {
 | 
					      "properties": {
 | 
				
			||||||
        "service": {
 | 
					        "service": { "$ref": "#/$defs/entity" },
 | 
				
			||||||
          "$ref": "#/$defs/entity"
 | 
					        "confirm": { "$ref": "#/$defs/confirm" },
 | 
				
			||||||
        },
 | 
					        "data": {
 | 
				
			||||||
        "confirm": {
 | 
					          "type": "object",
 | 
				
			||||||
          "type": "boolean",
 | 
					          "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."
 | 
				
			||||||
          "default": false,
 | 
					 | 
				
			||||||
          "description": "Confirm the action before execution as a precaution."
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
      },
 | 
					      },
 | 
				
			||||||
      "required": ["service"]
 | 
					      "required": ["service"]
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    "confirm": {
 | 
				
			||||||
 | 
					      "type": "boolean",
 | 
				
			||||||
 | 
					      "default": false,
 | 
				
			||||||
 | 
					      "description": "Confirm the action before execution as a precaution."
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -28,14 +28,13 @@ using Toybox.WatchUi;
 | 
				
			|||||||
using Toybox.Timer;
 | 
					using Toybox.Timer;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class Alert extends WatchUi.View {
 | 
					class Alert extends WatchUi.View {
 | 
				
			||||||
    private static const bRadius = 10;
 | 
					    private static const scRadius = 10;
 | 
				
			||||||
    private var mTimer     as Timer.Timer;
 | 
					    private var mTimer   as Timer.Timer;
 | 
				
			||||||
    private var mTimeout   as Lang.Number;
 | 
					    private var mTimeout as Lang.Number;
 | 
				
			||||||
    private var mText      as Lang.String;
 | 
					    private var mText    as Lang.String;
 | 
				
			||||||
    private var mFont      as Graphics.FontType;
 | 
					    private var mFont    as Graphics.FontType;
 | 
				
			||||||
    private var mFgcolor   as Graphics.ColorType;
 | 
					    private var mFgcolor as Graphics.ColorType;
 | 
				
			||||||
    private var mBgcolor   as Graphics.ColorType;
 | 
					    private var mBgcolor as Graphics.ColorType;
 | 
				
			||||||
    private var mAntiAlias as Lang.Boolean = false;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    function initialize(params as Lang.Dictionary) {
 | 
					    function initialize(params as Lang.Dictionary) {
 | 
				
			||||||
        View.initialize();
 | 
					        View.initialize();
 | 
				
			||||||
@@ -65,10 +64,6 @@ class Alert extends WatchUi.View {
 | 
				
			|||||||
            mTimeout = 2000;
 | 
					            mTimeout = 2000;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (Graphics.Dc has :setAntiAlias) {
 | 
					 | 
				
			||||||
            mAntiAlias = true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        mTimer = new Timer.Timer();
 | 
					        mTimer = new Timer.Timer();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -88,7 +83,7 @@ class Alert extends WatchUi.View {
 | 
				
			|||||||
        var bX      = (dc.getWidth()  - bWidth)  / 2;
 | 
					        var bX      = (dc.getWidth()  - bWidth)  / 2;
 | 
				
			||||||
        var bY      = (dc.getHeight() - bHeight) / 2;
 | 
					        var bY      = (dc.getHeight() - bHeight) / 2;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (mAntiAlias) {
 | 
					        if (Graphics.Dc has :setAntiAlias) {
 | 
				
			||||||
            dc.setAntiAlias(true);
 | 
					            dc.setAntiAlias(true);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -98,7 +93,7 @@ class Alert extends WatchUi.View {
 | 
				
			|||||||
        );
 | 
					        );
 | 
				
			||||||
        dc.clear();
 | 
					        dc.clear();
 | 
				
			||||||
        dc.setColor(mBgcolor, mBgcolor);
 | 
					        dc.setColor(mBgcolor, mBgcolor);
 | 
				
			||||||
        dc.fillRoundedRectangle(bX, bY, bWidth, bHeight, bRadius);
 | 
					        dc.fillRoundedRectangle(bX, bY, bWidth, bHeight, scRadius);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        dc.setColor(mFgcolor, mBgcolor);
 | 
					        dc.setColor(mFgcolor, mBgcolor);
 | 
				
			||||||
        for (var i = 0; i < 3; ++i) {
 | 
					        for (var i = 0; i < 3; ++i) {
 | 
				
			||||||
@@ -106,7 +101,7 @@ class Alert extends WatchUi.View {
 | 
				
			|||||||
            bY      += i;
 | 
					            bY      += i;
 | 
				
			||||||
            bWidth  -= (2 * i);
 | 
					            bWidth  -= (2 * i);
 | 
				
			||||||
            bHeight -= (2 * i);
 | 
					            bHeight -= (2 * i);
 | 
				
			||||||
            dc.drawRoundedRectangle(bX, bY, bWidth, bHeight, bRadius);
 | 
					            dc.drawRoundedRectangle(bX, bY, bWidth, bHeight, scRadius);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        var tX = dc.getWidth() / 2;
 | 
					        var tX = dc.getWidth() / 2;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -36,16 +36,14 @@ using Toybox.Communications;
 | 
				
			|||||||
using Toybox.Timer;
 | 
					using Toybox.Timer;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class ErrorView extends ScalableView {
 | 
					class ErrorView extends ScalableView {
 | 
				
			||||||
    private var mText            as Lang.String = "";
 | 
					    private static const scErrorIconMargin as Lang.Float = 7f;
 | 
				
			||||||
 | 
					    private var mText            as Lang.String          = "";
 | 
				
			||||||
    private var mDelegate        as ErrorDelegate;
 | 
					    private var mDelegate        as ErrorDelegate;
 | 
				
			||||||
    private const cSettings      as Lang.Dictionary = {
 | 
					 | 
				
			||||||
        :errorIconMargin => 7f
 | 
					 | 
				
			||||||
    };
 | 
					 | 
				
			||||||
    // Vertical spacing between the top of the face and the error icon
 | 
					    // Vertical spacing between the top of the face and the error icon
 | 
				
			||||||
    private var mErrorIconMargin as Lang.Number;
 | 
					    private var mErrorIconMargin as Lang.Number;
 | 
				
			||||||
    private var mErrorIcon;
 | 
					    private var mErrorIcon;
 | 
				
			||||||
    private var mTextArea        as WatchUi.TextArea or Null;
 | 
					    private var mTextArea        as WatchUi.TextArea or Null;
 | 
				
			||||||
    private var mAntiAlias       as Lang.Boolean = false;
 | 
					    private var mAntiAlias       as Lang.Boolean         = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private static var instance;
 | 
					    private static var instance;
 | 
				
			||||||
    private static var mShown as Lang.Boolean = false;
 | 
					    private static var mShown as Lang.Boolean = false;
 | 
				
			||||||
@@ -54,7 +52,7 @@ class ErrorView extends ScalableView {
 | 
				
			|||||||
        ScalableView.initialize();
 | 
					        ScalableView.initialize();
 | 
				
			||||||
        mDelegate = new ErrorDelegate(self);
 | 
					        mDelegate = new ErrorDelegate(self);
 | 
				
			||||||
        // Convert the settings from % of screen size to pixels
 | 
					        // Convert the settings from % of screen size to pixels
 | 
				
			||||||
        mErrorIconMargin = pixelsForScreen(cSettings.get(:errorIconMargin) as Lang.Float);
 | 
					        mErrorIconMargin = pixelsForScreen(scErrorIconMargin);
 | 
				
			||||||
        mErrorIcon       = Application.loadResource(Rez.Drawables.ErrorIcon) as Graphics.BitmapResource;
 | 
					        mErrorIcon       = Application.loadResource(Rez.Drawables.ErrorIcon) as Graphics.BitmapResource;
 | 
				
			||||||
        if (Graphics.Dc has :setAntiAlias) {
 | 
					        if (Graphics.Dc has :setAntiAlias) {
 | 
				
			||||||
            mAntiAlias = true;
 | 
					            mAntiAlias = true;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -86,8 +86,8 @@ class HomeAssistantApp extends Application.AppBase {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    // Return the initial view of your application here
 | 
					    // Return the initial view of your application here
 | 
				
			||||||
    function getInitialView() as Lang.Array<WatchUi.Views or WatchUi.InputDelegates>? {
 | 
					    function getInitialView() as Lang.Array<WatchUi.Views or WatchUi.InputDelegates>? {
 | 
				
			||||||
        mIsApp               = true;
 | 
					        mIsApp      = true;
 | 
				
			||||||
        mQuitTimer           = new QuitTimer();
 | 
					        mQuitTimer  = new QuitTimer();
 | 
				
			||||||
        RezStrings.update();
 | 
					        RezStrings.update();
 | 
				
			||||||
        mApiStatus  = RezStrings.getChecking();
 | 
					        mApiStatus  = RezStrings.getChecking();
 | 
				
			||||||
        mMenuStatus = RezStrings.getChecking();
 | 
					        mMenuStatus = RezStrings.getChecking();
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -34,12 +34,14 @@ class HomeAssistantConfirmation extends WatchUi.Confirmation {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class HomeAssistantConfirmationDelegate extends WatchUi.ConfirmationDelegate {
 | 
					class HomeAssistantConfirmationDelegate extends WatchUi.ConfirmationDelegate {
 | 
				
			||||||
    private var mConfirmMethod;
 | 
					    private var mConfirmMethod as Method(state as Lang.Boolean) as Void;
 | 
				
			||||||
    private var mTimer;
 | 
					    private var mTimer         as Timer.Timer or Null;
 | 
				
			||||||
 | 
					    private var mState         as Lang.Boolean;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    function initialize(callback as Method() as Void) {
 | 
					    function initialize(callback as Method(state as Lang.Boolean) as Void, state as Lang.Boolean) {
 | 
				
			||||||
        WatchUi.ConfirmationDelegate.initialize();
 | 
					        WatchUi.ConfirmationDelegate.initialize();
 | 
				
			||||||
        mConfirmMethod = callback;
 | 
					        mConfirmMethod = callback;
 | 
				
			||||||
 | 
					        mState         = state;
 | 
				
			||||||
        var timeout = Settings.getConfirmTimeout(); // ms
 | 
					        var timeout = Settings.getConfirmTimeout(); // ms
 | 
				
			||||||
        if (timeout > 0) {
 | 
					        if (timeout > 0) {
 | 
				
			||||||
            mTimer = new Timer.Timer();
 | 
					            mTimer = new Timer.Timer();
 | 
				
			||||||
@@ -49,11 +51,11 @@ class HomeAssistantConfirmationDelegate extends WatchUi.ConfirmationDelegate {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    function onResponse(response) as Lang.Boolean {
 | 
					    function onResponse(response) as Lang.Boolean {
 | 
				
			||||||
        getApp().getQuitTimer().reset();
 | 
					        getApp().getQuitTimer().reset();
 | 
				
			||||||
        if (mTimer) {
 | 
					        if (mTimer != null) {
 | 
				
			||||||
            mTimer.stop();
 | 
					            mTimer.stop();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        if (response == WatchUi.CONFIRM_YES) {
 | 
					        if (response == WatchUi.CONFIRM_YES) {
 | 
				
			||||||
            mConfirmMethod.invoke();
 | 
					            mConfirmMethod.invoke(mState);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        return true;
 | 
					        return true;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -64,21 +64,26 @@ class HomeAssistantMenuItemFactory {
 | 
				
			|||||||
        return instance;
 | 
					        return instance;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    function toggle(label as Lang.String or Lang.Symbol, entity_id as Lang.String or Null) as WatchUi.MenuItem {
 | 
					    function toggle(
 | 
				
			||||||
 | 
					        label     as Lang.String or Lang.Symbol,
 | 
				
			||||||
 | 
					        entity_id as Lang.String or Null,
 | 
				
			||||||
 | 
					        confirm   as Lang.Boolean
 | 
				
			||||||
 | 
					    ) as WatchUi.MenuItem {
 | 
				
			||||||
        return new HomeAssistantToggleMenuItem(
 | 
					        return new HomeAssistantToggleMenuItem(
 | 
				
			||||||
            label,
 | 
					            label,
 | 
				
			||||||
 | 
					            confirm,
 | 
				
			||||||
            { "entity_id" => entity_id },
 | 
					            { "entity_id" => entity_id },
 | 
				
			||||||
            mMenuItemOptions
 | 
					            mMenuItemOptions
 | 
				
			||||||
        );
 | 
					        );
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    function template_tap(
 | 
					    function template_tap(
 | 
				
			||||||
        label      as Lang.String or Lang.Symbol,
 | 
					        label    as Lang.String or Lang.Symbol,
 | 
				
			||||||
        entity     as Lang.String or Null,
 | 
					        entity   as Lang.String or Null,
 | 
				
			||||||
        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,
 | 
				
			||||||
        data       as Lang.Dictionary or Null
 | 
					        data     as Lang.Dictionary or Null
 | 
				
			||||||
    ) as WatchUi.MenuItem {
 | 
					    ) as WatchUi.MenuItem {
 | 
				
			||||||
        if (entity != null) {
 | 
					        if (entity != null) {
 | 
				
			||||||
            if (data == null) {
 | 
					            if (data == null) {
 | 
				
			||||||
@@ -116,11 +121,11 @@ class HomeAssistantMenuItemFactory {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    function tap(
 | 
					    function tap(
 | 
				
			||||||
        label      as Lang.String or Lang.Symbol,
 | 
					        label   as Lang.String or Lang.Symbol,
 | 
				
			||||||
        entity     as Lang.String or Null,
 | 
					        entity  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,
 | 
				
			||||||
        data       as Lang.Dictionary or Null
 | 
					        data    as Lang.Dictionary or Null
 | 
				
			||||||
    ) as WatchUi.MenuItem {
 | 
					    ) as WatchUi.MenuItem {
 | 
				
			||||||
        if (entity != null) {
 | 
					        if (entity != null) {
 | 
				
			||||||
            if (data == null) {
 | 
					            if (data == null) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -57,15 +57,16 @@ class HomeAssistantTapMenuItem extends WatchUi.IconMenuItem {
 | 
				
			|||||||
        if (mConfirm) {
 | 
					        if (mConfirm) {
 | 
				
			||||||
            WatchUi.pushView(
 | 
					            WatchUi.pushView(
 | 
				
			||||||
                new HomeAssistantConfirmation(),
 | 
					                new HomeAssistantConfirmation(),
 | 
				
			||||||
                new HomeAssistantConfirmationDelegate(method(:onConfirm)),
 | 
					                new HomeAssistantConfirmationDelegate(method(:onConfirm), false),
 | 
				
			||||||
                WatchUi.SLIDE_IMMEDIATE
 | 
					                WatchUi.SLIDE_IMMEDIATE
 | 
				
			||||||
            );
 | 
					            );
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
            onConfirm();
 | 
					            mHomeAssistantService.call(mService, mData);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    function onConfirm() as Void {
 | 
					    // NB. Parameter 'b' is ignored
 | 
				
			||||||
 | 
					    function onConfirm(b as Lang.Boolean) as Void {
 | 
				
			||||||
        mHomeAssistantService.call(mService, mData);
 | 
					        mHomeAssistantService.call(mService, mData);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -64,15 +64,16 @@ class HomeAssistantTemplateMenuItem extends WatchUi.IconMenuItem {
 | 
				
			|||||||
        if (mConfirm) {
 | 
					        if (mConfirm) {
 | 
				
			||||||
            WatchUi.pushView(
 | 
					            WatchUi.pushView(
 | 
				
			||||||
                new HomeAssistantConfirmation(),
 | 
					                new HomeAssistantConfirmation(),
 | 
				
			||||||
                new HomeAssistantConfirmationDelegate(method(:onConfirm)),
 | 
					                new HomeAssistantConfirmationDelegate(method(:onConfirm), false),
 | 
				
			||||||
                WatchUi.SLIDE_IMMEDIATE
 | 
					                WatchUi.SLIDE_IMMEDIATE
 | 
				
			||||||
            );
 | 
					            );
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
            onConfirm();
 | 
					            onConfirm(false);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    function onConfirm() as Void {
 | 
					    // NB. Parameter 'b' is ignored
 | 
				
			||||||
 | 
					    function onConfirm(b as Lang.Boolean) as Void {
 | 
				
			||||||
        if (mService != null) {
 | 
					        if (mService != null) {
 | 
				
			||||||
            mHomeAssistantService.call(mService, mData);
 | 
					            mHomeAssistantService.call(mService, mData);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@@ -181,9 +182,7 @@ class HomeAssistantTemplateMenuItem extends WatchUi.IconMenuItem {
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
            Communications.makeWebRequest(
 | 
					            Communications.makeWebRequest(
 | 
				
			||||||
                url,
 | 
					                url,
 | 
				
			||||||
                {
 | 
					                { "template" => mTemplate },
 | 
				
			||||||
                    "template" => mTemplate
 | 
					 | 
				
			||||||
                },
 | 
					 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    :method  => Communications.HTTP_REQUEST_METHOD_POST,
 | 
					                    :method  => Communications.HTTP_REQUEST_METHOD_POST,
 | 
				
			||||||
                    :headers => {
 | 
					                    :headers => {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -25,18 +25,21 @@ using Toybox.Application.Properties;
 | 
				
			|||||||
using Toybox.Timer;
 | 
					using Toybox.Timer;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class HomeAssistantToggleMenuItem extends WatchUi.ToggleMenuItem {
 | 
					class HomeAssistantToggleMenuItem extends WatchUi.ToggleMenuItem {
 | 
				
			||||||
    private var mData as Lang.Dictionary;
 | 
					    private var mConfirm as Lang.Boolean;
 | 
				
			||||||
 | 
					    private var mData    as Lang.Dictionary;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    function initialize(
 | 
					    function initialize(
 | 
				
			||||||
        label     as Lang.String or Lang.Symbol,
 | 
					        label   as Lang.String or Lang.Symbol,
 | 
				
			||||||
        data      as Lang.Dictionary or Null,
 | 
					        confirm as Lang.Boolean,
 | 
				
			||||||
        options   as {
 | 
					        data    as Lang.Dictionary or Null,
 | 
				
			||||||
 | 
					        options as {
 | 
				
			||||||
            :alignment as WatchUi.MenuItem.Alignment,
 | 
					            :alignment as WatchUi.MenuItem.Alignment,
 | 
				
			||||||
            :icon      as Graphics.BitmapType or WatchUi.Drawable or Lang.Symbol
 | 
					            :icon      as Graphics.BitmapType or WatchUi.Drawable or Lang.Symbol
 | 
				
			||||||
        } or Null
 | 
					        } or Null
 | 
				
			||||||
    ) {
 | 
					    ) {
 | 
				
			||||||
        WatchUi.ToggleMenuItem.initialize(label, null, null, false, options);
 | 
					        WatchUi.ToggleMenuItem.initialize(label, null, null, false, options);
 | 
				
			||||||
        mData = data;
 | 
					        mConfirm = confirm;
 | 
				
			||||||
 | 
					        mData    = data;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private function setUiToggle(state as Null or Lang.String) as Void {
 | 
					    private function setUiToggle(state as Null or Lang.String) as Void {
 | 
				
			||||||
@@ -301,4 +304,20 @@ class HomeAssistantToggleMenuItem extends WatchUi.ToggleMenuItem {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    function callService(b as Lang.Boolean) as Void {
 | 
				
			||||||
 | 
					        if (mConfirm) {
 | 
				
			||||||
 | 
					            WatchUi.pushView(
 | 
				
			||||||
 | 
					                new HomeAssistantConfirmation(),
 | 
				
			||||||
 | 
					                new HomeAssistantConfirmationDelegate(method(:onConfirm), b),
 | 
				
			||||||
 | 
					                WatchUi.SLIDE_IMMEDIATE
 | 
				
			||||||
 | 
					            );
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            setState(b);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    function onConfirm(b as Lang.Boolean) as Void {
 | 
				
			||||||
 | 
					        setState(b);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -64,7 +64,7 @@ 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));
 | 
					                    addItem(HomeAssistantMenuItemFactory.create().toggle(name, entity, confirm));
 | 
				
			||||||
                } else if (type.equals("template") && content != null) {
 | 
					                } else if (type.equals("template") && content != null) {
 | 
				
			||||||
                    if (service == null) {
 | 
					                    if (service == null) {
 | 
				
			||||||
                        addItem(HomeAssistantMenuItemFactory.create().template_notap(name, content));
 | 
					                        addItem(HomeAssistantMenuItemFactory.create().template_notap(name, content));
 | 
				
			||||||
@@ -149,7 +149,7 @@ class HomeAssistantViewDelegate extends WatchUi.Menu2InputDelegate {
 | 
				
			|||||||
            if (Globals.scDebug) {
 | 
					            if (Globals.scDebug) {
 | 
				
			||||||
                System.println(haToggleItem.getLabel() + " " + haToggleItem.getId() + " " + haToggleItem.isEnabled());
 | 
					                System.println(haToggleItem.getLabel() + " " + haToggleItem.getId() + " " + haToggleItem.isEnabled());
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            haToggleItem.setState(haToggleItem.isEnabled());
 | 
					            haToggleItem.callService(haToggleItem.isEnabled());
 | 
				
			||||||
        } else if (item instanceof HomeAssistantTapMenuItem) {
 | 
					        } else if (item instanceof HomeAssistantTapMenuItem) {
 | 
				
			||||||
            var haItem = item as HomeAssistantTapMenuItem;
 | 
					            var haItem = item as HomeAssistantTapMenuItem;
 | 
				
			||||||
            if (Globals.scDebug) {
 | 
					            if (Globals.scDebug) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -27,6 +27,7 @@ using Toybox.System;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// Can use push view so must never be run in a glance context
 | 
					// Can use push view so must never be run in a glance context
 | 
				
			||||||
class WebhookManager {
 | 
					class WebhookManager {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    function onReturnRequestWebhookId(responseCode as Lang.Number, data as Null or Lang.Dictionary or Lang.String) as Void {
 | 
					    function onReturnRequestWebhookId(responseCode as Lang.Number, data as Null or Lang.Dictionary or Lang.String) as Void {
 | 
				
			||||||
        switch (responseCode) {
 | 
					        switch (responseCode) {
 | 
				
			||||||
            case Communications.BLE_HOST_TIMEOUT:
 | 
					            case Communications.BLE_HOST_TIMEOUT:
 | 
				
			||||||
@@ -236,11 +237,12 @@ class WebhookManager {
 | 
				
			|||||||
            {
 | 
					            {
 | 
				
			||||||
                :method       => Communications.HTTP_REQUEST_METHOD_POST,
 | 
					                :method       => Communications.HTTP_REQUEST_METHOD_POST,
 | 
				
			||||||
                :headers      => {
 | 
					                :headers      => {
 | 
				
			||||||
                    "Content-Type"  => Communications.REQUEST_CONTENT_TYPE_JSON
 | 
					                    "Content-Type" => Communications.REQUEST_CONTENT_TYPE_JSON
 | 
				
			||||||
                },
 | 
					                },
 | 
				
			||||||
                :responseType => Communications.HTTP_RESPONSE_CONTENT_TYPE_JSON
 | 
					                :responseType => Communications.HTTP_RESPONSE_CONTENT_TYPE_JSON
 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
            method(:onReturnRegisterWebhookSensor)
 | 
					            method(:onReturnRegisterWebhookSensor)
 | 
				
			||||||
        );
 | 
					        );
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user