Skip to content

Commit

Permalink
Initial fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
philipabbey committed Mar 7, 2024
1 parent 181335b commit 92d3fbe
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 4 deletions.
5 changes: 5 additions & 0 deletions resources/settings/properties.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@
-->
<property id="clear_cache" type="boolean">false</property>

<!--
Enable notification via vibrations, typically for confirmation of actions
-->
<property id="enable_vibration" type="boolean">true</property>

<!--
Application timeout in seconds, except 0 for no
timeout (default). After this amount of elapsed
Expand Down
7 changes: 7 additions & 0 deletions resources/settings/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@
<settingConfig type="boolean" />
</setting>

<setting
propertyKey="@Properties.enable_vibration"
title="@Strings.SettingsVibration"
>
<settingConfig type="boolean" />
</setting>

<setting
propertyKey="@Properties.app_timeout"
title="@Strings.SettingsAppTimeout"
Expand Down
1 change: 1 addition & 0 deletions resources/strings/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
<string id="SettingsConfigUrl">URL for menu configuration (JSON).</string>
<string id="SettingsCacheConfig">Should the application cache the menu configuration?</string>
<string id="SettingsClearCache">Should the application clear the existing cache next time it is started?</string>
<string id="SettingsVibration">Should the application provide feedback via vibrations?</string>
<string id="SettingsAppTimeout">Timeout in seconds. Exit the application after this period of inactivity to save the device battery.</string>
<string id="SettingsConfirmTimeout">After this time (in seconds), a confirmation dialog for an action is automatically closed and the action is cancelled. Set to 0 to disable the timeout.</string>
<string id="SettingsTextAlign">Left (off) or Right (on) Menu Alignment.</string>
Expand Down
11 changes: 7 additions & 4 deletions source/HomeAssistantService.mc
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,12 @@ class HomeAssistantService {
// System.println("HomeAssistantService call() URL=" + url);
// System.println("HomeAssistantService call() service=" + service);

var entity_id = data.get("entity_id");
if (entity_id == null) {
entity_id = "";
var entity_id = "";
if (data != null) {
entity_id = data.get("entity_id");
if (entity_id == null) {
entity_id = "";
}
}

Communications.makeWebRequest(
Expand All @@ -141,7 +144,7 @@ class HomeAssistantService {
},
method(:onReturnCall)
);
if (mHasVibrate) {
if (mHasVibrate and Settings.getVibrate()) {
Attention.vibrate([
new Attention.VibeProfile(50, 100), // On for 100ms
new Attention.VibeProfile( 0, 100), // Off for 100ms
Expand Down
6 changes: 6 additions & 0 deletions source/Settings.mc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class Settings {
private static var mConfigUrl as Lang.String = "";
private static var mCacheConfig as Lang.Boolean = false;
private static var mClearCache as Lang.Boolean = false;
private static var mVibrate as Lang.Boolean = false;
private static var mAppTimeout as Lang.Number = 0; // seconds
private static var mConfirmTimeout as Lang.Number = 3; // seconds
private static var mMenuAlignment as Lang.Number = WatchUi.MenuItem.MENU_ITEM_LABEL_ALIGN_LEFT;
Expand All @@ -54,6 +55,7 @@ class Settings {
mConfigUrl = Properties.getValue("config_url");
mCacheConfig = Properties.getValue("cache_config");
mClearCache = Properties.getValue("clear_cache");
mVibrate = Properties.getValue("enable_vibration");
mAppTimeout = Properties.getValue("app_timeout");
mConfirmTimeout = Properties.getValue("confirm_timeout");
mMenuAlignment = Properties.getValue("menu_alignment");
Expand Down Expand Up @@ -130,6 +132,10 @@ class Settings {
Properties.setValue("clear_cache", mClearCache);
}

static function getVibrate() as Lang.Boolean {
return mVibrate;
}

static function getAppTimeout() as Lang.Number {
return mAppTimeout * 1000; // Convert to milliseconds
}
Expand Down

0 comments on commit 92d3fbe

Please sign in to comment.