Compare commits
7 Commits
v3.10
...
6721a13e99
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6721a13e99 | ||
|
|
b6cec5a6d4 | ||
|
|
75ccf7dc01 | ||
|
|
6596b5fa5d | ||
|
|
b94343de4f | ||
|
|
cc2fc27532 | ||
|
|
188fb8feff |
@@ -22,7 +22,7 @@ Thank you to all those who have provided positive feedback, code and language tr
|
||||
|
||||
> [!IMPORTANT]
|
||||
> **The intended audience for this application are those comfortable with configuring a HomeAssistant** (e.g. editing the YAML configuration files) and debugging why URLs don't work. It does not require programming skills, but the menu is configured via JSON which feels like "coding" (more like "describing"). If you are not comfortable with this relatively low level of configuration, you may like to try other Garmin applications instead.
|
||||
|
||||
>
|
||||
> [!IMPORTANT]
|
||||
> Remember, you are expecting to define a customised menu making use of several options using your Home Assistant's custom entities on a small (portable) device. **There is no "_simple_" way to configure the menu with the ever increasing options demanded by the user community.** Was your Home Assistant trivial to setup? No!
|
||||
>
|
||||
@@ -392,9 +392,8 @@ Two words. Perhaps too lazy to consider why others gave rave reviews and ponder
|
||||
|
||||
<img src="images/etiquette/2026-01-21 GHA_Bad_Review.png" width="70%" title="Two words">
|
||||
|
||||
<hr>
|
||||
---
|
||||
|
||||
Blaming the wrong application. Just rude. Please get your facts straight. And it was such a simple workaround for the Garmin Connect IQ app bug.
|
||||
|
||||
<img src="images/etiquette/2025-11-19%20GHA_Bad_Review.png" width="85%" title="Misplaced blame">
|
||||
s
|
||||
@@ -42,7 +42,7 @@
|
||||
| 2.27 | Trivial bug fix for the glance view to prevent the "Unconfigured" result being erroneously displayed because the settings were not yet pulled from persistent storage. |
|
||||
| 2.28 | Added support for Vivoactive 6 device which also required an SDK update to 8.1.0. |
|
||||
| 2.29 | Added support for three new devices, Forerunners 570 42mm & 47mm and 970. |
|
||||
| 2.30 | <img src="images/Venu2_glance_default.png" width="200" title="Default Glance"/><br/>Extensive re-work of the [Glance](examples/Glance.md) view, including the ability to customise it with a user supplied template. |
|
||||
| 2.30 | <img src="images/Venu2_glance2.png" width="200" title="Default Glance"/><br/>Extensive re-work of the [Glance](examples/Glance.md) view, including the ability to customise it with a user supplied template. |
|
||||
| 2.31 | Adding [two new options](./examples/Actions.md#exit-on-tap) to the menu items: 1) The ability to disable a menu item, e.g. temporarily for seasonal changes, 2) The option to exit after a menu item has been select. |
|
||||
| 2.32 | Bug fix for a breaking change extracting options caused by the need to rearrange function parameters for an [annoying compiler error](https://github.com/house-of-abbey/GarminHomeAssistant/issues/253). |
|
||||
| 3.0 | First version with the ability to use [Wi-Fi or LTE](Wi-Fi.md) instead of Bluetooth but with limited functionality, thanks to [@vincentezw](https://github.com/vincentezw). |
|
||||
@@ -55,4 +55,5 @@
|
||||
| 3.7 | Bug fix for `numeric` menu items not working over Wi-Fi & LTE. |
|
||||
| 3.8 | Added icon for `numeric` menu items and revised icons in general. |
|
||||
| 3.9 | Small update to warn users with empty menu definitions to read the instructions! |
|
||||
| 3.10 | Bug avoidance for a fatal "out of memory error" in the glance when caching the menu to [`Storage`](https://developer.garmin.com/connect-iq/api-docs/Toybox/Application/Storage.html). This is now delayed until the main application is opened. Added support for two new devices, D2 Mach 2 and eTrex Touch. |
|
||||
| 3.10 | Bug avoidance for a fatal _"Error: Out Of Memory Error"_ in the glance when caching the menu to [`Storage`](https://developer.garmin.com/connect-iq/api-docs/Toybox/Application/Storage.html). This is now delayed until the main application is opened. Added support for two new devices, D2 Mach 2 and eTrex Touch. |
|
||||
| 3.11 | <img src="images/Venu2_glance_default.png" width="200" title="Default Glance"/><br/>Better handling of menus larger than the Glance view can handle. As a result the Glance can no longer verify the availability of the JSON menu as fetching it might cause an _"Error: Out Of Memory Error"_. |
|
||||
|
||||
@@ -11,6 +11,7 @@ The application is designed around a simple scrollable menu where menu items hav
|
||||
**The intended audience for this application are those comfortable with configuring a HomeAssistant** (e.g. editing the YAML configuration files) and debugging why URLs don't work. It does not require programming skills, but the menu is configured via JSON which feels like "coding" (more like "describing"). If you are not comfortable with this relatively low level of configuration, you may like to try other Garmin applications instead.
|
||||
|
||||
**If you are struggling with getting the application to work, please consult the [troubleshooting guide](TroubleShooting.md) first.** Please also be aware of the [etiquette](Etiquette.md) the developers expect before:
|
||||
|
||||
1. Reaching out for help, in short read the instructions.
|
||||
2. Reviewing the application publicly, in short be sure of your claims.
|
||||
|
||||
@@ -33,7 +34,7 @@ As of version 2.0, there are now two installable versions. For older devices bef
|
||||
|
||||
| Version | Explanation |
|
||||
|------------------------|-------------|
|
||||
| Application (original) | For newer devices that allow glance views in their applications, e.g. Venu 2, the GarminHomeAssistant application can be started either from a glance or from the list of applications and activities. Head over to the [GarminHomeAssistant](https://apps.garmin.com/en-US/apps/61c91d28-ec5e-438d-9f83-39e9f45b199d) application page on the [Connect IQ application store](https://apps.garmin.com/en-US/) to download the application. The application can be started two different ways, either from the glance in the carousel, or as an application from the list of applications & activities. With the latter, it is worth marking the application as a favourite.<br/><img src="images/Venu2_app_start.png" width="200" title="Venu 2" style="margin:5px"/><img src="images/Vivoactive3_app_start.jpg" width="200" title="Vivoactive 3" style="margin:5px"/><br/>If you place the application on your list of favourites, and rearrange it to appear near the top, then the item is just one button press away from the watch face. This second picture here shows the application menu on a Vivoactive 3 watch.<br/><img src="images/Venu2_glance_default.png" width="200" title="Venu 2" style="margin:5px"/><br/>On newer watches, you can also start the application from the glance carousel. The glance view here typically displays some trackable status, so ours provides some early indication of availability. Older watches will still allow you to start this application from the list of applications and activities. |
|
||||
| Application (original) | For newer devices that allow glance views in their applications, e.g. Venu 2, the GarminHomeAssistant application can be started either from a glance or from the list of applications and activities. Head over to the [GarminHomeAssistant](https://apps.garmin.com/en-US/apps/61c91d28-ec5e-438d-9f83-39e9f45b199d) application page on the [Connect IQ application store](https://apps.garmin.com/en-US/) to download the application. The application can be started two different ways, either from the glance in the carousel, or as an application from the list of applications & activities. With the latter, it is worth marking the application as a favourite.<br/><img src="images/Venu2_app_start.png" width="200" title="Venu 2" style="margin:5px"/><img src="images/Vivoactive3_app_start.jpg" width="200" title="Vivoactive 3" style="margin:5px"/><br/>If you place the application on your list of favourites, and rearrange it to appear near the top, then the item is just one button press away from the watch face. This second picture here shows the application menu on a Vivoactive 3 watch.<br/><img src="./images/Venu2_glance_custom.png" width="200" title="Venu 2" style="margin:5px"/><br/>On newer watches, you can also start the application from the glance carousel. The glance view here typically displays some trackable status, so ours provides some early indication of API availability or something custom as shown here. Older watches will still allow you to start this application from the list of applications and activities. |
|
||||
| Widget | **"Maintenance only mode"** so no new features will be added to this version.<br>For older devices that use widgets, e.g. Venu (1) as opposed to applications with "glances", the GarminHomeAssistant application can instead be started from the widget carousel. This is a separate item in the Connect IQ AppStore and with this installation, the application will no longer appear in the list of applications and activities. Head over to the [GarminHomeAssistant](https://apps.garmin.com/en-US/apps/) widget page on the [Connect IQ application store](https://apps.garmin.com/en-US/) to download the widget.<br/><img src="images/Venu_Widget_sim.png" width="200" title="Venu 2" style="margin:5px"/><br/>Typically the widget view implements something similar to the glance view, e.g. status, and exists in a widget carousel to allow you to select an application to launch.<br>**Please note that memory in widgets is more limited than applications. This means a large menu definition can crash the widget without the code catching the error.**<br> This version was born out of the application version and from Ver 2.0 shared the same source code repository until Ver 2.8 when they were [separated](https://github.com/house-of-abbey/GarminHomeAssistantWidget) to allow the application version to take advantage of its increase memory availability. |
|
||||
|
||||
### Features
|
||||
@@ -62,6 +63,7 @@ The following table lists the differences in functionality between the two. The
|
||||
> Remember, you are expecting to define a customised menu making use of several options using your Home Assistant's custom entities on a small (portable) device. **There is no "_simple_" way to configure the menu with the ever increasing options demanded by the user community.** Was your Home Assistant trivial to setup? No!
|
||||
>
|
||||
> Therefore as developers we have two options:
|
||||
>
|
||||
> 1. Assistance via menu driven configuration with nested menus on a small screen whose implementation would expand the code beyond the capacity of smaller devices, or
|
||||
> 2. As we have opted here, for assistance via some external configuration that is driven by code and can be authored using a more fully functional desktop or laptop PC.
|
||||
>
|
||||
@@ -314,6 +316,7 @@ A future move to v3.x will remove support for all deprecated JSON elements to si
|
||||
## Editing the JSON file
|
||||
|
||||
You have options. The first is what we use.
|
||||
|
||||
1. **Best!** Use the GarminHomeAssistant [Web-based Editor](https://house-of-abbey.github.io/GarminHomeAssistant/web/) which includes `entity` and `action` name completion and validation by fetching data from your own HomeAssistant instance. _Pretty nifty eh?_ The other method listed below do not add this convenience and checking. NB. This has been tested in Microsoft Edge, Chrome and Firefox.
|
||||
2. Use the [Studio Code Server](https://community.home-assistant.io/t/home-assistant-community-add-on-visual-studio-code/107863) addon for HomeAssistant. You can then edit your JSON file in place.
|
||||
3. Locally installed VSCode, or if not installed, try
|
||||
@@ -369,6 +372,7 @@ You may choose to cache your menu definition on your device in order to reduce t
|
||||
**Summary:** The two cache options are therefore distinct, the **first is a manual** forced refresh (the old way). The menu is refreshed on start up and no restart is required. The **second enables automatic checking** after starting and after presenting a usable menu with no extra delay but then any detected changes require a restart.
|
||||
|
||||
Whilst it would be a smoother experience, there are no plans to make the menu definition update dynamically recreate the rendered menu items without a restart because:
|
||||
|
||||
1. Re-rendering the menu could change the selected item just as you action it.
|
||||
2. V3.3 proved that older devices are now reaching their memory limits. If you have an old device with limited memory to spare you will probably find the App disables the automatic method for you. If your device crashes with this option turned on, best turn it off manually and let me know via a [Github issue](https://github.com/house-of-abbey/GarminHomeAssistant/issues). This will allow us to fine tune the conditions for insufficient memory. We will then ask you to perform a [small task to retrieve the debug information](https://developer.garmin.com/connect-iq/core-topics/debugging/) we need about memory usage.
|
||||
3. Restarting is simple for the user and simpler for the code.
|
||||
|
||||
@@ -117,6 +117,7 @@ pause
|
||||
#### API: On-line
|
||||
|
||||
There's an online way of testing the API URL too, thanks to [REQBIN](https://reqbin.com/post-online). This has less setup and it can be saved if you log into the web site. Please note two things:
|
||||
|
||||
1. The URL entere below must include a trailing '/' unlike the URL entered into the watch settings.
|
||||
2. The service imposes a limit on the number requests you can submit without a subscription, so click with purpose! NB. Changing browser buys you a few more clicks.
|
||||
|
||||
@@ -125,13 +126,10 @@ There's an online way of testing the API URL too, thanks to [REQBIN](https://req
|
||||
#### SSL Certificate Chain
|
||||
|
||||
With thanks to [@ziceva](https://github.com/ziceva) for solving this problem. The symptoms are:
|
||||
|
||||
1. Using an API URL with SSL (HTTPS), the [web-based editor](https://house-of-abbey.github.io/GarminHomeAssistant/web/) running in a browser on the same phone running Garmin Connect works well.
|
||||
2. The exact same configuration is set in the Garmin HomeAssistant application.
|
||||
3. The Garmin HomeAssistant application reports:
|
||||
```
|
||||
API: not available
|
||||
Menu: not available
|
||||
```
|
||||
3. The Garmin HomeAssistant application reports neither the API nor the menu are available.
|
||||
|
||||
**Solution: Make sure you use a _full chain_ certificate in your HTTPS proxy as some watches might be unable to validate the site certificate alone.**
|
||||
|
||||
@@ -147,7 +145,6 @@ To verify if you have this issue you can use a tool like [SSL Shoppers's SSL Che
|
||||
|
||||

|
||||
|
||||
|
||||
### Top Problems
|
||||
|
||||
1. Failure to copy & paste keys and URLs leading to minor and hard to see errors in strings, even with protestations they are the same! (No they weren't...)
|
||||
@@ -158,17 +155,11 @@ To verify if you have this issue you can use a tool like [SSL Shoppers's SSL Che
|
||||
The [editor](https://house-of-abbey.github.io/GarminHomeAssistant/web/) provides the following functions:
|
||||
|
||||
1. Syntax highlighting
|
||||
|
||||
2. Schema checking
|
||||
|
||||

|
||||
|
||||
3. Entity name completion
|
||||
|
||||

|
||||
|
||||
4. Rendering previews, to aid HA 'template' creation
|
||||
|
||||

|
||||

|
||||
|
||||
@@ -185,6 +176,7 @@ On (1) you will initially be presented with the following message. Please do not
|
||||
<div style="margin:30px;padding:20px;background-color:lightgrey;border:1px solid black;border-radius: 10px;">
|
||||
|
||||
# GarminHomeAssistant Web Editor
|
||||
|
||||
This is the web editor for the GarminHomeAssistant watch app, it offers enhanced schema checking and validation over the original JSON schema by using the HomeAssistant API to create a schema based on your HomeAssistant configuration.
|
||||
|
||||
This editor makes use of the same credentials as the watch app (these can be pasted in the top bar of this page). However in order for this editor to work, you will need to amend the CORS settings of your HomeAssistant instance. Add this to your configuration.yaml file:
|
||||
@@ -215,7 +207,7 @@ For directions on how to write your menu.json file, please see the README in the
|
||||
|
||||
For this you will need to have already got the main application or widget working with a menu in order to prove that the API calls are successful. We have proven this works with both our home brew infrastructure as well as Nabu Casa. Now with a script similar to one of the following two, you should be able to fake the watch API call and verify receipt by HomeAssistant.
|
||||
|
||||
#### Battery: Linux, MacOS, UNIX, Cygwin etc
|
||||
### Battery: Linux, MacOS, UNIX, Cygwin etc
|
||||
|
||||
Assume a file called: `send_battery.bash`
|
||||
|
||||
@@ -248,13 +240,13 @@ curl -s -X POST \
|
||||
|
||||
Execute:
|
||||
|
||||
```
|
||||
```text
|
||||
$ ./send_battery.bash 45 1
|
||||
```
|
||||
|
||||
The output looks like this:
|
||||
|
||||
```
|
||||
```text
|
||||
Battery Level = 45
|
||||
Battery Charging? = true
|
||||
|
||||
@@ -315,13 +307,13 @@ pause
|
||||
|
||||
Execute:
|
||||
|
||||
```
|
||||
```text
|
||||
> home_assistant_battery_level.cmd 41 1
|
||||
```
|
||||
|
||||
The output looks like this:
|
||||
|
||||
```
|
||||
```text
|
||||
"Battery Level = 41"
|
||||
"Battery Charging? = true"
|
||||
|
||||
@@ -345,7 +337,7 @@ There's an online way of testing the API URL too, thanks to [REQBIN](https://req
|
||||
|
||||
URL for copy & paste:
|
||||
|
||||
```
|
||||
```text
|
||||
https://<Your Domain>/api/webhook/<Your Webhook ID>
|
||||
```
|
||||
|
||||
@@ -399,7 +391,7 @@ As a desperate measure to assist with debugging the HomeAssistant Application, y
|
||||
|
||||
The figure above shows how to find the file on Windows by attaching your watch by USB cable. Inside the `CIQ_LOG.YML` file there are often multiple entries, each looking like this:
|
||||
|
||||
```
|
||||
```text
|
||||
Error: Unexpected Type Error
|
||||
Details: 'Failed invoking <symbol>'
|
||||
Time: 2024-08-30T12:00:25Z
|
||||
|
||||
2
Wi-Fi.md
@@ -18,7 +18,7 @@ With version 3.0 onwards the application now includes the ability to temporarily
|
||||
|
||||
5. On some Garmin devices, the HTTPS handshake is performed using **TLS 1.2**. If your server or proxy enforces a higher minimum (e.g., TLS 1.3), you will encounter an SSL handshake error with the message:
|
||||
|
||||
```
|
||||
```text
|
||||
HTTP request returned error code = 0
|
||||
```
|
||||
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
[Home](../README.md) | [Switches](Switches.md) | [Actions](Actions.md) | [Templates](Templates.md) | [Numeric](Numeric.md) | [Glance](Glance.md) | [Background Service](../BackgroundService.md) | [Wi-Fi](../Wi-Fi.md) | [HTTP Headers](../HTTP_Headers.md) | [Trouble Shooting](../TroubleShooting.md) | [Version History](../HISTORY.md)
|
||||
|
||||
|
||||
# Actions
|
||||
|
||||
A simple example using a scene as a `tap` menu item.
|
||||
Two simple examples using a scene and a cover as `tap` menu items.
|
||||
|
||||
```json
|
||||
{
|
||||
@@ -14,6 +13,16 @@ A simple example using a scene as a `tap` menu item.
|
||||
"action": "scene.turn_on"
|
||||
}
|
||||
},
|
||||
{
|
||||
"entity":"cover.patio_shutter",
|
||||
"name":"Patio Door Shutter",
|
||||
"type":"tap",
|
||||
"content":"{{state_translated('cover.patio_shutter')}} - {{state_attr('cover.patio_shutter', 'current_position')}}",
|
||||
"tap_action":{
|
||||
"action":"cover.toggle",
|
||||
"confirm":true
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Any menu item with an action (`tap`, `template`, or `toggle`), may have a confirmation view added. For consistency this is always done via the `tap_action` JSON object, even though for a `toggle` menu item there will only ever be a single field inside. For the `toggle` menu item, the confirmation is presented on both `on` and `off` directions. There is no option for asymmetry, i.e. only in one direction.
|
||||
@@ -30,15 +39,15 @@ For example:
|
||||
|
||||
```json
|
||||
{
|
||||
"entity": "switch.garage_door",
|
||||
"name": "Garage Door",
|
||||
"entity": "switch.flood_lights",
|
||||
"name": "Flood Lights",
|
||||
"type": "toggle",
|
||||
"tap_action": {
|
||||
"confirm": true
|
||||
}
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
The `confirm` field may contain a string instead of a Boolean in order to provide a custom message to display instead of the default "Sure?" text.
|
||||
|
||||
```json
|
||||
|
||||
@@ -2,17 +2,15 @@
|
||||
|
||||
# Glance
|
||||
|
||||
Since [version 2.30](../History.md), it is possible to ovverride the text displayed on the Glance view. This page explains how to customise the text.
|
||||
Since [version 2.30](../History.md), it is possible to override the text displayed on the Glance view. This page explains how to customise the text.
|
||||
|
||||
## Status View
|
||||
|
||||
## Default View
|
||||
|
||||
The default view has always been to display the status of the menu and API availability to indicate if there's a problem. This view has now been updated to be more colourful.
|
||||
The status view displays the accessibility of HomeAssistant API to indicate if there's a problem.
|
||||
|
||||
<img src="../images/Venu2_glance_default.png" width="200" title="Venu 2 Default Glance"/>
|
||||
|
||||
When either the API or the menu file is inaccessible, the fields will turn red.
|
||||
|
||||
When API is inaccessible the field will turn red.
|
||||
|
||||
## Customised View
|
||||
|
||||
@@ -45,9 +43,9 @@ For example:
|
||||
}
|
||||
```
|
||||
|
||||
You may make this as complicated as you like! But you have limited space and only ASCII text characters. **It is best to turn on menu caching in order to speed up the display of the template**. The display is then nearly instantaneous.
|
||||
The 'status' view will persist showing until the API becomes available as without the API the custom template cannot be evaluated.
|
||||
|
||||
The default view will persist showing until the errors are resolved. In order to extract the custom glance template both the menu and the API are required. So it is logical that the two tests must pass first. The exception here is if the menu is cached, in which case only the API needs to pass.
|
||||
You may make this as complicated as you like! But you have limited space and only ASCII text characters. **It is essential to turn on menu caching in order to display of the template**. This is a change in v3.11 where multiple users are now making larger JSON menus than was originally envisaged for this watch application. As a result the Glance view would fail with an untrapable (fatal) _"Error: Out Of Memory Error"_. A work around is to pull out the glance subsection of the menu and cache that separately during execution of the full application, but that means any changes to the customised Glance view do not show until after the full application has been run.
|
||||
|
||||
> [!IMPORTANT]
|
||||
> Sadly what you cannot do is use special characters like: 🌞🔋⛅🪫. Whilst these do display in menu items, they do not seem to work on the Glance view. We really like them, so have tried but failed. Only ASCII text appears to be supported by the Garmin Connect IQ SDK's Glance View. This is not something we have any control over, please do not request this to be "fixed".
|
||||
@@ -68,13 +66,12 @@ It is possible to revert to the default glance content without deleting the temp
|
||||
|
||||
So the glance view object has a `type` field with two possible values: `info` and `status`. When the type is `status` the `content` field is not required.
|
||||
|
||||
|
||||
## Displayed Errors
|
||||
|
||||
The following shows the default glance when the menu file is not available at the specified URL.
|
||||
The following shows the status Glance view when the API not available at the specified URL.
|
||||
|
||||
<img src="../images/Venu2_glance_no_menu.png" width="200" title="Venu 2 Glance showing errors"/>
|
||||
<img src="../images/Venu2_glance_no_api.png" width="200" title="Venu 2 Glance showing errors"/>
|
||||
|
||||
Once the custom glance template has been retrieved and evaluated the display will change. Should the connectivity to your HomeAssistant then be lost, e.g. you move out of range of your phone, the glance reflects this in the colour of the residual two rectangles. The top one remains an indicator for the API, and the bottom rectangle remains an indicator for the menu availability, reflecting the original placement in the default glance view that has now been replaced.
|
||||
It is possible to loose connectivity with your HomeAssistant API after connecting and evaluating the Glance template. When the API connection is re-established, the Glance view will update.
|
||||
|
||||
<img src="../images/Venu2_glance_no_bt.png" width="200" title="Venu 2 Glance showing lost connectivity"/>
|
||||
|
||||
|
Before Width: | Height: | Size: 17 KiB |
BIN
images/Venu2_glance2.png
Normal file
|
After Width: | Height: | Size: 8.7 KiB |
|
Before Width: | Height: | Size: 8.3 KiB After Width: | Height: | Size: 9.6 KiB |
|
Before Width: | Height: | Size: 8.7 KiB After Width: | Height: | Size: 8.2 KiB |
BIN
images/Venu2_glance_no_api.png
Normal file
|
After Width: | Height: | Size: 8.3 KiB |
|
Before Width: | Height: | Size: 8.2 KiB After Width: | Height: | Size: 9.6 KiB |
|
Before Width: | Height: | Size: 8.8 KiB |
@@ -28,10 +28,10 @@ using Toybox.Timer;
|
||||
(:glance, :background)
|
||||
class HomeAssistantApp extends Application.AppBase {
|
||||
static const scStorageKeyMenu as Lang.String = "menu";
|
||||
static const scStorageKeyGlance as Lang.String = "glance";
|
||||
|
||||
private var mHasToast as Lang.Boolean = false;
|
||||
private var mApiStatus as Lang.String?;
|
||||
private var mMenuStatus as Lang.String?;
|
||||
private var mHaMenu as HomeAssistantView?;
|
||||
private var mGlanceTemplate as Lang.String? = null;
|
||||
private var mGlanceText as Lang.String? = null;
|
||||
@@ -111,7 +111,6 @@ class HomeAssistantApp extends Application.AppBase {
|
||||
mQuitTimer = new QuitTimer();
|
||||
mUpdateTimer = new Timer.Timer();
|
||||
mApiStatus = WatchUi.loadResource($.Rez.Strings.Checking) as Lang.String;
|
||||
mMenuStatus = WatchUi.loadResource($.Rez.Strings.Checking) as Lang.String;
|
||||
mHasToast = WatchUi has :showToast;
|
||||
Settings.update();
|
||||
|
||||
@@ -166,7 +165,6 @@ class HomeAssistantApp extends Application.AppBase {
|
||||
// System.println("HomeAssistantApp onReturnFetchMenuConfig() Response Code: " + responseCode);
|
||||
// System.println("HomeAssistantApp onReturnFetchMenuConfig() Response Data: " + data);
|
||||
|
||||
mMenuStatus = WatchUi.loadResource($.Rez.Strings.Unavailable) as Lang.String;
|
||||
switch (responseCode) {
|
||||
case Communications.BLE_HOST_TIMEOUT:
|
||||
case Communications.BLE_CONNECTION_UNAVAILABLE:
|
||||
@@ -205,12 +203,8 @@ class HomeAssistantApp extends Application.AppBase {
|
||||
break;
|
||||
|
||||
case 200:
|
||||
if (data == null) {
|
||||
mMenuStatus = WatchUi.loadResource($.Rez.Strings.Unavailable) as Lang.String;
|
||||
} else {
|
||||
if (hasCachedMenu()) {
|
||||
mMenuStatus = WatchUi.loadResource($.Rez.Strings.Cached) as Lang.String;
|
||||
} else if (mIsApp) {
|
||||
if (data != null) {
|
||||
if (mIsApp) {
|
||||
// var stats = System.getSystemStats(); // stats.* values in bytes
|
||||
// System.println("HomeAssistantApp onReturnFetchMenuConfig() Memory: total=" + stats.totalMemory + ", used=" + stats.usedMemory + ", free=" + stats.freeMemory);
|
||||
|
||||
@@ -219,14 +213,14 @@ class HomeAssistantApp extends Application.AppBase {
|
||||
// "Keys and values are limited to 8 KB each, and a total of 128 KB of storage is available."
|
||||
// "Storage.setValue() fails with an uncatchable out-of-memory error."
|
||||
Storage.setValue(scStorageKeyMenu, data as Lang.Dictionary);
|
||||
mMenuStatus = WatchUi.loadResource($.Rez.Strings.Cached) as Lang.String;
|
||||
} else {
|
||||
mMenuStatus = WatchUi.loadResource($.Rez.Strings.Available) as Lang.String;
|
||||
// Store the smaller glance section of the menu separately so the Glance view can retrieve it within memory limits.
|
||||
var glance = (data as Lang.Dictionary)["glance"];
|
||||
if (glance != null) {
|
||||
Storage.setValue(scStorageKeyGlance, glance as Lang.Dictionary);
|
||||
}
|
||||
}
|
||||
if (!mIsApp) {
|
||||
glanceTemplate(data);
|
||||
} else {
|
||||
}
|
||||
if (mIsApp) {
|
||||
if (data == null) {
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.NoJson) as Lang.String);
|
||||
} else if (data.size() == 0) {
|
||||
@@ -268,13 +262,13 @@ class HomeAssistantApp extends Application.AppBase {
|
||||
function fetchMenuConfig() as Lang.Boolean {
|
||||
// System.println("Menu URL = " + Settings.getConfigUrl());
|
||||
if (Settings.getConfigUrl().equals("")) {
|
||||
mMenuStatus = WatchUi.loadResource($.Rez.Strings.Unconfigured) as Lang.String;
|
||||
WatchUi.requestUpdate();
|
||||
} else {
|
||||
var menu = Storage.getValue(scStorageKeyMenu) as Lang.Dictionary;
|
||||
if (menu != null and (Settings.getClearCache() || !Settings.getCacheConfig())) {
|
||||
// System.println("HomeAssistantApp fetchMenuConfig(): Clearing cached menu on user request.");
|
||||
Storage.deleteValue(scStorageKeyMenu);
|
||||
Storage.deleteValue(scStorageKeyGlance);
|
||||
menu = null;
|
||||
Settings.unsetClearCache();
|
||||
}
|
||||
@@ -282,13 +276,8 @@ class HomeAssistantApp extends Application.AppBase {
|
||||
// System.println("HomeAssistantApp fetchMenuConfig(): Menu not cached, fetching.");
|
||||
fetchMenuConfigBasic(method(:onReturnFetchMenuConfig));
|
||||
} else {
|
||||
mMenuStatus = WatchUi.loadResource($.Rez.Strings.Cached) as Lang.String;
|
||||
WatchUi.requestUpdate();
|
||||
if (!mIsApp) {
|
||||
glanceTemplate(menu);
|
||||
} else {
|
||||
buildMenu(menu);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -329,7 +318,6 @@ class HomeAssistantApp extends Application.AppBase {
|
||||
} else {
|
||||
ErrorView.show(WatchUi.loadResource(errorRez) as Lang.String);
|
||||
}
|
||||
mMenuStatus = WatchUi.loadResource(errorRez) as Lang.String;
|
||||
} else {
|
||||
Communications.makeWebRequest(
|
||||
Settings.getConfigUrl(),
|
||||
@@ -368,10 +356,9 @@ class HomeAssistantApp extends Application.AppBase {
|
||||
|
||||
//! Extract the optional template to override the default glance view.
|
||||
//
|
||||
function glanceTemplate(menu as Lang.Dictionary) {
|
||||
if (menu != null) {
|
||||
if (menu["glance"] != null) {
|
||||
var glance = menu["glance"] as Lang.Dictionary;
|
||||
function glanceTemplate() {
|
||||
var glance = Storage.getValue(scStorageKeyGlance) as Lang.Dictionary;
|
||||
if ((glance != null) && (glance["type"] != null)) {
|
||||
if (glance["type"].equals("info")) {
|
||||
mGlanceTemplate = glance["content"] as Lang.String;
|
||||
// System.println("HomeAssistantApp glanceTemplate() " + mGlanceTemplate);
|
||||
@@ -380,7 +367,6 @@ class HomeAssistantApp extends Application.AppBase {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//! Test if two dictionaries are structurally equal. Used to see if the JSON menu has been
|
||||
//! amended but yet to be updated in the application cache.
|
||||
@@ -539,6 +525,11 @@ class HomeAssistantApp extends Application.AppBase {
|
||||
if (menu == null || !structuralEquals(data, menu)) {
|
||||
// System.println("HomeAssistantApp onReturnCheckMenuConfig() New menu found.");
|
||||
Storage.setValue(scStorageKeyMenu, data as Lang.Dictionary);
|
||||
// Store the smaller glance section of the menu separately so the Glance view can retrieve it within memory limits.
|
||||
var glance = (data as Lang.Dictionary)["glance"];
|
||||
if (glance != null) {
|
||||
Storage.setValue(scStorageKeyGlance, glance as Lang.Dictionary);
|
||||
}
|
||||
if (menu != null) {
|
||||
// Notify the the user we have just got a newer menu file
|
||||
var toast = WatchUi.loadResource($.Rez.Strings.MenuUpdated) as Lang.String;
|
||||
@@ -897,51 +888,18 @@ class HomeAssistantApp extends Application.AppBase {
|
||||
switch (responseCode) {
|
||||
case Communications.BLE_HOST_TIMEOUT:
|
||||
case Communications.BLE_CONNECTION_UNAVAILABLE:
|
||||
// System.println("HomeAssistantApp onReturnFetchGlanceContent() Response Code: BLE_HOST_TIMEOUT or BLE_CONNECTION_UNAVAILABLE, Bluetooth connection severed.");
|
||||
if (mIsApp) {
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.NoPhone) as Lang.String);
|
||||
}
|
||||
break;
|
||||
|
||||
case Communications.BLE_QUEUE_FULL:
|
||||
// System.println("HomeAssistantApp onReturnFetchGlanceContent() Response Code: BLE_QUEUE_FULL, API calls too rapid.");
|
||||
if (mIsApp) {
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.ApiFlood) as Lang.String);
|
||||
}
|
||||
break;
|
||||
|
||||
case Communications.NETWORK_REQUEST_TIMED_OUT:
|
||||
// System.println("HomeAssistantApp onReturnFetchGlanceContent() Response Code: NETWORK_REQUEST_TIMED_OUT, check Internet connection.");
|
||||
if (mIsApp) {
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.NoResponse) as Lang.String);
|
||||
}
|
||||
break;
|
||||
|
||||
case Communications.INVALID_HTTP_BODY_IN_NETWORK_RESPONSE:
|
||||
// System.println("HomeAssistantApp onReturnFetchGlanceContent() Response Code: INVALID_HTTP_BODY_IN_NETWORK_RESPONSE, check JSON is returned.");
|
||||
if (mIsApp) {
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.NoJson) as Lang.String);
|
||||
}
|
||||
break;
|
||||
|
||||
case 404:
|
||||
// System.println("HomeAssistantApp onReturnFetchGlanceContent() Response Code: 404, page not found. Check Configuration URL setting.");
|
||||
if (mIsApp) {
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.ConfigUrlNotFound) as Lang.String);
|
||||
}
|
||||
break;
|
||||
|
||||
case 200:
|
||||
if ((data != null) && (data instanceof Lang.Dictionary)) {
|
||||
mGlanceText = data["glanceTemplate"];
|
||||
}
|
||||
WatchUi.requestUpdate();
|
||||
break;
|
||||
|
||||
default:
|
||||
// System.println("HomeAssistantApp onReturnFetchGlanceContent(): Unhandled HTTP response code = " + responseCode);
|
||||
if (mIsApp) {
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.UnhandledHttpErr) as Lang.String + responseCode);
|
||||
}
|
||||
}
|
||||
WatchUi.requestUpdate();
|
||||
}
|
||||
@@ -989,14 +947,6 @@ class HomeAssistantApp extends Application.AppBase {
|
||||
return mApiStatus;
|
||||
}
|
||||
|
||||
//! Return the Menu status result.
|
||||
//!
|
||||
//! @return A string describing the Menu status
|
||||
//
|
||||
function getMenuStatus() as Lang.String {
|
||||
return mMenuStatus;
|
||||
}
|
||||
|
||||
//! Return the optional glance text that overrides the default glance content. This
|
||||
//! is derived from the glance template.
|
||||
//!
|
||||
@@ -1047,11 +997,12 @@ class HomeAssistantApp extends Application.AppBase {
|
||||
function getGlanceView() as [ WatchUi.GlanceView ] or [ WatchUi.GlanceView, WatchUi.GlanceViewDelegate ] or Null {
|
||||
mIsApp = false; // A bit unnecessary given the default
|
||||
mApiStatus = WatchUi.loadResource($.Rez.Strings.Checking) as Lang.String;
|
||||
mMenuStatus = WatchUi.loadResource($.Rez.Strings.Checking) as Lang.String;
|
||||
Settings.update();
|
||||
glanceTemplate();
|
||||
updateStatus();
|
||||
mGlanceTimer = new Timer.Timer();
|
||||
mGlanceTimer.start(method(:updateStatus), Globals.scApiBackoffMs, true);
|
||||
// Although this is now known immediately, wait before displaying so the status can be seen first.
|
||||
return [new HomeAssistantGlanceView(self)];
|
||||
}
|
||||
|
||||
@@ -1066,8 +1017,6 @@ class HomeAssistantApp extends Application.AppBase {
|
||||
//! Update the menu and API statuses. Required for the Glance update timer.
|
||||
//
|
||||
function updateStatus() as Void {
|
||||
mGlanceTimer = null;
|
||||
fetchMenuConfig();
|
||||
fetchApiStatus();
|
||||
if (!Settings.getWebhookId().equals("") && !Settings.getClearWebhookId()) {
|
||||
fetchGlanceContent();
|
||||
|
||||
@@ -47,8 +47,6 @@ class HomeAssistantGlanceView extends WatchUi.GlanceView {
|
||||
private var mTitle as WatchUi.Text?;
|
||||
private var mApiText as WatchUi.Text?;
|
||||
private var mApiStatus as WatchUi.Text?;
|
||||
private var mMenuText as WatchUi.Text?;
|
||||
private var mMenuStatus as WatchUi.Text?;
|
||||
private var mGlanceContent as WatchUi.TextArea?;
|
||||
private var mAntiAlias as Lang.Boolean = false;
|
||||
|
||||
@@ -69,7 +67,7 @@ class HomeAssistantGlanceView extends WatchUi.GlanceView {
|
||||
function onLayout(dc as Graphics.Dc) as Void {
|
||||
var h = dc.getHeight();
|
||||
|
||||
mTextWidth = dc.getTextWidthInPixels(WatchUi.loadResource($.Rez.Strings.GlanceMenu) as Lang.String + ":", Graphics.FONT_XTINY);
|
||||
mTextWidth = dc.getTextWidthInPixels("API:", Graphics.FONT_XTINY);
|
||||
|
||||
mTitle = new WatchUi.Text({
|
||||
:text => WatchUi.loadResource($.Rez.Strings.AppName) as Lang.String,
|
||||
@@ -86,7 +84,7 @@ class HomeAssistantGlanceView extends WatchUi.GlanceView {
|
||||
:font => Graphics.FONT_XTINY,
|
||||
:justification => Graphics.TEXT_JUSTIFY_LEFT | Graphics.TEXT_JUSTIFY_VCENTER,
|
||||
:locX => scLeftRectMargin + scRectWidth + scRightRectMargin,
|
||||
:locY => 3 * h / 6
|
||||
:locY => 4 * h / 6
|
||||
});
|
||||
mApiStatus = new WatchUi.Text({
|
||||
:text => WatchUi.loadResource($.Rez.Strings.Checking) as Lang.String,
|
||||
@@ -94,28 +92,11 @@ class HomeAssistantGlanceView extends WatchUi.GlanceView {
|
||||
:font => Graphics.FONT_XTINY,
|
||||
:justification => Graphics.TEXT_JUSTIFY_LEFT | Graphics.TEXT_JUSTIFY_VCENTER,
|
||||
:locX => scLeftRectMargin + scRectWidth + scRightRectMargin + scMidSep + mTextWidth,
|
||||
:locY => 3 * h / 6
|
||||
});
|
||||
|
||||
mMenuText = new WatchUi.Text({
|
||||
:text => WatchUi.loadResource($.Rez.Strings.GlanceMenu) as Lang.String + ":",
|
||||
:color => Graphics.COLOR_WHITE,
|
||||
:font => Graphics.FONT_XTINY,
|
||||
:justification => Graphics.TEXT_JUSTIFY_LEFT | Graphics.TEXT_JUSTIFY_VCENTER,
|
||||
:locX => scLeftRectMargin + scRectWidth + scRightRectMargin,
|
||||
:locY => 5 * h / 6
|
||||
});
|
||||
mMenuStatus = new WatchUi.Text({
|
||||
:text => WatchUi.loadResource($.Rez.Strings.Checking) as Lang.String,
|
||||
:color => Graphics.COLOR_WHITE,
|
||||
:font => Graphics.FONT_XTINY,
|
||||
:justification => Graphics.TEXT_JUSTIFY_LEFT | Graphics.TEXT_JUSTIFY_VCENTER,
|
||||
:locX => scLeftRectMargin + scRectWidth + scRightRectMargin + scMidSep + mTextWidth,
|
||||
:locY => 5 * h / 6
|
||||
:locY => 4 * h / 6
|
||||
});
|
||||
|
||||
mGlanceContent = new WatchUi.TextArea({
|
||||
:text => "A longer piece of text to wrap.",
|
||||
:text => "",
|
||||
:color => Graphics.COLOR_WHITE,
|
||||
:font => Graphics.FONT_XTINY,
|
||||
:justification => Graphics.TEXT_JUSTIFY_LEFT | Graphics.TEXT_JUSTIFY_VCENTER,
|
||||
@@ -134,10 +115,8 @@ class HomeAssistantGlanceView extends WatchUi.GlanceView {
|
||||
var h = dc.getHeight();
|
||||
var w = dc.getWidth() - scLeftRectMargin - scRightGlanceMargin;
|
||||
var apiStatus = mApp.getApiStatus();
|
||||
var menuStatus = mApp.getMenuStatus();
|
||||
var glanceText = mApp.getGlanceText();
|
||||
var apiCol;
|
||||
var menuCol;
|
||||
// System.println("HomeAssistantGlanceView onUpdate() glanceText=" + glanceText);
|
||||
|
||||
GlanceView.onUpdate(dc);
|
||||
@@ -160,33 +139,15 @@ class HomeAssistantGlanceView extends WatchUi.GlanceView {
|
||||
apiCol = Graphics.COLOR_RED;
|
||||
}
|
||||
|
||||
if (menuStatus.equals(WatchUi.loadResource($.Rez.Strings.Checking))) {
|
||||
menuCol = Graphics.COLOR_YELLOW;
|
||||
} else if (menuStatus.equals(WatchUi.loadResource($.Rez.Strings.Available))) {
|
||||
menuCol = Graphics.COLOR_GREEN;
|
||||
} else if (menuStatus.equals(WatchUi.loadResource($.Rez.Strings.Cached))) {
|
||||
menuCol = Graphics.COLOR_GREEN;
|
||||
} else {
|
||||
menuCol = Graphics.COLOR_RED;
|
||||
}
|
||||
|
||||
if (glanceText == null) {
|
||||
// Default Glance View
|
||||
// Status Glance View
|
||||
mApiText.draw(dc);
|
||||
mApiStatus.setText(apiStatus);
|
||||
mApiStatus.setColor(apiCol);
|
||||
dc.setColor(apiCol, apiCol);
|
||||
dc.drawRoundedRectangle(scLeftRectMargin, 2 * h / 6 + scVertMargin, w, 2 * h / 6 - (2 * scVertMargin), scRectRadius);
|
||||
dc.fillRoundedRectangle(scLeftRectMargin, 2 * h / 6 + scVertMargin, scRectWidth, 2 * h / 6 - (2 * scVertMargin), scRectRadius);
|
||||
dc.drawRoundedRectangle(scLeftRectMargin, 2 * h / 6 + scVertMargin, w, 4 * h / 6 - (2 * scVertMargin), scRectRadius);
|
||||
dc.fillRoundedRectangle(scLeftRectMargin, 2 * h / 6 + scVertMargin, scRectWidth, 4 * h / 6 - (2 * scVertMargin), scRectRadius);
|
||||
mApiStatus.draw(dc);
|
||||
|
||||
mMenuText.draw(dc);
|
||||
mMenuStatus.setText(menuStatus);
|
||||
mMenuStatus.setColor(menuCol);
|
||||
dc.setColor(menuCol, menuCol);
|
||||
dc.drawRoundedRectangle(scLeftRectMargin, 4 * h / 6 + scVertMargin, w, 2 * h / 6 - (2 * scVertMargin), scRectRadius);
|
||||
dc.fillRoundedRectangle(scLeftRectMargin, 4 * h / 6 + scVertMargin, scRectWidth, 2 * h / 6 - (2 * scVertMargin), scRectRadius);
|
||||
mMenuStatus.draw(dc);
|
||||
} else {
|
||||
// Customised Glance View
|
||||
dc.setColor(Graphics.COLOR_BLUE, Graphics.COLOR_BLUE);
|
||||
@@ -198,9 +159,7 @@ class HomeAssistantGlanceView extends WatchUi.GlanceView {
|
||||
scRectRadius
|
||||
);
|
||||
dc.setColor(apiCol, apiCol);
|
||||
dc.fillRoundedRectangle(scLeftRectMargin, 2 * h / 6 + scVertMargin, scRectWidth, 2 * h / 6 - (2 * scVertMargin), scRectRadius);
|
||||
dc.setColor(menuCol, menuCol);
|
||||
dc.fillRoundedRectangle(scLeftRectMargin, 4 * h / 6 + scVertMargin, scRectWidth, 2 * h / 6 - (2 * scVertMargin), scRectRadius);
|
||||
dc.fillRoundedRectangle(scLeftRectMargin, 2 * h / 6 + scVertMargin, scRectWidth, 4 * h / 6 - (2 * scVertMargin), scRectRadius);
|
||||
mGlanceContent.setText(glanceText);
|
||||
mGlanceContent.draw(dc);
|
||||
}
|
||||
|
||||