mirror of
https://github.com/house-of-abbey/GarminHomeAssistant.git
synced 2025-06-19 04:48:31 +00:00
Initial Solution
This commit is contained in:
@ -28,14 +28,13 @@ using Toybox.WatchUi;
|
||||
using Toybox.Timer;
|
||||
|
||||
class Alert extends WatchUi.View {
|
||||
private static const bRadius = 10;
|
||||
private var mTimer as Timer.Timer;
|
||||
private var mTimeout as Lang.Number;
|
||||
private var mText as Lang.String;
|
||||
private var mFont as Graphics.FontType;
|
||||
private var mFgcolor as Graphics.ColorType;
|
||||
private var mBgcolor as Graphics.ColorType;
|
||||
private var mAntiAlias as Lang.Boolean = false;
|
||||
private static const scRadius = 10;
|
||||
private var mTimer as Timer.Timer;
|
||||
private var mTimeout as Lang.Number;
|
||||
private var mText as Lang.String;
|
||||
private var mFont as Graphics.FontType;
|
||||
private var mFgcolor as Graphics.ColorType;
|
||||
private var mBgcolor as Graphics.ColorType;
|
||||
|
||||
function initialize(params as Lang.Dictionary) {
|
||||
View.initialize();
|
||||
@ -65,10 +64,6 @@ class Alert extends WatchUi.View {
|
||||
mTimeout = 2000;
|
||||
}
|
||||
|
||||
if (Graphics.Dc has :setAntiAlias) {
|
||||
mAntiAlias = true;
|
||||
}
|
||||
|
||||
mTimer = new Timer.Timer();
|
||||
}
|
||||
|
||||
@ -88,7 +83,7 @@ class Alert extends WatchUi.View {
|
||||
var bX = (dc.getWidth() - bWidth) / 2;
|
||||
var bY = (dc.getHeight() - bHeight) / 2;
|
||||
|
||||
if (mAntiAlias) {
|
||||
if (Graphics.Dc has :setAntiAlias) {
|
||||
dc.setAntiAlias(true);
|
||||
}
|
||||
|
||||
@ -98,7 +93,7 @@ class Alert extends WatchUi.View {
|
||||
);
|
||||
dc.clear();
|
||||
dc.setColor(mBgcolor, mBgcolor);
|
||||
dc.fillRoundedRectangle(bX, bY, bWidth, bHeight, bRadius);
|
||||
dc.fillRoundedRectangle(bX, bY, bWidth, bHeight, scRadius);
|
||||
|
||||
dc.setColor(mFgcolor, mBgcolor);
|
||||
for (var i = 0; i < 3; ++i) {
|
||||
@ -106,7 +101,7 @@ class Alert extends WatchUi.View {
|
||||
bY += i;
|
||||
bWidth -= (2 * i);
|
||||
bHeight -= (2 * i);
|
||||
dc.drawRoundedRectangle(bX, bY, bWidth, bHeight, bRadius);
|
||||
dc.drawRoundedRectangle(bX, bY, bWidth, bHeight, scRadius);
|
||||
}
|
||||
|
||||
var tX = dc.getWidth() / 2;
|
||||
|
@ -36,16 +36,14 @@ using Toybox.Communications;
|
||||
using Toybox.Timer;
|
||||
|
||||
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 const cSettings as Lang.Dictionary = {
|
||||
:errorIconMargin => 7f
|
||||
};
|
||||
// Vertical spacing between the top of the face and the error icon
|
||||
private var mErrorIconMargin as Lang.Number;
|
||||
private var mErrorIcon;
|
||||
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 mShown as Lang.Boolean = false;
|
||||
@ -54,7 +52,7 @@ class ErrorView extends ScalableView {
|
||||
ScalableView.initialize();
|
||||
mDelegate = new ErrorDelegate(self);
|
||||
// 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;
|
||||
if (Graphics.Dc has :setAntiAlias) {
|
||||
mAntiAlias = true;
|
||||
|
@ -86,8 +86,8 @@ class HomeAssistantApp extends Application.AppBase {
|
||||
|
||||
// Return the initial view of your application here
|
||||
function getInitialView() as Lang.Array<WatchUi.Views or WatchUi.InputDelegates>? {
|
||||
mIsApp = true;
|
||||
mQuitTimer = new QuitTimer();
|
||||
mIsApp = true;
|
||||
mQuitTimer = new QuitTimer();
|
||||
RezStrings.update();
|
||||
mApiStatus = RezStrings.getChecking();
|
||||
mMenuStatus = RezStrings.getChecking();
|
||||
|
@ -34,12 +34,14 @@ class HomeAssistantConfirmation extends WatchUi.Confirmation {
|
||||
}
|
||||
|
||||
class HomeAssistantConfirmationDelegate extends WatchUi.ConfirmationDelegate {
|
||||
private var mConfirmMethod;
|
||||
private var mTimer;
|
||||
private var mConfirmMethod as Method(state as Lang.Boolean) as Void;
|
||||
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();
|
||||
mConfirmMethod = callback;
|
||||
mState = state;
|
||||
var timeout = Settings.getConfirmTimeout(); // ms
|
||||
if (timeout > 0) {
|
||||
mTimer = new Timer.Timer();
|
||||
@ -49,11 +51,11 @@ class HomeAssistantConfirmationDelegate extends WatchUi.ConfirmationDelegate {
|
||||
|
||||
function onResponse(response) as Lang.Boolean {
|
||||
getApp().getQuitTimer().reset();
|
||||
if (mTimer) {
|
||||
if (mTimer != null) {
|
||||
mTimer.stop();
|
||||
}
|
||||
if (response == WatchUi.CONFIRM_YES) {
|
||||
mConfirmMethod.invoke();
|
||||
mConfirmMethod.invoke(mState);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -64,21 +64,26 @@ class HomeAssistantMenuItemFactory {
|
||||
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(
|
||||
label,
|
||||
confirm,
|
||||
{ "entity_id" => entity_id },
|
||||
mMenuItemOptions
|
||||
);
|
||||
}
|
||||
|
||||
function template_tap(
|
||||
label as Lang.String or Lang.Symbol,
|
||||
entity as Lang.String or Null,
|
||||
template as Lang.String or Null,
|
||||
service as Lang.String or Null,
|
||||
confirm as Lang.Boolean,
|
||||
data as Lang.Dictionary or Null
|
||||
label as Lang.String or Lang.Symbol,
|
||||
entity as Lang.String or Null,
|
||||
template as Lang.String or Null,
|
||||
service as Lang.String or Null,
|
||||
confirm as Lang.Boolean,
|
||||
data as Lang.Dictionary or Null
|
||||
) as WatchUi.MenuItem {
|
||||
if (entity != null) {
|
||||
if (data == null) {
|
||||
@ -116,11 +121,11 @@ class HomeAssistantMenuItemFactory {
|
||||
}
|
||||
|
||||
function tap(
|
||||
label as Lang.String or Lang.Symbol,
|
||||
entity as Lang.String or Null,
|
||||
service as Lang.String or Null,
|
||||
confirm as Lang.Boolean,
|
||||
data as Lang.Dictionary or Null
|
||||
label as Lang.String or Lang.Symbol,
|
||||
entity as Lang.String or Null,
|
||||
service as Lang.String or Null,
|
||||
confirm as Lang.Boolean,
|
||||
data as Lang.Dictionary or Null
|
||||
) as WatchUi.MenuItem {
|
||||
if (entity != null) {
|
||||
if (data == null) {
|
||||
|
@ -57,15 +57,16 @@ class HomeAssistantTapMenuItem extends WatchUi.IconMenuItem {
|
||||
if (mConfirm) {
|
||||
WatchUi.pushView(
|
||||
new HomeAssistantConfirmation(),
|
||||
new HomeAssistantConfirmationDelegate(method(:onConfirm)),
|
||||
new HomeAssistantConfirmationDelegate(method(:onConfirm), false),
|
||||
WatchUi.SLIDE_IMMEDIATE
|
||||
);
|
||||
} 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);
|
||||
}
|
||||
|
||||
|
@ -64,15 +64,16 @@ class HomeAssistantTemplateMenuItem extends WatchUi.IconMenuItem {
|
||||
if (mConfirm) {
|
||||
WatchUi.pushView(
|
||||
new HomeAssistantConfirmation(),
|
||||
new HomeAssistantConfirmationDelegate(method(:onConfirm)),
|
||||
new HomeAssistantConfirmationDelegate(method(:onConfirm), false),
|
||||
WatchUi.SLIDE_IMMEDIATE
|
||||
);
|
||||
} else {
|
||||
onConfirm();
|
||||
onConfirm(false);
|
||||
}
|
||||
}
|
||||
|
||||
function onConfirm() as Void {
|
||||
// NB. Parameter 'b' is ignored
|
||||
function onConfirm(b as Lang.Boolean) as Void {
|
||||
if (mService != null) {
|
||||
mHomeAssistantService.call(mService, mData);
|
||||
}
|
||||
@ -181,9 +182,7 @@ class HomeAssistantTemplateMenuItem extends WatchUi.IconMenuItem {
|
||||
}
|
||||
Communications.makeWebRequest(
|
||||
url,
|
||||
{
|
||||
"template" => mTemplate
|
||||
},
|
||||
{ "template" => mTemplate },
|
||||
{
|
||||
:method => Communications.HTTP_REQUEST_METHOD_POST,
|
||||
:headers => {
|
||||
|
@ -25,18 +25,21 @@ using Toybox.Application.Properties;
|
||||
using Toybox.Timer;
|
||||
|
||||
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(
|
||||
label as Lang.String or Lang.Symbol,
|
||||
data as Lang.Dictionary or Null,
|
||||
options as {
|
||||
label as Lang.String or Lang.Symbol,
|
||||
confirm as Lang.Boolean,
|
||||
data as Lang.Dictionary or Null,
|
||||
options as {
|
||||
:alignment as WatchUi.MenuItem.Alignment,
|
||||
:icon as Graphics.BitmapType or WatchUi.Drawable or Lang.Symbol
|
||||
} or Null
|
||||
) {
|
||||
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 {
|
||||
@ -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.equals("toggle") && entity != null) {
|
||||
addItem(HomeAssistantMenuItemFactory.create().toggle(name, entity));
|
||||
addItem(HomeAssistantMenuItemFactory.create().toggle(name, entity, confirm));
|
||||
} else if (type.equals("template") && content != null) {
|
||||
if (service == null) {
|
||||
addItem(HomeAssistantMenuItemFactory.create().template_notap(name, content));
|
||||
@ -149,7 +149,7 @@ class HomeAssistantViewDelegate extends WatchUi.Menu2InputDelegate {
|
||||
if (Globals.scDebug) {
|
||||
System.println(haToggleItem.getLabel() + " " + haToggleItem.getId() + " " + haToggleItem.isEnabled());
|
||||
}
|
||||
haToggleItem.setState(haToggleItem.isEnabled());
|
||||
haToggleItem.callService(haToggleItem.isEnabled());
|
||||
} else if (item instanceof HomeAssistantTapMenuItem) {
|
||||
var haItem = item as HomeAssistantTapMenuItem;
|
||||
if (Globals.scDebug) {
|
||||
|
@ -27,6 +27,7 @@ using Toybox.System;
|
||||
|
||||
// Can use push view so must never be run in a glance context
|
||||
class WebhookManager {
|
||||
|
||||
function onReturnRequestWebhookId(responseCode as Lang.Number, data as Null or Lang.Dictionary or Lang.String) as Void {
|
||||
switch (responseCode) {
|
||||
case Communications.BLE_HOST_TIMEOUT:
|
||||
@ -236,11 +237,12 @@ class WebhookManager {
|
||||
{
|
||||
:method => Communications.HTTP_REQUEST_METHOD_POST,
|
||||
:headers => {
|
||||
"Content-Type" => Communications.REQUEST_CONTENT_TYPE_JSON
|
||||
"Content-Type" => Communications.REQUEST_CONTENT_TYPE_JSON
|
||||
},
|
||||
:responseType => Communications.HTTP_RESPONSE_CONTENT_TYPE_JSON
|
||||
},
|
||||
method(:onReturnRegisterWebhookSensor)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user