mirror of
https://github.com/house-of-abbey/GarminHomeAssistant.git
synced 2025-06-17 20:08:33 +00:00
Single HomeAssistantService for all Taps
1. Amended code for a single HomeAssistantService for all 'tap's 2. Removed now redundant GET request for taps without a service now that having a service is enforced. 3. Determined that migrating API code from 'toggle's to the HomeAssistantService is awkward due to the close coupling with other methods in the class.
This commit is contained in:
@ -30,12 +30,12 @@ using Toybox.Timer;
|
|||||||
const bRadius = 10;
|
const bRadius = 10;
|
||||||
|
|
||||||
class Alert extends WatchUi.View {
|
class Alert extends WatchUi.View {
|
||||||
hidden var mTimer;
|
private var mTimer;
|
||||||
hidden var mTimeout;
|
private var mTimeout;
|
||||||
hidden var mText;
|
private var mText;
|
||||||
hidden var mFont;
|
private var mFont;
|
||||||
hidden var mFgcolor;
|
private var mFgcolor;
|
||||||
hidden var mBgcolor;
|
private var mBgcolor;
|
||||||
|
|
||||||
function initialize(params as Lang.Dictionary) {
|
function initialize(params as Lang.Dictionary) {
|
||||||
View.initialize();
|
View.initialize();
|
||||||
|
@ -26,14 +26,14 @@ using Toybox.WatchUi;
|
|||||||
using Toybox.Communications;
|
using Toybox.Communications;
|
||||||
|
|
||||||
class ErrorView extends ScalableView {
|
class ErrorView extends ScalableView {
|
||||||
hidden const cSettings as Lang.Dictionary = {
|
private const cSettings as Lang.Dictionary = {
|
||||||
:errorIconMargin => 7f
|
: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
|
||||||
hidden var mErrorIconMargin;
|
private var mErrorIconMargin;
|
||||||
hidden var mText as Lang.String;
|
private var mText as Lang.String;
|
||||||
hidden var mErrorIcon;
|
private var mErrorIcon;
|
||||||
hidden var mTextArea;
|
private var mTextArea;
|
||||||
|
|
||||||
function initialize(text as Lang.String) {
|
function initialize(text as Lang.String) {
|
||||||
ScalableView.initialize();
|
ScalableView.initialize();
|
||||||
|
@ -24,20 +24,20 @@ using Toybox.WatchUi;
|
|||||||
using Toybox.Application.Properties;
|
using Toybox.Application.Properties;
|
||||||
|
|
||||||
class HomeAssistantApp extends Application.AppBase {
|
class HomeAssistantApp extends Application.AppBase {
|
||||||
hidden var mHaMenu;
|
private var mHaMenu;
|
||||||
hidden var strNoApiKey as Lang.String;
|
private var strNoApiKey as Lang.String;
|
||||||
hidden var strNoApiUrl as Lang.String;
|
private var strNoApiUrl as Lang.String;
|
||||||
hidden var strNoConfigUrl as Lang.String;
|
private var strNoConfigUrl as Lang.String;
|
||||||
hidden var strNoPhone as Lang.String;
|
private var strNoPhone as Lang.String;
|
||||||
hidden var strNoInternet as Lang.String;
|
private var strNoInternet as Lang.String;
|
||||||
hidden var strNoResponse as Lang.String;
|
private var strNoResponse as Lang.String;
|
||||||
hidden var strNoMenu as Lang.String;
|
private var strNoMenu as Lang.String;
|
||||||
hidden var strApiFlood as Lang.String;
|
private var strApiFlood as Lang.String;
|
||||||
hidden var strConfigUrlNotFound as Lang.String;
|
private var strConfigUrlNotFound as Lang.String;
|
||||||
hidden var strUnhandledHttpErr as Lang.String;
|
private var strUnhandledHttpErr as Lang.String;
|
||||||
hidden var strTrailingSlashErr as Lang.String;
|
private var strTrailingSlashErr as Lang.String;
|
||||||
hidden var mItemsToUpdate; // Array initialised by onReturnFetchMenuConfig()
|
private var mItemsToUpdate; // Array initialised by onReturnFetchMenuConfig()
|
||||||
hidden var mNextItemToUpdate = 0; // Index into the above array
|
private var mNextItemToUpdate = 0; // Index into the above array
|
||||||
|
|
||||||
function initialize() {
|
function initialize() {
|
||||||
AppBase.initialize();
|
AppBase.initialize();
|
||||||
|
@ -24,17 +24,20 @@ using Toybox.Graphics;
|
|||||||
using Toybox.Application.Properties;
|
using Toybox.Application.Properties;
|
||||||
|
|
||||||
class HomeAssistantIconMenuItem extends WatchUi.IconMenuItem {
|
class HomeAssistantIconMenuItem extends WatchUi.IconMenuItem {
|
||||||
hidden var mHomeAssistantService as HomeAssistantService;
|
private var mHomeAssistantService as HomeAssistantService;
|
||||||
|
private var mService as Lang.String;
|
||||||
|
// private var mIdentifier as Lang.String;
|
||||||
|
|
||||||
function initialize(
|
function initialize(
|
||||||
label as Lang.String or Lang.Symbol,
|
label as Lang.String or Lang.Symbol,
|
||||||
subLabel as Lang.String or Lang.Symbol or Null,
|
subLabel as Lang.String or Lang.Symbol or Null,
|
||||||
identifier as Lang.Object or Null,
|
identifier as Lang.Object or Null,
|
||||||
service as Lang.String or Null,
|
service as Lang.String or Null,
|
||||||
icon as Graphics.BitmapType or WatchUi.Drawable,
|
icon as Graphics.BitmapType or WatchUi.Drawable,
|
||||||
options as {
|
options as {
|
||||||
:alignment as WatchUi.MenuItem.Alignment
|
:alignment as WatchUi.MenuItem.Alignment
|
||||||
} or Null
|
} or Null,
|
||||||
|
haService as HomeAssistantService
|
||||||
) {
|
) {
|
||||||
WatchUi.IconMenuItem.initialize(
|
WatchUi.IconMenuItem.initialize(
|
||||||
label,
|
label,
|
||||||
@ -44,12 +47,13 @@ class HomeAssistantIconMenuItem extends WatchUi.IconMenuItem {
|
|||||||
options
|
options
|
||||||
);
|
);
|
||||||
|
|
||||||
mHomeAssistantService = new HomeAssistantService(service, identifier);
|
mHomeAssistantService = haService;
|
||||||
|
mIdentifier = identifier;
|
||||||
|
mService = service;
|
||||||
}
|
}
|
||||||
|
|
||||||
function callService() as Void {
|
function callService() as Void {
|
||||||
mHomeAssistantService.call();
|
mHomeAssistantService.call(mIdentifier as Lang.String, mService);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,8 @@ using Toybox.Graphics;
|
|||||||
using Toybox.Application.Properties;
|
using Toybox.Application.Properties;
|
||||||
|
|
||||||
class HomeAssistantMenuItem extends WatchUi.MenuItem {
|
class HomeAssistantMenuItem extends WatchUi.MenuItem {
|
||||||
hidden var mHomeAssistantService as HomeAssistantService;
|
private var mHomeAssistantService as HomeAssistantService;
|
||||||
|
private var mService as Lang.String;
|
||||||
|
|
||||||
function initialize(
|
function initialize(
|
||||||
label as Lang.String or Lang.Symbol,
|
label as Lang.String or Lang.Symbol,
|
||||||
@ -34,7 +35,8 @@ class HomeAssistantMenuItem extends WatchUi.MenuItem {
|
|||||||
options as {
|
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,
|
||||||
|
haService as HomeAssistantService
|
||||||
) {
|
) {
|
||||||
WatchUi.MenuItem.initialize(
|
WatchUi.MenuItem.initialize(
|
||||||
label,
|
label,
|
||||||
@ -43,11 +45,12 @@ class HomeAssistantMenuItem extends WatchUi.MenuItem {
|
|||||||
options
|
options
|
||||||
);
|
);
|
||||||
|
|
||||||
mHomeAssistantService = new HomeAssistantService(service, identifier);
|
mHomeAssistantService = haService;
|
||||||
|
mService = service;
|
||||||
}
|
}
|
||||||
|
|
||||||
function callService() as Void {
|
function callService() as Void {
|
||||||
mHomeAssistantService.call();
|
mHomeAssistantService.call(mIdentifier as Lang.String, mService);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -23,57 +23,57 @@ using Toybox.Lang;
|
|||||||
using Toybox.WatchUi;
|
using Toybox.WatchUi;
|
||||||
|
|
||||||
class HomeAssistantMenuItemFactory {
|
class HomeAssistantMenuItemFactory {
|
||||||
|
private var mMenuItemOptions as Lang.Dictionary;
|
||||||
private var mMenuItemAlignment;
|
private var mLabelToggle as Lang.Dictionary;
|
||||||
private var mLabelToggle;
|
private var strMenuItemTap as Lang.String;
|
||||||
private var strMenuItemTap;
|
private var bRepresentTypesWithLabels as Lang.Boolean;
|
||||||
private var bRepresentTypesWithLabels;
|
private var mTapTypeIcon as WatchUi.Bitmap;
|
||||||
|
private var mGroupTypeIcon as WatchUi.Bitmap;
|
||||||
private var mTapTypeIcon;
|
private var mHomeAssistantService as HomeAssistantService;
|
||||||
|
|
||||||
private var mGroupTypeIcon;
|
|
||||||
|
|
||||||
private static var instance;
|
private static var instance;
|
||||||
|
|
||||||
private function initialize() {
|
private function initialize() {
|
||||||
mLabelToggle = {
|
mLabelToggle = {
|
||||||
:enabled => WatchUi.loadResource($.Rez.Strings.MenuItemOn) as Lang.String,
|
:enabled => WatchUi.loadResource($.Rez.Strings.MenuItemOn) as Lang.String,
|
||||||
:disabled => WatchUi.loadResource($.Rez.Strings.MenuItemOff) as Lang.String
|
:disabled => WatchUi.loadResource($.Rez.Strings.MenuItemOff) as Lang.String
|
||||||
};
|
};
|
||||||
|
|
||||||
bRepresentTypesWithLabels = Application.Properties.getValue("types_representation") as Lang.Boolean;
|
bRepresentTypesWithLabels = Application.Properties.getValue("types_representation") as Lang.Boolean;
|
||||||
|
|
||||||
var menuItemAlignment = Application.Properties.getValue("menu_alignment") as Lang.Boolean;
|
var menuItemAlignment = Application.Properties.getValue("menu_alignment") as Lang.Boolean;
|
||||||
|
if(menuItemAlignment){
|
||||||
if(menuItemAlignment == true){
|
mMenuItemOptions = {
|
||||||
mMenuItemAlignment = {:alignment => WatchUi.MenuItem.MENU_ITEM_LABEL_ALIGN_RIGHT};
|
:alignment => WatchUi.MenuItem.MENU_ITEM_LABEL_ALIGN_RIGHT
|
||||||
|
};
|
||||||
} else {
|
} else {
|
||||||
mMenuItemAlignment = {:alignment => WatchUi.MenuItem.MENU_ITEM_LABEL_ALIGN_LEFT};
|
mMenuItemOptions = {
|
||||||
|
:alignment => WatchUi.MenuItem.MENU_ITEM_LABEL_ALIGN_LEFT
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
strMenuItemTap = WatchUi.loadResource($.Rez.Strings.MenuItemTap);
|
strMenuItemTap = WatchUi.loadResource($.Rez.Strings.MenuItemTap);
|
||||||
mTapTypeIcon = new WatchUi.Bitmap({
|
mTapTypeIcon = new WatchUi.Bitmap({
|
||||||
:rezId=>$.Rez.Drawables.TapTypeIcon,
|
:rezId => $.Rez.Drawables.TapTypeIcon,
|
||||||
:locX=>WatchUi.LAYOUT_HALIGN_CENTER,
|
:locX => WatchUi.LAYOUT_HALIGN_CENTER,
|
||||||
:locY=>WatchUi.LAYOUT_VALIGN_CENTER
|
:locY => WatchUi.LAYOUT_VALIGN_CENTER
|
||||||
});
|
});
|
||||||
|
|
||||||
mGroupTypeIcon = new WatchUi.Bitmap({
|
mGroupTypeIcon = new WatchUi.Bitmap({
|
||||||
:rezId=>$.Rez.Drawables.GroupTypeIcon,
|
:rezId => $.Rez.Drawables.GroupTypeIcon,
|
||||||
:locX=>WatchUi.LAYOUT_HALIGN_CENTER,
|
:locX => WatchUi.LAYOUT_HALIGN_CENTER,
|
||||||
:locY=>WatchUi.LAYOUT_VALIGN_CENTER
|
:locY => WatchUi.LAYOUT_VALIGN_CENTER
|
||||||
});
|
});
|
||||||
|
mHomeAssistantService = new HomeAssistantService();
|
||||||
}
|
}
|
||||||
|
|
||||||
static function create() {
|
static function create() as HomeAssistantMenuItemFactory {
|
||||||
if (instance == null) {
|
if (instance == null) {
|
||||||
instance = new HomeAssistantMenuItemFactory();
|
instance = new HomeAssistantMenuItemFactory();
|
||||||
}
|
}
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
function toggle(label as Lang.String or Lang.Symbol, identifier as Lang.Object or Null) as WatchUi.MenuItem{
|
function toggle(label as Lang.String or Lang.Symbol, identifier as Lang.Object or Null) as WatchUi.MenuItem {
|
||||||
var subLabel = null;
|
var subLabel = null;
|
||||||
|
|
||||||
if (bRepresentTypesWithLabels == true){
|
if (bRepresentTypesWithLabels == true){
|
||||||
@ -85,36 +85,38 @@ class HomeAssistantMenuItemFactory {
|
|||||||
subLabel,
|
subLabel,
|
||||||
identifier,
|
identifier,
|
||||||
false,
|
false,
|
||||||
mMenuItemAlignment
|
mMenuItemOptions
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function tap(label as Lang.String or Lang.Symbol, identifier as Lang.Object or Null, service as Lang.String or Null) as WatchUi.MenuItem{
|
function tap(label as Lang.String or Lang.Symbol, identifier as Lang.Object or Null, service as Lang.String or Null) as WatchUi.MenuItem {
|
||||||
if (bRepresentTypesWithLabels) {
|
if (bRepresentTypesWithLabels) {
|
||||||
return new HomeAssistantMenuItem(
|
return new HomeAssistantMenuItem(
|
||||||
label,
|
label,
|
||||||
strMenuItemTap,
|
strMenuItemTap,
|
||||||
identifier,
|
identifier,
|
||||||
service,
|
service,
|
||||||
mMenuItemAlignment
|
mMenuItemOptions,
|
||||||
);
|
mHomeAssistantService
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
return new HomeAssistantIconMenuItem(
|
return new HomeAssistantIconMenuItem(
|
||||||
label,
|
label,
|
||||||
null,
|
null,
|
||||||
identifier,
|
identifier,
|
||||||
service,
|
service,
|
||||||
mTapTypeIcon,
|
mTapTypeIcon,
|
||||||
mMenuItemAlignment
|
mMenuItemOptions,
|
||||||
);
|
mHomeAssistantService
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function group(definition as Lang.Dictionary) as WatchUi.MenuItem{
|
function group(definition as Lang.Dictionary) as WatchUi.MenuItem {
|
||||||
if (bRepresentTypesWithLabels) {
|
if (bRepresentTypesWithLabels) {
|
||||||
return new HomeAssistantViewMenuItem(definition);
|
return new HomeAssistantViewMenuItem(definition);
|
||||||
} else {
|
} else {
|
||||||
return new HomeAssistantViewIconMenuItem(definition, mGroupTypeIcon, mMenuItemAlignment);
|
return new HomeAssistantViewIconMenuItem(definition, mGroupTypeIcon, mMenuItemOptions);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,21 +23,16 @@ using Toybox.WatchUi;
|
|||||||
using Toybox.Graphics;
|
using Toybox.Graphics;
|
||||||
using Toybox.Application.Properties;
|
using Toybox.Application.Properties;
|
||||||
|
|
||||||
class HomeAssistantService{
|
class HomeAssistantService {
|
||||||
hidden var mApiKey as Lang.String;
|
private var mApiKey as Lang.String;
|
||||||
hidden var strNoPhone as Lang.String;
|
private var strNoPhone as Lang.String;
|
||||||
hidden var strNoInternet as Lang.String;
|
private var strNoInternet as Lang.String;
|
||||||
hidden var strNoResponse as Lang.String;
|
private var strNoResponse as Lang.String;
|
||||||
hidden var strApiFlood as Lang.String;
|
private var strApiFlood as Lang.String;
|
||||||
hidden var strApiUrlNotFound as Lang.String;
|
private var strApiUrlNotFound as Lang.String;
|
||||||
hidden var strUnhandledHttpErr as Lang.String;
|
private var strUnhandledHttpErr as Lang.String;
|
||||||
hidden var mService as Lang.String;
|
|
||||||
hidden var mIdentifier as Lang.Object;
|
|
||||||
|
|
||||||
function initialize(
|
function initialize() {
|
||||||
service as Lang.String or Null,
|
|
||||||
identifier as Lang.Object or Null
|
|
||||||
) {
|
|
||||||
strNoPhone = WatchUi.loadResource($.Rez.Strings.NoPhone);
|
strNoPhone = WatchUi.loadResource($.Rez.Strings.NoPhone);
|
||||||
strNoInternet = WatchUi.loadResource($.Rez.Strings.NoInternet);
|
strNoInternet = WatchUi.loadResource($.Rez.Strings.NoInternet);
|
||||||
strNoResponse = WatchUi.loadResource($.Rez.Strings.NoResponse);
|
strNoResponse = WatchUi.loadResource($.Rez.Strings.NoResponse);
|
||||||
@ -45,14 +40,13 @@ class HomeAssistantService{
|
|||||||
strApiUrlNotFound = WatchUi.loadResource($.Rez.Strings.ApiUrlNotFound);
|
strApiUrlNotFound = WatchUi.loadResource($.Rez.Strings.ApiUrlNotFound);
|
||||||
strUnhandledHttpErr = WatchUi.loadResource($.Rez.Strings.UnhandledHttpErr);
|
strUnhandledHttpErr = WatchUi.loadResource($.Rez.Strings.UnhandledHttpErr);
|
||||||
mApiKey = Properties.getValue("api_key");
|
mApiKey = Properties.getValue("api_key");
|
||||||
mService = service;
|
|
||||||
mIdentifier = identifier;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Callback function after completing the POST request to call a service.
|
// Callback function after completing the POST request to call a service.
|
||||||
//
|
//
|
||||||
function onReturnCall(responseCode as Lang.Number, data as Null or Lang.Dictionary or Lang.String) as Void {
|
function onReturnCall(responseCode as Lang.Number, data as Null or Lang.Dictionary or Lang.String, context as Lang.Object) as Void {
|
||||||
if (Globals.scDebug) {
|
var identifier = context as Lang.String;
|
||||||
|
if (Globals.scDebug) {
|
||||||
System.println("HomeAssistantService onReturnCall() Response Code: " + responseCode);
|
System.println("HomeAssistantService onReturnCall() Response Code: " + responseCode);
|
||||||
System.println("HomeAssistantService onReturnCall() Response Data: " + data);
|
System.println("HomeAssistantService onReturnCall() Response Data: " + data);
|
||||||
}
|
}
|
||||||
@ -86,7 +80,7 @@ class HomeAssistantService{
|
|||||||
var d = data as Lang.Array;
|
var d = data as Lang.Array;
|
||||||
var toast = "Executed";
|
var toast = "Executed";
|
||||||
for(var i = 0; i < d.size(); i++) {
|
for(var i = 0; i < d.size(); i++) {
|
||||||
if ((d[i].get("entity_id") as Lang.String).equals(mIdentifier)) {
|
if ((d[i].get("entity_id") as Lang.String).equals(identifier)) {
|
||||||
toast = (d[i].get("attributes") as Lang.Dictionary).get("friendly_name") as Lang.String;
|
toast = (d[i].get("attributes") as Lang.Dictionary).get("friendly_name") as Lang.String;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -109,14 +103,15 @@ class HomeAssistantService{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function call() as Void {
|
function call(identifier as Lang.String, service as Lang.String) as Void {
|
||||||
var options = {
|
var options = {
|
||||||
: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,
|
||||||
"Authorization" => "Bearer " + mApiKey
|
"Authorization" => "Bearer " + mApiKey
|
||||||
},
|
},
|
||||||
:responseType => Communications.HTTP_RESPONSE_CONTENT_TYPE_JSON
|
:responseType => Communications.HTTP_RESPONSE_CONTENT_TYPE_JSON,
|
||||||
|
:context => identifier
|
||||||
};
|
};
|
||||||
if (! System.getDeviceSettings().phoneConnected) {
|
if (! System.getDeviceSettings().phoneConnected) {
|
||||||
if (Globals.scDebug) {
|
if (Globals.scDebug) {
|
||||||
@ -129,36 +124,19 @@ class HomeAssistantService{
|
|||||||
}
|
}
|
||||||
WatchUi.pushView(new ErrorView(strNoInternet + "."), new ErrorDelegate(), WatchUi.SLIDE_UP);
|
WatchUi.pushView(new ErrorView(strNoInternet + "."), new ErrorDelegate(), WatchUi.SLIDE_UP);
|
||||||
} else {
|
} else {
|
||||||
// Updated SDK and got a new error
|
var url = (Properties.getValue("api_url") as Lang.String) + "/services/" + service.substring(0, service.find(".")) + "/" + service.substring(service.find(".")+1, null);
|
||||||
// ERROR: venu: Cannot find symbol ':substring' on type 'PolyType<Null or $.Toybox.Lang.Object>'.
|
if (Globals.scDebug) {
|
||||||
var id = mIdentifier as Lang.String;
|
System.println("HomeAssistantService call() URL=" + url);
|
||||||
if (mService == null) {
|
System.println("HomeAssistantService call() service=" + service);
|
||||||
var url = (Properties.getValue("api_url") as Lang.String) + "/services/" + id.substring(0, id.find(".")) + "/" + id.substring(id.find(".")+1, null);
|
|
||||||
if (Globals.scDebug) {
|
|
||||||
System.println("HomeAssistantService call() URL=" + url);
|
|
||||||
System.println("HomeAssistantService call() mIdentifier=" + mIdentifier);
|
|
||||||
}
|
|
||||||
Communications.makeWebRequest(
|
|
||||||
url,
|
|
||||||
null,
|
|
||||||
options,
|
|
||||||
method(:onReturnCall)
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
var url = (Properties.getValue("api_url") as Lang.String) + "/services/" + mService.substring(0, mService.find(".")) + "/" + mService.substring(mService.find(".")+1, null);
|
|
||||||
if (Globals.scDebug) {
|
|
||||||
System.println("HomeAssistantService call() URL=" + url);
|
|
||||||
System.println("HomeAssistantService call() mService=" + mService);
|
|
||||||
}
|
|
||||||
Communications.makeWebRequest(
|
|
||||||
url,
|
|
||||||
{
|
|
||||||
"entity_id" => id
|
|
||||||
},
|
|
||||||
options,
|
|
||||||
method(:onReturnCall)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
Communications.makeWebRequest(
|
||||||
|
url,
|
||||||
|
{
|
||||||
|
"entity_id" => identifier
|
||||||
|
},
|
||||||
|
options,
|
||||||
|
method(:onReturnCall)
|
||||||
|
);
|
||||||
if (Attention has :vibrate) {
|
if (Attention has :vibrate) {
|
||||||
Attention.vibrate([
|
Attention.vibrate([
|
||||||
new Attention.VibeProfile(50, 100), // On for 100ms
|
new Attention.VibeProfile(50, 100), // On for 100ms
|
||||||
|
@ -25,23 +25,23 @@ using Toybox.Application.Properties;
|
|||||||
using Toybox.Timer;
|
using Toybox.Timer;
|
||||||
|
|
||||||
class HomeAssistantToggleMenuItem extends WatchUi.ToggleMenuItem {
|
class HomeAssistantToggleMenuItem extends WatchUi.ToggleMenuItem {
|
||||||
hidden var mApiKey as Lang.String;
|
private var mApiKey as Lang.String;
|
||||||
hidden var strNoPhone as Lang.String;
|
private var strNoPhone as Lang.String;
|
||||||
hidden var strNoInternet as Lang.String;
|
private var strNoInternet as Lang.String;
|
||||||
hidden var strNoResponse as Lang.String;
|
private var strNoResponse as Lang.String;
|
||||||
hidden var strApiFlood as Lang.String;
|
private var strApiFlood as Lang.String;
|
||||||
hidden var strApiUrlNotFound as Lang.String;
|
private var strApiUrlNotFound as Lang.String;
|
||||||
hidden var strUnhandledHttpErr as Lang.String;
|
private var strUnhandledHttpErr as Lang.String;
|
||||||
|
|
||||||
function initialize(
|
function initialize(
|
||||||
label as Lang.String or Lang.Symbol,
|
label as Lang.String or Lang.Symbol,
|
||||||
subLabel as Lang.String or Lang.Symbol or {
|
subLabel as Lang.String or Lang.Symbol or {
|
||||||
:enabled as Lang.String or Lang.Symbol or Null,
|
:enabled as Lang.String or Lang.Symbol or Null,
|
||||||
:disabled as Lang.String or Lang.Symbol or Null
|
:disabled as Lang.String or Lang.Symbol or Null
|
||||||
} or Null,
|
} or Null,
|
||||||
identifier,
|
identifier,
|
||||||
enabled as Lang.Boolean,
|
enabled as Lang.Boolean,
|
||||||
options as {
|
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
|
||||||
|
@ -24,10 +24,9 @@ using Toybox.Graphics;
|
|||||||
using Toybox.WatchUi;
|
using Toybox.WatchUi;
|
||||||
|
|
||||||
class HomeAssistantView extends WatchUi.Menu2 {
|
class HomeAssistantView extends WatchUi.Menu2 {
|
||||||
|
|
||||||
// List of items that need to have their status updated periodically
|
// List of items that need to have their status updated periodically
|
||||||
hidden var mListToggleItems = [];
|
private var mListToggleItems = [];
|
||||||
hidden var mListMenuItems = [];
|
private var mListMenuItems = [];
|
||||||
|
|
||||||
function initialize(
|
function initialize(
|
||||||
definition as Lang.Dictionary,
|
definition as Lang.Dictionary,
|
||||||
|
@ -22,7 +22,7 @@ using Toybox.Lang;
|
|||||||
using Toybox.WatchUi;
|
using Toybox.WatchUi;
|
||||||
|
|
||||||
class HomeAssistantViewIconMenuItem extends WatchUi.IconMenuItem {
|
class HomeAssistantViewIconMenuItem extends WatchUi.IconMenuItem {
|
||||||
hidden var mMenu as HomeAssistantView;
|
private var mMenu as HomeAssistantView;
|
||||||
|
|
||||||
function initialize(definition as Lang.Dictionary, icon as WatchUi.Drawable, options as {
|
function initialize(definition as Lang.Dictionary, icon as WatchUi.Drawable, options as {
|
||||||
:alignment as WatchUi.MenuItem.Alignment
|
:alignment as WatchUi.MenuItem.Alignment
|
||||||
|
@ -22,7 +22,7 @@ using Toybox.Lang;
|
|||||||
using Toybox.WatchUi;
|
using Toybox.WatchUi;
|
||||||
|
|
||||||
class HomeAssistantViewMenuItem extends WatchUi.MenuItem {
|
class HomeAssistantViewMenuItem extends WatchUi.MenuItem {
|
||||||
hidden var mMenu as HomeAssistantView;
|
private var mMenu as HomeAssistantView;
|
||||||
|
|
||||||
function initialize(definition as Lang.Dictionary) {
|
function initialize(definition as Lang.Dictionary) {
|
||||||
// definitions.get(...) are Strings here as they have been checked by HomeAssistantView first
|
// definitions.get(...) are Strings here as they have been checked by HomeAssistantView first
|
||||||
|
@ -23,7 +23,7 @@ using Toybox.WatchUi;
|
|||||||
using Toybox.Math;
|
using Toybox.Math;
|
||||||
|
|
||||||
class ScalableView extends WatchUi.View {
|
class ScalableView extends WatchUi.View {
|
||||||
hidden var mScreenWidth;
|
private var mScreenWidth;
|
||||||
|
|
||||||
function initialize() {
|
function initialize() {
|
||||||
View.initialize();
|
View.initialize();
|
||||||
|
Reference in New Issue
Block a user