mirror of
https://github.com/house-of-abbey/GarminHomeAssistant.git
synced 2025-08-06 20:08:33 +00:00
7 New devices, mainly Fenix
SDK updated to 7.3.0 in order to get new devices to work in simulation. This means some function prototypes have had to be amended.
This commit is contained in:
@ -91,7 +91,7 @@ class ErrorView extends ScalableView {
|
||||
return mDelegate;
|
||||
}
|
||||
|
||||
static function create(text as Lang.String) as Lang.Array<ErrorView or ErrorDelegate> {
|
||||
static function create(text as Lang.String) as [ WatchUi.Views ] or [ WatchUi.Views, WatchUi.InputDelegates ] {
|
||||
if (instance == null) {
|
||||
instance = new ErrorView();
|
||||
}
|
||||
|
@ -27,17 +27,18 @@ using Toybox.Timer;
|
||||
|
||||
(:glance, :background)
|
||||
class HomeAssistantApp extends Application.AppBase {
|
||||
private var mApiStatus as Lang.String or Null;
|
||||
private var mMenuStatus as Lang.String or Null;
|
||||
private var mHaMenu as HomeAssistantView or Null;
|
||||
private var mQuitTimer as QuitTimer or Null;
|
||||
private var mGlanceTimer as Timer.Timer or Null;
|
||||
private var mUpdateTimer as Timer.Timer or Null;
|
||||
private var mApiStatus as Lang.String or Null;
|
||||
private var mMenuStatus as Lang.String or Null;
|
||||
private var mHaMenu as HomeAssistantView or Null;
|
||||
private var mQuitTimer as QuitTimer or Null;
|
||||
private var mGlanceTimer as Timer.Timer or Null;
|
||||
private var mUpdateTimer as Timer.Timer or Null;
|
||||
// Array initialised by onReturnFetchMenuConfig()
|
||||
private var mItemsToUpdate as Lang.Array<HomeAssistantToggleMenuItem or HomeAssistantTapMenuItem or HomeAssistantGroupMenuItem> or Null;
|
||||
private var mIsGlance as Lang.Boolean = false;
|
||||
private var mIsApp as Lang.Boolean = false; // Or Widget
|
||||
private var mUpdating as Lang.Boolean = false; // Don't start a second chain of updates
|
||||
private var mItemsToUpdate as Lang.Array<HomeAssistantToggleMenuItem or HomeAssistantTapMenuItem or HomeAssistantGroupMenuItem> or Null;
|
||||
private var mIsGlance as Lang.Boolean = false;
|
||||
private var mIsApp as Lang.Boolean = false; // Or Widget
|
||||
private var mUpdating as Lang.Boolean = false; // Don't start a second chain of updates
|
||||
private var mTemplates as Lang.Dictionary = {};
|
||||
|
||||
function initialize() {
|
||||
AppBase.initialize();
|
||||
@ -87,7 +88,7 @@ class HomeAssistantApp extends Application.AppBase {
|
||||
}
|
||||
|
||||
// Return the initial view of your application here
|
||||
function getInitialView() as Lang.Array<WatchUi.Views or WatchUi.InputDelegates>? {
|
||||
function getInitialView() as [ WatchUi.Views ] or [ WatchUi.Views, WatchUi.InputDelegates ] {
|
||||
mIsApp = true;
|
||||
mQuitTimer = new QuitTimer();
|
||||
mUpdateTimer = new Timer.Timer();
|
||||
@ -117,9 +118,9 @@ class HomeAssistantApp extends Application.AppBase {
|
||||
var isCached = fetchMenuConfig();
|
||||
fetchApiStatus();
|
||||
if (isCached) {
|
||||
return [mHaMenu, new HomeAssistantViewDelegate(true)] as Lang.Array<WatchUi.Views or WatchUi.InputDelegates>;
|
||||
return [mHaMenu, new HomeAssistantViewDelegate(true)];
|
||||
} else {
|
||||
return [new WatchUi.View(), new WatchUi.BehaviorDelegate()] as Lang.Array<WatchUi.Views or WatchUi.InputDelegates>;
|
||||
return [new WatchUi.View(), new WatchUi.BehaviorDelegate()];
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -260,7 +261,6 @@ class HomeAssistantApp extends Application.AppBase {
|
||||
mQuitTimer.begin();
|
||||
}
|
||||
|
||||
var mTemplates as Lang.Dictionary = {};
|
||||
function startUpdates() {
|
||||
if (mHaMenu != null and !mUpdating) {
|
||||
mItemsToUpdate = mHaMenu.getItemsToUpdate();
|
||||
@ -432,11 +432,7 @@ class HomeAssistantApp extends Application.AppBase {
|
||||
break;
|
||||
|
||||
case 200:
|
||||
var msg = null;
|
||||
if (data != null) {
|
||||
msg = data.get("message");
|
||||
}
|
||||
if (msg.equals("API running.")) {
|
||||
if ((data != null) && data.get("message").equals("API running.")) {
|
||||
mApiStatus = WatchUi.loadResource($.Rez.Strings.Available) as Lang.String;
|
||||
} else {
|
||||
if (!mIsGlance) {
|
||||
@ -530,7 +526,7 @@ class HomeAssistantApp extends Application.AppBase {
|
||||
return mQuitTimer;
|
||||
}
|
||||
|
||||
function getGlanceView() as Lang.Array<WatchUi.GlanceView or WatchUi.GlanceViewDelegate> or Null {
|
||||
function getGlanceView() as [ WatchUi.GlanceView ] or [ WatchUi.GlanceView, WatchUi.GlanceViewDelegate ] or Null {
|
||||
mIsGlance = true;
|
||||
mApiStatus = WatchUi.loadResource($.Rez.Strings.Checking) as Lang.String;
|
||||
mMenuStatus = WatchUi.loadResource($.Rez.Strings.Checking) as Lang.String;
|
||||
@ -555,7 +551,7 @@ class HomeAssistantApp extends Application.AppBase {
|
||||
|
||||
// Called each time the Registered Temporal Event is to be invoked. So the object is created each time on request and
|
||||
// then destroyed on completion (to save resources).
|
||||
function getServiceDelegate() as Lang.Array<System.ServiceDelegate> {
|
||||
function getServiceDelegate() as [ System.ServiceDelegate ] {
|
||||
return [new BackgroundServiceDelegate()];
|
||||
}
|
||||
|
||||
|
@ -73,7 +73,8 @@ class HomeAssistantView extends WatchUi.Menu2 {
|
||||
}
|
||||
}
|
||||
|
||||
function getItemsToUpdate() as Lang.Array<HomeAssistantToggleMenuItem or HomeAssistantTapMenuItem or HomeAssistantGroupMenuItem> {
|
||||
// Lang.Array.addAll() fails structural type checking without including "Null" in the return type
|
||||
function getItemsToUpdate() as Lang.Array<HomeAssistantToggleMenuItem or HomeAssistantTapMenuItem or HomeAssistantGroupMenuItem or Null> {
|
||||
var fullList = [];
|
||||
var lmi = mItems as Lang.Array<WatchUi.MenuItem>;
|
||||
|
||||
|
@ -181,7 +181,8 @@ class WebhookManager {
|
||||
// Webhook ID might have been deleted on Home Assistant server and a Lang.String is trying to tell us an error message
|
||||
Settings.unsetWebhookId();
|
||||
Settings.unsetIsSensorsLevelEnabled();
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.WebhookFailed) as Lang.String + "\n" + data.toString());
|
||||
// ErrorView.show(WatchUi.loadResource($.Rez.Strings.WebhookFailed) as Lang.String + "\n" + data.toString());
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.WebhookFailed) as Lang.String);
|
||||
}
|
||||
break;
|
||||
|
||||
@ -217,8 +218,7 @@ class WebhookManager {
|
||||
}
|
||||
|
||||
function registerWebhookSensors() {
|
||||
var activityInfo = ActivityMonitor.getInfo();
|
||||
var heartRate = Activity.getActivityInfo().currentHeartRate;
|
||||
var heartRate = Activity.getActivityInfo().currentHeartRate;
|
||||
|
||||
var sensors = [
|
||||
{
|
||||
@ -243,15 +243,6 @@ class WebhookManager {
|
||||
"entity_category" => "diagnostic",
|
||||
"disabled" => !Settings.isSensorsLevelEnabled()
|
||||
},
|
||||
{
|
||||
"name" => "Steps today",
|
||||
"state" => activityInfo.steps == null ? "unknown" : activityInfo.steps,
|
||||
"type" => "sensor",
|
||||
"unique_id" => "steps_today",
|
||||
"icon" => "mdi:walk",
|
||||
"state_class" => "total",
|
||||
"disabled" => !Settings.isSensorsLevelEnabled()
|
||||
},
|
||||
{
|
||||
"name" => "Heart rate",
|
||||
"state" => heartRate == null ? "unknown" : heartRate,
|
||||
@ -264,41 +255,57 @@ class WebhookManager {
|
||||
}
|
||||
];
|
||||
|
||||
if (ActivityMonitor.Info has :floorsClimbed) {
|
||||
if (Toybox has :ActivityMonitor) {
|
||||
System.println("WebhookManager registerWebhookSensors(): has ActivityMonitor class");
|
||||
var activityInfo = ActivityMonitor.getInfo();
|
||||
sensors.add({
|
||||
"name" => "Floors climbed today",
|
||||
"state" => activityInfo.floorsClimbed == null ? "unknown" : activityInfo.floorsClimbed,
|
||||
"name" => "Steps today",
|
||||
"state" => activityInfo.steps == null ? "unknown" : activityInfo.steps,
|
||||
"type" => "sensor",
|
||||
"unique_id" => "floors_climbed_today",
|
||||
"icon" => "mdi:stairs-up",
|
||||
"unique_id" => "steps_today",
|
||||
"icon" => "mdi:walk",
|
||||
"state_class" => "total",
|
||||
"disabled" => !Settings.isSensorsLevelEnabled()
|
||||
});
|
||||
}
|
||||
|
||||
if (ActivityMonitor.Info has :floorsDescended) {
|
||||
sensors.add({
|
||||
"name" => "Floors descended today",
|
||||
"state" => activityInfo.floorsDescended == null ? "unknown" : activityInfo.floorsDescended,
|
||||
"type" => "sensor",
|
||||
"unique_id" => "floors_descended_today",
|
||||
"icon" => "mdi:stairs-down",
|
||||
"state_class" => "total",
|
||||
"disabled" => !Settings.isSensorsLevelEnabled()
|
||||
});
|
||||
}
|
||||
if (ActivityMonitor.Info has :floorsClimbed) {
|
||||
sensors.add({
|
||||
"name" => "Floors climbed today",
|
||||
"state" => activityInfo.floorsClimbed == null ? "unknown" : activityInfo.floorsClimbed,
|
||||
"type" => "sensor",
|
||||
"unique_id" => "floors_climbed_today",
|
||||
"icon" => "mdi:stairs-up",
|
||||
"state_class" => "total",
|
||||
"disabled" => !Settings.isSensorsLevelEnabled()
|
||||
});
|
||||
}
|
||||
|
||||
if (ActivityMonitor.Info has :respirationRate) {
|
||||
sensors.add({
|
||||
"name" => "Respiration rate",
|
||||
"state" => activityInfo.respirationRate == null ? "unknown" : activityInfo.respirationRate,
|
||||
"type" => "sensor",
|
||||
"unique_id" => "respiration_rate",
|
||||
"icon" => "mdi:lungs",
|
||||
"unit_of_measurement" => "bpm",
|
||||
"state_class" => "measurement",
|
||||
"disabled" => !Settings.isSensorsLevelEnabled()
|
||||
});
|
||||
if (ActivityMonitor.Info has :floorsDescended) {
|
||||
sensors.add({
|
||||
"name" => "Floors descended today",
|
||||
"state" => activityInfo.floorsDescended == null ? "unknown" : activityInfo.floorsDescended,
|
||||
"type" => "sensor",
|
||||
"unique_id" => "floors_descended_today",
|
||||
"icon" => "mdi:stairs-down",
|
||||
"state_class" => "total",
|
||||
"disabled" => !Settings.isSensorsLevelEnabled()
|
||||
});
|
||||
}
|
||||
|
||||
if (ActivityMonitor.Info has :respirationRate) {
|
||||
sensors.add({
|
||||
"name" => "Respiration rate",
|
||||
"state" => activityInfo.respirationRate == null ? "unknown" : activityInfo.respirationRate,
|
||||
"type" => "sensor",
|
||||
"unique_id" => "respiration_rate",
|
||||
"icon" => "mdi:lungs",
|
||||
"unit_of_measurement" => "bpm",
|
||||
"state_class" => "measurement",
|
||||
"disabled" => !Settings.isSensorsLevelEnabled()
|
||||
});
|
||||
}
|
||||
} else {
|
||||
System.println("WebhookManager registerWebhookSensors(): has no ActivityMonitor class");
|
||||
}
|
||||
|
||||
if (Activity has :getProfileInfo) {
|
||||
|
Reference in New Issue
Block a user