mirror of
https://github.com/house-of-abbey/GarminHomeAssistant.git
synced 2025-06-16 11:28:40 +00:00
Compare commits
29 Commits
restyled/7
...
v2.5
Author | SHA1 | Date | |
---|---|---|---|
7ab8246197 | |||
776134e842 | |||
a95736ebed | |||
9c001f3402 | |||
7786efd883 | |||
0b80e4546d | |||
6e67c4cf2a | |||
b80227e484 | |||
d9b345e5b8 | |||
fc7302ad3b | |||
d9ecaf34ee | |||
62b8f0fccf | |||
26954cbc60 | |||
a5b2af81bc | |||
10c64c0fdc | |||
ed3dce8827 | |||
35a65ebdf4 | |||
b46c4d2eb4 | |||
2b21c840c6 | |||
1448f6b0c2 | |||
ce2f4d38d0 | |||
13d3ffd1ec | |||
5620ea6695 | |||
7243917103 | |||
49fb42cc0f | |||
39fc04fc5c | |||
3c5e970892 | |||
bd32d94ac7 | |||
f0b84856ad |
@ -1,3 +1,5 @@
|
||||
[Home](README.md) | [Switches](examples/Switches.md) | [Actions](examples/Actions.md) | [Templates](examples/Templates.md) | Battery Reporting | [Trouble Shooting](TroubleShooting.md) | [Version History](HISTORY.md)
|
||||
|
||||
# Battery Reporting
|
||||
|
||||
From version 2.1 the application includes a background service to report the current device battery level and charging status back to Home Assistant. This is a feature that Garmin omitted to include with the Bluetooth connection.
|
||||
@ -6,7 +8,7 @@ From version 2.1 the application includes a background service to report the cur
|
||||
|
||||
The main drawback of this solution is that the Garmin application must be run once with the feature enabled in the settings before reporting will start. Reporting continues after you have exited the application. This is a limit we cannot code around.
|
||||
|
||||
It should be as simple as that, there should be a new device in the mobile app integration called `Garmin Watch` with the battery level and charging status.
|
||||
It should be as simple as starting the application (or widget). There should be a new device in the mobile app integration called `Garmin Watch` with the battery level and charging status.
|
||||
|
||||
[](https://my.home-assistant.io/redirect/integration/?domain=mobile_app)
|
||||
|
||||
@ -14,9 +16,7 @@ If this is not the case, head over to the [troubleshooting page](Troubleshooting
|
||||
|
||||
## Stop Reporting
|
||||
|
||||
To stop the reporting, the option must be turned off in the settings and then the application run once. Running the application then removes the background service.
|
||||
|
||||
In both cases, the enable and repeat time settings can be changed whilst the application is running (i.e. live) and the background service will be amended.
|
||||
To stop the reporting, the option must be turned off in the settings and then the application run once. Running the application then removes the background service. Both the enable and repeat time settings can be changed whilst the application is running (i.e. live) and the background service will be amended.
|
||||
|
||||
## Renaming the device
|
||||
|
||||
@ -32,7 +32,7 @@ Select the device called `Garmin Watch` and then click on the edit icon in the t
|
||||
|
||||
## Fixing the icon
|
||||
|
||||
In configuration.yaml:
|
||||
In `configuration.yaml`:
|
||||
|
||||
```yaml
|
||||
template:
|
||||
@ -116,7 +116,7 @@ N.B. `sensor.<device>_battery_level` will likely need to be changed to `sensor.<
|
||||
|
||||
## Migrating
|
||||
|
||||
You should remove your old template sensors before migrating to the new integration. You can do this by removing the `sensor.<device>_battery_level` and `binary_sensor.<device>_battery_is_charging` entities from `configuration.yaml` and then restarting Home Assistant or reloading the yaml.
|
||||
You should remove your old template sensors before migrating to the new integration. You can do this by removing the `sensor.<device>_battery_level` and `binary_sensor.<device>_battery_is_charging` entities from `configuration.yaml` and then restarting Home Assistant or reloading the YAML.
|
||||
|
||||
[Here is the old configuration method for reference.](https://github.com/house-of-abbey/GarminHomeAssistant/blob/b51e2aa2a4afbc58ad466f3b81667d1cd252d091/BatteryReporting.md)
|
||||
|
||||
|
19
HISTORY.md
Normal file
19
HISTORY.md
Normal file
@ -0,0 +1,19 @@
|
||||
[Home](README.md) | [Switches](examples/Switches.md) | [Actions](examples/Actions.md) | [Templates](examples/Templates.md) | [Battery Reporting](BatteryReporting.md) | [Trouble Shooting](TroubleShooting.md) | Version History
|
||||
|
||||
# Version History
|
||||
|
||||
| Version | Comment |
|
||||
|:-------:|---------|
|
||||
| 1.0 | Initial release for 26 devices. |
|
||||
| 1.1 | Updated for 54 more devices, 80 in total. Scene support. Added vibrate acknowledgement for tap-based menu items. Falls back to a custom visual confirmation in the absence of 'toast' and vibrate support. Bug fix for large menus needing status updates. |
|
||||
| 1.2 | Do not crash on zero items to update. Report unreachable URLs. Verify API URL does not have a trailing slash '/'. Increased HTTP response diagnosis. Reduced minimum API Level required from 3.3.0 to 3.1.0 to allow more device "part numbers" to be satisfied. |
|
||||
| 1.3 | Tap for scripts was working in emulation but not on some phones. Decision is to make the 'service' field in the JSON compulsory for 'tap' menu items. This is a breaking change, but for many might be a fix for something not working correctly. Improve language support, we can now accept language corrections and prevent the automated translation of strings from clobbering manually refined entries. Thank you to two new contributors. |
|
||||
| 1.4 | New lean user Interface with thanks to [Someone0nEarth](https://github.com/Someone0nEarth) for their contribution which is now the default. If you prefer the old style you can still select it in the settings. The provision of a 'service' tag is now not just heavily suggested by the JSON schema, it is enforced in code. With apologies to anyone suffering a breakage as a result. |
|
||||
| 1.5 | <img src="images/confirmation_view.png" width="200" title="Confirmation View"/><br/>Added an optional confirmation dialogue view to prevent accidental execution of actions on mistaken tap. This also brings a change in the JSON schema to allow an optional field to specify that the confirmation should be used for a menu item. As we are now maturing and adding features we have decided to mitigate breaking changes to the JSON schema by being more careful to adopt the Home Assistant schema (noting there is a 1:1 mapping between YAML and JSON). This change does deprecate the top level `service` tag in favour of `tag_action` containing multiple fields including `service` & `confirm`. Users should migrate to the new format for the new functionality, but the timescale for actual deprecation are long and undecided. |
|
||||
| 1.6 | Added a user configurable 'timeout' in seconds so that when no action is taken the application automatically closes, stopping the continuous polling for changes of status and hence saving the drain on the battery. This can be disabled with timeout=0. |
|
||||
| 1.7 | Added timeout to confirmation views so that when used for security devices it does not linger when left unconfirmed. Thanks to [Jan Schneider](https://github.com/j-a-n) for the contribution. Known bug for devices not supporting [`WatchUi.getCurrentView()`](https://developer.garmin.com/connect-iq/api-docs/Toybox/WatchUi.html#getCurrentView-instance_function) API call which is only available on API Level 3.4.0, e.g. Vivoactive 4S. |
|
||||
| 2.0 | A significant code base change to enable both a 'widget' version for older devices, e.g. Venu (1), and an application with a glance, e.g. Venu2. These two versions must now be distributed under separate application IDs, but they have the same code base. A further 20 more devices are now supported, the settings have been internationalised, and there's a bug fix for older devices when trying to display a helpful error message but instead the application crashed. This version has come from a significant collaboration with [Someone0nEarth](https://github.com/Someone0nEarth). |
|
||||
| 2.1 | Deployment of an idea to provide Home Assistant with access to the watch battery level. Using this requires [significant setup](BatteryReporting.md) on the Home Assistant configuration and hence is detailed separately. Due to this, the default state for this battery option is _off_. Changed the application settings user interface to be more intuitive, and hence amended the way settings are managed in the background. |
|
||||
| 2.2 | Adds a feature to cache the menu configuration and save the time taken for an HTTP request to fetch it. You as the user are responsible for managing the cache by clearing it when you update your configuration. Improvement to widget root display updates. Bug fix for battery level reporting when in the glance carousel. Fixed an uninternationalised string, "Execute". Unfixed issue with battery level updates when the user is not an administrator. |
|
||||
| 2.3 | Fix for battery level updates where previously the function only worked for administrator accounts. The new solution is based on Webhooks and is simpler to implement on Home Assistant. Language support fix where an automatic translation produced an inappropriate word, possibly in more than one language. |
|
||||
| 2.4 | Sensor status reporting via Home Assistant 'templates'. This provides a generalised way of viewing the status of any entity as long as the result can be rendered as text, e.g. 'uncovered', 'open', '76%', '21 °C'. Removal of the menu style option. The original style was kept after the introduction of the icon style solely to keep the code for a possible re-use for sensor statuses. This version delivers that new feature, hence the style option has been removed. The new JSON configuration file format allows for the old style to be replicated if you are desperate! Added a feature to provide parameters to actions (`tap` or `template`). Added a feature to confirm `toggle` menu items. |
|
137
README.md
137
README.md
@ -1,42 +1,44 @@
|
||||
Home | [Switches](examples/Switches.md) | [Actions](examples/Actions.md) | [Templates](examples/Templates.md) | [Battery Reporting](BatteryReporting.md) | [Trouble Shooting](TroubleShooting.md) | [Version History](HISTORY.md)
|
||||
|
||||
# GarminHomeAssistant
|
||||
|
||||
<img src="images/Actual_Venu2_Theme.jpg" width="200" title="Venu 2"/>
|
||||
|
||||
A Garmin application to provide a "dashboard" to control your devices via [Home Assistant](https://www.home-assistant.io/). The application will never be as fully fledged as a Home Assistant dashboard, so it is designed to be good enough for the simple and essential things. Those things that can be activated via an on/off toggle or a tap. That should cover lights, switches, and anything requiring a single press such as an automation. For anything more complicated, e.g. thermostat, it would always be quicker and simpler to reach for your phone or tablet... or the device's own remote control!
|
||||
|
||||
The application is designed around a simple scrollable menu where menu items have been extended to interface with the [Home Assistant API](https://developers.home-assistant.io/docs/api/rest/), e.g. to get the status of switches or lights for display on the toggle menu item. It is possible to nest menus, so there is a menu item to open a sub-menu. This can be arbitrarily deep and nested in the format of a tree of items, although you need to consider if reaching for your phone becomes quicker to select the device what you want to control.
|
||||
The application is designed around a simple scrollable menu where menu items have been extended to interface with the [Home Assistant API](https://developers.home-assistant.io/docs/api/rest/), e.g. to get the status of switches or lights for display on the toggle menu item, or a text status for an entity (template item). It is possible to nest menus, so there is a menu item to open a sub-menu. This can be arbitrarily deep and nested in the format of a tree of items, although you need to consider if reaching for your phone becomes quicker to select the device what you want to control.
|
||||
|
||||
The intended audience for this application are those comfortable with configuring a Home Assistant (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". If you are not comfortable with this relatively low level of configuration, you may like to try other Garmin applications instead.
|
||||
**The intended audience for this application are those comfortable with configuring a Home Assistant** (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". If you are not comfortable with this relatively low level of configuration, you may like to try other Garmin applications instead.
|
||||
|
||||
It is important to note that your Home Assistant instance will need to be accessible via HTTPS with public SSL or all requests from the Garmin will not work. This cannot be a self-signed certificate, it must be a public certificate. You can get one for free from [Let's Encrypt](https://letsencrypt.org/) or you can pay for [Home Assistant cloud](https://www.nabucasa.com/).
|
||||
It is important to note that your Home Assistant instance will need to be accessible via HTTPS with public SSL or all requests from the Garmin will not work. This cannot be a self-signed certificate, it must be a public certificate. You can get one for free from [Let's Encrypt](https://letsencrypt.org/) or you can pay for [Home Assistant cloud](https://www.nabucasa.com/). (You can install a local [Nginx proxy server](https://my.home-assistant.io/redirect/supervisor_addon/?addon=a0d7b954_nginxproxymanager) to manage Let's Encrypt certificates.)
|
||||
|
||||
**If you are struggling with getting the application to work, please consult the [trouble shooting](Troubleshooting.md#menu-configuration-url) guide first.**
|
||||
**If you are struggling with getting the application to work, please consult the [trouble shooting](TroubleShooting.md#menu-configuration-url) guide first.**
|
||||
|
||||
|
||||
## Widget or Application?
|
||||
|
||||
As of version 2.0, there are now two installable versions. For older devices before applications supported 'glances', there is a now widget version. These two version must be downloaded separately due to the way the Connect IQ App Store requires them to have separate application IDs. Therefore you need to choose which you want up front. Here how they compare.
|
||||
As of version 2.0, there are now two installable versions. For older devices before applications supported 'glances', there is a now widget version. These two version must be downloaded separately due to the way the Connect IQ App Store requires them to have separate application IDs. Therefore you need to choose which you want up front. Here's how they compare.
|
||||
|
||||
| Version | Explanation |
|
||||
|------------------------|-------------|
|
||||
| Application (original) | For newer devices that allow glance views in their applications (e.g. Venu2), the GarminHomeAssistant application can be started either from a glance (with only the application name presently, no status) 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.<hr><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="Venu 2" 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_start.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. |
|
||||
| Widget | For older devices that use widgets (e.g. Venu1) 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.<hr><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. |
|
||||
| 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="Venu 2" 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_start.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. |
|
||||
| Widget | 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.** |
|
||||
|
||||
As the source code base for both is the same, the version numbers of each will be kept in step. that means that the widget version starts version numbering at 2.0 too.
|
||||
As the source code base for both is the same, the version numbers of each will be kept in step. That means that the widget version starts version numbering at 2.0.
|
||||
|
||||
## Dashboard Definition
|
||||
|
||||
Setup for this menu is more complicated than the Connect IQ settings menu really allows you to specify. In order to make the dashboard easily configurable and easy to change, we have provided an external mechanism for specifying the menu layout, a JSON file you write, retrieved from a URL you specify. JSON was chosen over YAML because Garmin can parse JSON HTTP GET responses into its own internal dictionary, it cannot parse YAML, hence a choice of one really. Note that JSON and YAML are essentially a 1:1 format mapping except JSON does not have comments. We recommend you take advantage of [Home Assistant's own web server](https://www.home-assistant.io/integrations/http/#hosting-files) to provide the JSON definition. The advantage here are:
|
||||
Setup for this menu is more complicated than the Connect IQ settings menu really allows you to specify. In order to make the dashboard easily configurable and easy to change, we have provided an external mechanism for specifying the menu layout, a JSON file you write, retrieved from a URL you specify. JSON was chosen over YAML because Garmin can parse JSON HTTP GET responses into its own internal dictionary, it cannot parse YAML, hence a choice of one really. Note that JSON and YAML are essentially a 1:1 format mapping except JSON does not have comments. We recommend you take advantage of [Home Assistant's own web server](https://www.home-assistant.io/integrations/http/#hosting-files) to provide the JSON definition. The advantages of this are:
|
||||
|
||||
1. the file is as public as you make your Home Assistant,
|
||||
2. the file is editable within Home Assistant via "Studio Code Server", and
|
||||
2. the file is editable within Home Assistant via "[Studio Code Server](https://my.home-assistant.io/redirect/supervisor_addon/?addon=a0d7b954_vscode)", and
|
||||
3. the schema is verifiable using [JSON Schema](https://json-schema.org/overview/what-is-jsonschema).
|
||||
|
||||
We have used `/config/www/garmin/<something>.json` on our Home Assistant's file system. That equates to a URL of `https://homeassistant.local/local/garmin/<something>.json`.
|
||||
|
||||
Schema verification is a big part of this design choice. If the application cannot read your menu definition, there's a limited amount of debug it can reasonable provide on a small screen. That responsibility now falls to you and the schema checker for help.
|
||||
Schema verification is a big part of this design choice. If the application cannot read your menu definition, there's a limited amount of debug it can reasonably provide on a small screen. That responsibility now falls to you and the schema checker for help.
|
||||
|
||||
Example schema as shown in the images:
|
||||
Example schema:
|
||||
|
||||
```json
|
||||
{
|
||||
@ -63,7 +65,6 @@ Example schema as shown in the images:
|
||||
"type": "toggle"
|
||||
},
|
||||
{
|
||||
"entity": "menu.each_lounge_light",
|
||||
"name": "Each Lounge Light",
|
||||
"title": "Lounge",
|
||||
"type": "group",
|
||||
@ -115,35 +116,40 @@ Example schema as shown in the images:
|
||||
}
|
||||
```
|
||||
|
||||
NB. Entity names are not real in case anyone's a hacker.
|
||||
NB. Entity names are not real in case anyone's a hacker ;-).
|
||||
|
||||
The example above illustrates how to configure:
|
||||
|
||||
* Light or switch toggles
|
||||
* Automation enable toggles
|
||||
* Lights or switches (toggle), <img src="images/toggle_icon.png" height="20">
|
||||
* Enables for automations (toggle), <img src="images/toggle_icon.png" height="20">
|
||||
* Script invocation (tap)
|
||||
* Service invocation, e.g. Scene setting, (tap)
|
||||
* A sub-menu to open (tap)
|
||||
* A sub-menu to open (group)
|
||||
* You can also display the status of devices (template) and add an optional 'tap' action. However that's a bit more involved and has its own [examples page](examples/Templates.md). Add those later!
|
||||
|
||||
The example JSON shows an example usage of each of these Home Assistance entity types. Presently, an automation is the only one that can be either a 'tap' or a 'toggle'.
|
||||
The following table indicates how Home Assistant entity types can map to the Garmin applications menu types. Presently, an automation is the only one that can be either a 'tap' or a 'toggle'.
|
||||
|
||||
| HA Type | Tap | Toggle |
|
||||
|------------|:---:|:------:|
|
||||
| Switch | ❌ | ✅ |
|
||||
| Light | ❌ | ✅ |
|
||||
| Automation | ✅ | ✅ |
|
||||
| Script | ✅ | ❌ |
|
||||
| Scene | ✅ | ❌ |
|
||||
| HA Entity Type | Tap | Toggle | Template (custom status text with optional tap action) |
|
||||
|------------------|:---:|:------:|:------------------------------------------------------:|
|
||||
| Switch | ❌ | ✅ | ✅<br>Separate on and off, or anything in between |
|
||||
| Light | ❌ | ✅ | ✅<br>Separate on and off, or anything in between |
|
||||
| Automation | ✅ | ✅ | ✅ |
|
||||
| Script | ✅ | ❌ | ✅ |
|
||||
| Scene | ✅ | ❌ | ✅ |
|
||||
| Sensor | ❌ | ❌ | ✅ |
|
||||
| Binary Sensor | ❌ | ❌ | ✅ |
|
||||
| Any other entity | ❌ | ❌ | ✅ |
|
||||
| Any service | ✅ | ❌ | ✅ |
|
||||
|
||||
NB. All 'tap' items must specify a 'service' tag.
|
||||
Templates need separate HTTP requests to update their status and send an action. Only the toggle items have the on/off <img src="images/toggle_icon.png" height="20"> icon. A Tap does not require a status update and hence does not require the associated HTTP GET request. NB. All 'tap' items must specify a 'service' tag.
|
||||
|
||||
Possible future extensions might include specifying the alternative texts to use instead of "On" and "Off", e.g. "Locked" and "Unlocked" (but wouldn't having locks operated from your watch be a security concern ;-))
|
||||
You can now specify alternative texts to use instead of "On" and "Off", e.g. "Locked" and "Unlocked" or "Open" and "Closed" through the use of a [template menu item](examples/Templates.md). But wouldn't having locks operated from your watch be a security concern ;-) ?
|
||||
|
||||
The [schema](https://raw.githubusercontent.com/house-of-abbey/GarminHomeAssistant/main/config.schema.json) is checked by using a URL directly back to this GitHub source repository, so you do not need to install that file. You can just copy & paste your entity names from the YAML configuration files used to configure Home Assistant. With a submenu, there's a difference between "title" and "name". The "name" goes on the menu item, and the "title" at the head of the submenu. If your dashboard definition fails to meet the schema, the application will simply drop items with the wrong field names without warning.
|
||||
The [schema](https://raw.githubusercontent.com/house-of-abbey/GarminHomeAssistant/main/config.schema.json) is checked by using a URL directly back to this GitHub source repository, so you do not need to install that file. You can just copy & paste your entity names from the YAML configuration files used to configure Home Assistant. With a submenu, there's a difference between "title" and "name". The "name" goes on the menu item, and the "title" at the head of the submenu. If your dashboard definition fails to meet the schema, the application will simply drop items with the wrong field names without warning to protect itself.
|
||||
|
||||
### Old deprecated format
|
||||
|
||||
Version 1.5 brought in a change to the JSON schema so the follow old format remains useable but is no longer favoured. The schema now marks it as 'deprecated' to nudge people over.
|
||||
Version 1.5 brought in a change to the JSON schema so the following old format remains useable but is no longer favoured. The schema now marks it as 'deprecated' to nudge people over.
|
||||
|
||||
```json
|
||||
{
|
||||
@ -169,32 +175,36 @@ The above should be replaced by the following:
|
||||
|
||||
This allows the `confirm` field to be accommodated in the `tap_action` along side the `service` tag, and follows the Home Assistant YAML format more closely.
|
||||
|
||||
### More Examples
|
||||
|
||||
- [Switches](examples/Switches.md)
|
||||
- [Actions](examples/Actions.md)
|
||||
- [Templates](examples/Templates.md)
|
||||
|
||||
## Editing the JSON file
|
||||
|
||||
You have options. The first is what we use.
|
||||
1. **Best!** Use the [Studio Code Server](https://community.home-assistant.io/t/home-assistant-community-add-on-visual-studio-code/107863) addon for Home Assistant. You can then edit your JSON file in place.
|
||||
2. Locally installed VSCode, or if not installed,
|
||||
3. try the on-line version at https://vscode.dev/.
|
||||
3. try the on-line version at https://vscode.dev/, which works really well.
|
||||
|
||||
Paste in your JSON (and change the file type to JSON if not saving), it will then verify your file format and schema for you, highlighting any errors for you to fix.
|
||||
|
||||
A failure to get the file format right tends to mean that the response to the application errors with `INVALID_HTTP_BODY_IN_NETWORK_RESPONSE` (code of -400). This means the response did not contain JSON, it was probably an error message in plain text that could not be parsed by the Connect IQ API call. See [Toybox.Communications](https://developer.garmin.com/connect-iq/api-docs/Toybox/Communications.html) for the list of error code you might be present with on your device.
|
||||
A failure to get the file format right tends to mean that the response to the application errors with `INVALID_HTTP_BODY_IN_NETWORK_RESPONSE` (code of -400). This means the response did not contain JSON, it was probably an error message in plain text that could not be parsed by the Connect IQ API call. See [Toybox.Communications](https://developer.garmin.com/connect-iq/api-docs/Toybox/Communications.html) for the list of error code you might be presented with on your device.
|
||||
|
||||
Make sure you can browse to the URL of your JSON file in a standard web browser to make sure it is accessible.
|
||||
|
||||
## API Key Creation
|
||||
|
||||
Having created your JSON definition for your dashboard, you need to create an API key for your personal account on Home Assistant. You will need a [Long-Lived Access Token](https://developers.home-assistant.io/docs/auth_api/#long-lived-access-token). This is not obvious and is bound to your own Home Assistant account.
|
||||
|
||||
Follow the menu sequence: `HA -> user profile -> Long-lived access tokens`. Make sure you save the generated token before dismissing it. You may like to perform this task on your phone so that you can copy and paste it (and message yourself a copy too ;-).
|
||||
Having created your JSON definition for your dashboard, you need to create an API key for your personal account on Home Assistant. You will need a [Long-Lived Access Token](https://developers.home-assistant.io/docs/auth_api/#long-lived-access-token). This is not obvious to find and is bound to your own Home Assistant account. Follow the menu sequence: `HA -> user profile -> Long-lived access tokens`. Make sure you save the generated token before dismissing it.
|
||||
|
||||

|
||||
|
||||
Having created that token, before you dismiss the dialogue box with the value you will never see again, copy it somewhere safe. You need to paste this into the Garmin Application's settings.
|
||||
Having created that token, before you dismiss the dialogue box with the value you will never see again, copy it somewhere safe. You need to paste this into the Garmin Application's settings. You may like to perform this task on your phone so that you can copy and paste it (and message yourself a copy too ;-)).
|
||||
|
||||
## API URL
|
||||
|
||||
If you are using Nabu Casa then your Cloud API URL can be found by looking up your URL via `HA -> Settings -> Home Assistant Cloud -> Remote Control -> Nabu Casa URL` and don't forget to add `/api` to the end of the copied string.
|
||||
If you are using [Nabu Casa](https://www.nabucasa.com/) then your Cloud API URL can be found by looking up your URL via `HA -> Settings -> Home Assistant Cloud -> Remote Control -> Nabu Casa URL` and don't forget to add `/api` to the end of the copied string.
|
||||
|
||||

|
||||
|
||||
@ -202,11 +212,9 @@ If you have built your own infrastructure, you really don't need any assistance
|
||||
|
||||
## Settings
|
||||
|
||||
Unfortunately the Settings dialogue box in the Garmin IQ application times out in Android when you go to a different screen (browser for example). When you go back to the Connect IQ application (select the view again) the settings dialogue box is broken and you have to open the Settings again, so you will need to save the settings every time before you switch applications to avoid losing the information you just put in.
|
||||
Unfortunately the Settings dialogue box in the Garmin IQ application "times out" in Android when you go to a different screen (a browser for example). When you go back to the Connect IQ application (select the view again) the settings dialogue box is broken and you have to open the Settings again, so you will need to save the settings every time before you switch applications to avoid losing the information you just put in. We recommend you can use an application like [Microsoft's "Phone Link"](https://apps.microsoft.com/detail/9NMPJ99VJBWV?hl=en-gb&gl=US) that allows you to *copy and paste* between your PC and your phone.
|
||||
|
||||
You can instead use an application like [Microsoft's "Phone Link"](https://apps.microsoft.com/detail/9NMPJ99VJBWV?hl=en-gb&gl=US) that allows you to copy and paste between your PC and your phone.
|
||||
|
||||
**Please, please, please!** Copy and paste your API key and all URLs, do not retype as it will be wrong.
|
||||
**Please, please, please!** *Copy and paste* your API key and all URLs, do not retype them as they will be wrong.
|
||||
|
||||
<img src="images/GarminHomeAssistantSettings.png" width="400" title="Application Settings"/>
|
||||
|
||||
@ -216,15 +224,15 @@ You can instead use an application like [Microsoft's "Phone Link"](https://apps.
|
||||
|
||||
You should now have a working application on your watch and be able to operate your Home Assistant devices for as long as your watch is within Bluetooth range of your phone.
|
||||
|
||||
You may choose to cache your menu definition on your device in order to reduce the delay in showing the menu (as it saves waiting for an HTTP GET request). If you use this option you are responsible for managing the cache when the menu is updated at source. The Toggle below allows you to choose to refresh the cache the next time the application starts. Once the cache has been cleared, the application will reset this toggle for you, so you do not need to return to the settings to flip it.
|
||||
You may choose to cache your menu definition on your device in order to reduce the delay in showing the menu (as it saves waiting for an HTTP GET request). If you use this option you are responsible for managing the cache when the menu is updated at source. The toggle option below the cache option allows you to choose to refresh the cache the next time the application starts. Once the cache has been cleared, the application will reset this toggle for you, so you do not need to return to the settings to amend it.
|
||||
|
||||
The application timeout prevents the app running on your watch when you have forgotten to close it. It prevents the refreshing of the menu statuses and therefore excessive wear on your battery level. There is a second timeout value for confirmation views. This is intended for use with more sensitive toggles so that the confirmation view is not left open and forgotten and then confirmed accidentally without you noticing. **We cannot advise you this is safe, be careful what you toggle with the watch application!**
|
||||
|
||||
There is a toggle setting for "text alignment" and provides finer adjustment for right-to-left languages. Perhaps this could be made automatic based on device language?
|
||||
There is a toggle setting for "text alignment" that provides finer adjustment for right-to-left languages. Perhaps this could be made automatic based on device language?
|
||||
|
||||
Another toggle setting for the **Widget version only** allows the user to select a non-standard user interface behaviour. As soon as the menu is retrieved the widget view is replaced by the menu without waiting for a user selection. This has been included as requested by a user, but defaults to off which retains the expected user interactions.
|
||||
|
||||
Finally you may enable a background service to report the battery level to your Home Assistant. This is not available over Bluetooth like with other Bluetooth devices as Garmin did not implement it. See the [set up instructions](#battery-level-reporting). the last field here is readonly and allows the user to copy & paste the Webhook ID setup by the application when required for debug.
|
||||
The application and widget both include a background service to report your watch's battery level and charging status. You may enable a background service to report the battery level to your Home Assistant. This is not available over your Bluetooth connection like with other Bluetooth devices as Garmin did not implement it. This no longer requires any setup, and we offer this [trouble shooting](TroubleShooting.md#watch-battery-level-reporting) guide. The last field here is readonly and allows the user to copy & paste the Webhook ID setup by the application when required for this trouble shooting guide.
|
||||
|
||||
## Tap Item Response
|
||||
|
||||
@ -238,19 +246,17 @@ The application will display a 'toast' showing Home Assistant's friendly name of
|
||||
|
||||
Home Assistant will inevitably change the state of devices you are also controlling via your Garmin. The Garmin application does not maintain a web socket to listen for changes. Instead it must poll the Home Assistant API with your key. Therefore the application is not that responsive to changes. Instead there will be a delay of multiples of 100 ms per item whose status needs to be checked and amended.
|
||||
|
||||
The per toggle item delay is caused by a queue of responses to web requests filling up a queue and giving a [`Communications.BLE_QUEUE_FULL`](https://developer.garmin.com/connect-iq/api-docs/Toybox/Communications.html). response code. For a Venu 2 Garmin watch an API call delay of 600 ms was found to be sustainable (500 ms was still too fast). The code now chains a sequence of updates, so as one finishes it invokes the next item's update. The more items requiring a status update that you pack into your dashboard, the slower each individual item will be updated!
|
||||
The per toggle item delay is caused by a queue of responses to web requests. The responses fill up a buffer and in early testing we observed [`Communications.BLE_QUEUE_FULL`](https://developer.garmin.com/connect-iq/api-docs/Toybox/Communications.html) response codes. For a Venu 2 Garmin watch an API call delay of 600 ms was found to be sustainable (500 ms was still too fast). The code now chains a sequence of updates, so as one finishes it invokes the next item's update. **The more items requiring a status update that you pack into your dashboard, the slower each individual item will be updated!**
|
||||
|
||||
The thinking here is that the watch application will only ever be open briefly not persistently, so the delay in picking up state changes won't be observed often for any race condition between two controllers.
|
||||
|
||||
As a consequence of this update mechanism, if you request changes too quickly you will be notified that your device cannot keep up with the rate of API responses and you will have to dismiss the error in order to continue. The is a _feature not a bug_!
|
||||
The thinking here is that the watch application will only ever be open briefly not persistently, so the delay in picking up state changes won't be observed often for any race condition between two controllers. As a consequence of this update mechanism, if you request changes too quickly you will be notified that your device cannot keep up with the rate of API responses and you will have to dismiss the error in order to continue. The is a _feature not a bug_!
|
||||
|
||||
## Changes to the (JSON) Dashboard Definition
|
||||
|
||||
When you change the JSON file defining your dashboard, you must exit the application and the reopen it. It only takes a matter of a few seconds to pick up the new definition, but it is not automatic.
|
||||
When you change the JSON file defining your dashboard, you must exit the application and the reopen it. It only takes a matter of a few seconds to pick up the new definition, but it is not automatic. *Don't forget* you may need to choose to clear your cached menu.
|
||||
|
||||
## Submitting Corrections for Translations
|
||||
|
||||
Initially all text has been created in English, and a [Python script](https://github.com/house-of-abbey/GarminHomeAssistant/blob/main/translate.py) (Google Translate under the hood) has been used to create the first version of all translations. We have been pleased to accept better translations from native language speakers, **thank you**. If you would like to submit improved translations, our preference is you do so via a Git pull request. If you are not comfortable doing this, then just raise an issue and someone will eventually pick the request up.
|
||||
Initially all text has been created in English, and a [Python script](https://github.com/house-of-abbey/GarminHomeAssistant/blob/main/translate.py) (Google Translate under the hood) has been used to create the first version of all translations. We have been pleased to accept better translations from native language speakers, *thank you*. If you would like to submit improved translations, our preference is you do so via a [Git pull request](https://github.com/house-of-abbey/GarminHomeAssistant/pulls). If you are not comfortable doing this, then just raise an issue and someone will eventually pick the request up.
|
||||
|
||||
In order to submit a language correction please create an XML file called `corrections.xml` in the same directory as your language containing the corrected text. The format of the XML file follows that of `strings.xml`. As an example here are some corrected French translations found in directory [`resources-fre/strings/corrections.xml`](https://github.com/house-of-abbey/GarminHomeAssistant/tree/main/resources-fre/strings/corrections.xml):
|
||||
|
||||
@ -262,35 +268,20 @@ In order to submit a language correction please create an XML file called `corre
|
||||
</strings>
|
||||
```
|
||||
|
||||
The `id` attribute values are taken from the same names used in [`strings.xml`](https://github.com/house-of-abbey/GarminHomeAssistant/blob/main/resources-fre/strings/strings.xml). Not all `id` values need to be specified as missing `id`s will then use automatic translations. If the existing convention is followed then:
|
||||
The `id` attribute values are taken from the same names used in [`strings.xml`](https://github.com/house-of-abbey/GarminHomeAssistant/blob/main/resources-fre/strings/strings.xml). **Not all `id` values need to be specified as missing `id`s will then use automatic translations.** If the existing convention is followed then:
|
||||
|
||||
* The Python script will use the corrections in preference to translating, and
|
||||
* Your pull request will be honoured without comment as we will take your corrections on trust.
|
||||
|
||||
## Battery Level Reporting
|
||||
|
||||
The application and widget both now include a background service to report your watch's battery level and charging status. This requires some [setup](BatteryReporting.md) via YAML in Home Assistant to display the transmitted value. We offer this [trouble shooting](Troubleshooting.md#watch-battery-level-reporting) guide.
|
||||
|
||||
## Version History
|
||||
|
||||
| Version | Comment |
|
||||
|:-------:|---------|
|
||||
| 1.0 | Initial release for 26 devices. |
|
||||
| 1.1 | Updated for 54 more devices, 80 in total. Scene support. Added vibrate acknowledgement for tap-based menu items. Falls back to a custom visual confirmation in the absence of 'toast' and vibrate support. Bug fix for large menus needing status updates. |
|
||||
| 1.2 | Do not crash on zero items to update. Report unreachable URLs. Verify API URL does not have a trailing slash '/'. Increased HTTP response diagnosis. Reduced minimum API Level required from 3.3.0 to 3.1.0 to allow more device "part numbers" to be satisfied. |
|
||||
| 1.3 | Tap for scripts was working in emulation but not on some phones. Decision is to make the 'service' field in the JSON compulsory for 'tap' menu items. This is a breaking change, but for many might be a fix for something not working correctly. Improve language support, we can now accept language corrections and prevent the automated translation of strings from clobbering manually refined entries. Thank you to two new contributors. |
|
||||
| 1.4 | New lean user Interface with thanks to [Someone0nEarth](https://github.com/Someone0nEarth) for their contribution which is now the default. If you prefer the old style you can still select it in the settings. The provision of a 'service' tag is now not just heavily suggested by the JSON schema, it is enforced in code. With apologies to anyone suffering a breakage as a result. |
|
||||
| 1.5 | <img src="images/confirmation_view.png" width="200" title="Confirmation View"/><br/>Added an optional confirmation dialogue view to prevent accidental execution of actions on mistaken tap. This also brings a change in the JSON schema to allow an optional field to specify that the confirmation should be used for a menu item. As we are now maturing and adding features we have decided to mitigate breaking changes to the JSON schema by being more careful to adopt the Home Assistant schema (noting there is a 1:1 mapping between YAML and JSON). This change does deprecate the top level `service` tag in favour of `tag_action` containing multiple fields including `service` & `confirm`. Users should migrate to the new format for the new functionality, but the timescale for actual deprecation are long and undecided. |
|
||||
| 1.6 | Added a user configurable 'timeout' in seconds so that when no action is taken the application automatically closes, stopping the continuous polling for changes of status and hence saving the drain on the battery. This can be disabled with timeout=0. |
|
||||
| 1.7 | Added timeout to confirmation views so that when used for security devices it does not linger when left unconfirmed. Thanks to [Jan Schneider](https://github.com/j-a-n) for the contribution. Known bug for devices not supporting [`WatchUi.getCurrentView()`](https://developer.garmin.com/connect-iq/api-docs/Toybox/WatchUi.html#getCurrentView-instance_function) API call which is only available on API Level 3.4.0, e.g. Vivoactive 4S. |
|
||||
| 2.0 | A significant code base change to enable both a 'widget' version for older devices, e.g. Venu (1), and an application with a glance, e.g. Venu2. These two versions must now be distributed under separate application IDs, but they have the same code base. A further 20 more devices are now supported, the settings have been internationalised, and there's a bug fix for older devices when trying to display a helpful error message but instead the application crashed. This version has come from a significant collaboration with [Someone0nEarth](https://github.com/Someone0nEarth). |
|
||||
| 2.1 | Deployment of an idea to provide Home Assistant with access to the watch battery level. Using this requires [significant setup](BatteryReporting.md) on the Home Assistant configuration and hence is detailed separately. Due to this, the default state for this battery option is _off_. Changed the application settings user interface to be more intuitive, and hence amended the way settings are managed in the background. |
|
||||
| 2.2 | Adds a feature to cache the menu configuration and save the time taken for an HTTP request to fetch it. You as the user are responsible for managing the cache by clearing it when you update your configuration. Improvement to widget root display updates. Bug fix for battery level reporting when in the glance carousel. Fixed an uninternationalised string, "Execute". Unfixed issue with battery level updates when the user is not an administrator. |
|
||||
| 2.3 | Fix for battery level updates where previously the function only worked for administrator accounts. The new solution is based on Webhooks and is simpler to implement on Home Assistant. Language support fix where an automatic translation produced an inappropriate word, possibly in more than one language. |
|
||||
| 2.4 | Sensor status reporting via Home Assistant 'templates'. This provides a generalised way of viewing the status of any entity as long as the result can be rendered as text, e.g. 'uncovered', 'open', '76%', '21 °C'. Removal of the menu style option. The original style was kept after the introduction of the icon style solely to keep the code for a possible re-use for sensor statuses. This version delivers that new feature, hence the style option has been removed. The new JSON configuration file format allows for the old style to be replicated if you are desperate! |
|
||||
|
||||
## Known Issues
|
||||
|
||||
1. On some (old) devices (e.g. Vivoactive 3, Fenix 5s & Edge 520+), the menu does not update correctly to reflect changes in state effected by an external Home Assistant control. E.g. when the phone application changes the toggle status of a switch, the Garmin application does not reflect that change until the menu is touched or scrolled a little. This is a [known issue](https://forums.garmin.com/developer/connect-iq/i/bug-reports/menu2-doesn-t-allow-live-updates) already reported without a suggested software fix.
|
||||
|
||||
2. Widgets have less memory than applications. With the new template based sensor display, widgets are more likely to run out of memory. E.g. a Vivoactive 3 device has a memory limit of 60 kB runtime memory for widgets (compare with 124 kB for applications) and is likely to be ~90% used. This makes it very likely that a larger menu will crash the application. We cannot predict what will take the application "over the edge", but we can provide this feedback to users to raise awareness.
|
||||
2. Widgets have less memory than applications. With the new template based sensor display, widgets are more likely to run out of memory. E.g. a Vivoactive 3 device has a memory limit of 60 kB runtime memory for widgets (compared with 124 kB for applications) and memory is likely to be ~90% used. This makes it very likely that a larger menu will crash the application. We cannot predict what will take the application "over the edge", but we can provide this feedback to users to raise awareness, hence the widget displays menu usage as a reminder. If the widget is crashing but the application variant is not, then your menu configuration is too big for the widget. **Please don't give the application a poor review for crashing on your excessive menu definition!**
|
||||
|
||||
<img src="images/Venu_Widget_sim.png" width="200" title="Venu 2" style="margin:5px"/>
|
||||
<img src="images/app_crash.png" width="200" title="Venu 2" style="margin:5px;border: 2px solid black;"/>
|
||||
|
||||
3. Templates can require significant definition for highly customised text. Just remember, you have the ability to crash the application by creating an excessively long menu definition. Don't be silly.
|
||||
|
||||
4. Parameters to tap menu items cannot have their parameter usage verified. If you get this wrong and crash the application, that's your fault not the application's. In this case, start by removing the parameters for the menu item causing the crash, and add them back one at a time until you find your fault. **Please don't give the application a poor review for your bad parameter definition!**
|
||||
|
@ -1,3 +1,5 @@
|
||||
[Home](README.md) | [Switches](examples/Switches.md) | [Actions](examples/Actions.md) | [Templates](examples/Templates.md) | [Battery Reporting](BatteryReporting.md) | Trouble Shooting | [Version History](HISTORY.md)
|
||||
|
||||
# Troubleshooting Guides
|
||||
|
||||
## Watch Menu and API
|
||||
@ -26,7 +28,7 @@ Now you have to manage:
|
||||
- Dynamic DNS
|
||||
- Public access via router port forwarding
|
||||
- Security via HTTPS and URL forwarding
|
||||
- Certificates for HTTPS via say [Let's Encrypt](https://letsencrypt.org/) (Nginx web server helps here)
|
||||
- Certificates for HTTPS via say [Let's Encrypt](https://letsencrypt.org/) (an Nginx proxy web server helps here)
|
||||
- Proxy allow list in `configuration.yaml` as follows:
|
||||
|
||||
```yaml
|
||||
@ -34,10 +36,10 @@ http:
|
||||
use_x_forwarded_for: true
|
||||
trusted_proxies:
|
||||
- 127.0.0.1
|
||||
- 192.168.xx.xx # Server IP - AMEND THIS
|
||||
- 192.168.xx.xx # Server IP - AMEND THIS
|
||||
- 172.30.32.0/23 # Docker IPs for NGINX
|
||||
- 172.30.33.0/24 # SSL proxy server
|
||||
- 172.16.0.0/12 #
|
||||
- 172.16.0.0/12 #
|
||||
```
|
||||
|
||||
### Menu Configuration URL
|
@ -27,10 +27,16 @@ set /p SDK_PATH=<"%USERPROFILE%\AppData\Roaming\Garmin\ConnectIQ\current-sdk.cfg
|
||||
set SDK_PATH=%SDK_PATH:~0,-1%\bin
|
||||
rem Assume we can create and use this directory
|
||||
set DEST=export
|
||||
|
||||
rem Device for simulation
|
||||
rem set DEVICE=venu2
|
||||
set DEVICE=vivoactive3
|
||||
|
||||
rem Application
|
||||
rem set JUNGLE=monkey.jungle
|
||||
rem Or Widget
|
||||
set JUNGLE=monkey-widget.jungle
|
||||
|
||||
rem C:\>java -jar %SDK_PATH%\monkeybrains.jar -h
|
||||
rem usage: monkeyc [-a <arg>] [-b <arg>] [--build-stats <arg>] [-c <arg>] [-d <arg>]
|
||||
rem [--debug-log-level <arg>] [--debug-log-output <arg>] [-e]
|
||||
@ -98,7 +104,7 @@ rem Compile PRG for a single device for side loading
|
||||
-Dapple.awt.UIElement=true ^
|
||||
-jar %SDK_PATH%\monkeybrains.jar ^
|
||||
--output %SRC%\bin\HomeAssistant.prg ^
|
||||
--jungles %SRC%\monkey.jungle ^
|
||||
--jungles %SRC%\monkey-widget.jungle ^
|
||||
--private-key %SRC%\..\developer_key ^
|
||||
--device %DEVICE%_sim ^
|
||||
--warn ^
|
||||
|
@ -8,9 +8,12 @@
|
||||
"items": {
|
||||
"$ref": "#/$defs/items"
|
||||
},
|
||||
"required": ["title", "items"],
|
||||
"additionalProperties": false
|
||||
"$schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": ["title", "items"],
|
||||
"additionalProperties": false,
|
||||
"$defs": {
|
||||
"toggle": {
|
||||
"type": "object",
|
||||
@ -106,15 +109,18 @@
|
||||
"properties": {
|
||||
"entity": {
|
||||
"$ref": "#/$defs/entity",
|
||||
"type": "string",
|
||||
"pattern": "^[^.]+\\.[^.]+$",
|
||||
"deprecated": true,
|
||||
"title": "Schema change:",
|
||||
"description": "'entity' is no longer necessary and should be removed."
|
||||
"description": "'entity' is no longer necessary and should now be removed."
|
||||
},
|
||||
"name": {
|
||||
"title": "Your familiar name",
|
||||
"title": "Menu item's familiar name.",
|
||||
"type": "string"
|
||||
},
|
||||
"title": {
|
||||
"title": "Sub menu's title once displayed.",
|
||||
"type": "string"
|
||||
},
|
||||
"type": {
|
||||
@ -131,6 +137,7 @@
|
||||
},
|
||||
"items": {
|
||||
"type": "array",
|
||||
"maxItems": 16,
|
||||
"items": {
|
||||
"oneOf": [
|
||||
{
|
||||
@ -149,23 +156,29 @@
|
||||
}
|
||||
},
|
||||
"entity": {
|
||||
"title": "Home Assistant entity name",
|
||||
"type": "string",
|
||||
"title": "Home Assistant entity name",
|
||||
"pattern": "^[^.]+\\.[^.]+$"
|
||||
},
|
||||
"service": {
|
||||
"type": "string",
|
||||
"title": "Home Assistant service name",
|
||||
"pattern": "^[^.]+\\.[^.]+$"
|
||||
},
|
||||
"tap_action": {
|
||||
"type": "object",
|
||||
"title": "Action",
|
||||
"description": "'confirm' field is optional.",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"service": {
|
||||
"$ref": "#/$defs/entity"
|
||||
"$ref": "#/$defs/service"
|
||||
},
|
||||
"confirm": {
|
||||
"$ref": "#/$defs/confirm"
|
||||
},
|
||||
"data": {
|
||||
"type": "object",
|
||||
"title": "Your services's parameters",
|
||||
"description": "The object containing the parameters and their values to be passed to the entity. No schema checking can be done here, you are on your own! On application crash, remove the parameters."
|
||||
}
|
||||
},
|
||||
@ -174,7 +187,8 @@
|
||||
"confirm": {
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"description": "Confirm the action before execution as a precaution."
|
||||
"title": "Confirmation",
|
||||
"description": "Optional confirmation of the action before execution as a precaution."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
56
examples/Actions.md
Normal file
56
examples/Actions.md
Normal file
@ -0,0 +1,56 @@
|
||||
[Home](../README.md) | [Switches](Switches.md) | Actions | [Templates](Templates.md) | [Battery Reporting](../BatteryReporting.md) | [Trouble Shooting](../TroubleShooting.md) | [Version History](../HISTORY.md)
|
||||
|
||||
# Actions
|
||||
|
||||
A simple example using a scene as a `tap`` menu item.
|
||||
|
||||
```json
|
||||
{
|
||||
"entity": "scene.telly_watching",
|
||||
"name": "Telly Scene",
|
||||
"type": "tap",
|
||||
"tap_action": {
|
||||
"service": "scene.turn_on"
|
||||
}
|
||||
},
|
||||
```
|
||||
|
||||
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.
|
||||
|
||||
```json
|
||||
"tap_action": {
|
||||
"confirm": true
|
||||
}
|
||||
```
|
||||
|
||||
<img src="../images/confirmation_view.png" width="200" title="Confirmation View"/>
|
||||
|
||||
For example:
|
||||
|
||||
```json
|
||||
{
|
||||
"entity": "switch.garage_door",
|
||||
"name": "Garage Door",
|
||||
"type": "toggle",
|
||||
"tap_action": {
|
||||
"confirm": true
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Note that for notify events, you _must_ not supply an `entity_id` or the API call will fail. There are other examples too.
|
||||
|
||||
```json
|
||||
{
|
||||
"name": "Message",
|
||||
"type": "tap",
|
||||
"tap_action": {
|
||||
"service": "notify.mobile_app_on_phone",
|
||||
"data": {
|
||||
"title": "This is a title",
|
||||
"message": "This is the message"
|
||||
},
|
||||
"confirm": true
|
||||
}
|
||||
}
|
||||
```
|
73
examples/Switches.md
Normal file
73
examples/Switches.md
Normal file
@ -0,0 +1,73 @@
|
||||
[Home](../README.md) | Switches | [Actions](Actions.md) | [Templates](Templates.md) | [Battery Reporting](../BatteryReporting.md) | [Trouble Shooting](../TroubleShooting.md) | [Version History](../HISTORY.md)
|
||||
|
||||
# Switches
|
||||
|
||||
This is the simplest form:
|
||||
|
||||
```json
|
||||
{
|
||||
"entity": "light.bedside_light_switch",
|
||||
"name": "Bedroom Light",
|
||||
"type": "toggle"
|
||||
},
|
||||
```
|
||||
|
||||
To support a non-standard light, switch, or automation as a toggle menu item you may like to define a custom switch. In order to facilitate custom switches at this time, you must create a template switch in HomeAssistant.
|
||||
|
||||
```yaml
|
||||
switch:
|
||||
- platform: template
|
||||
switches:
|
||||
<switch-name>:
|
||||
friendly_name: <name>
|
||||
value_template: <value>
|
||||
turn_on:
|
||||
service: <service>
|
||||
data:
|
||||
entity_id: <entity>
|
||||
<attribute>: <value>
|
||||
turn_off:
|
||||
service: <service>
|
||||
data:
|
||||
entity_id: <entity>
|
||||
<attribute>: <value>
|
||||
```
|
||||
|
||||
Then you can use the following in your config:
|
||||
|
||||
```json
|
||||
{
|
||||
"entity": "switch.<switch-name>",
|
||||
"name": "<name>",
|
||||
"type": "toggle"
|
||||
}
|
||||
```
|
||||
|
||||
## Example - Covers
|
||||
|
||||
```yaml
|
||||
switch:
|
||||
- platform: template
|
||||
switches:
|
||||
cover:
|
||||
friendly_name: Cover
|
||||
value_template: "{{ is_state('cover.cover', 'open') }}"
|
||||
turn_on:
|
||||
service: cover.open_cover
|
||||
data:
|
||||
entity_id: cover.cover
|
||||
turn_off:
|
||||
service: cover.close_cover
|
||||
data:
|
||||
entity_id: cover.cover
|
||||
```
|
||||
|
||||
Then you can use the following in your config:
|
||||
|
||||
```json
|
||||
{
|
||||
"entity": "switch.cover",
|
||||
"name": "Cover",
|
||||
"type": "toggle"
|
||||
}
|
||||
```
|
163
examples/Templates.md
Normal file
163
examples/Templates.md
Normal file
@ -0,0 +1,163 @@
|
||||
[Home](../README.md) | [Switches](Switches.md) | [Actions](Actions.md) | Templates | [Battery Reporting](../BatteryReporting.md) | [Trouble Shooting](../TroubleShooting.md) | [Version History](../HISTORY.md)
|
||||
|
||||
# Templates
|
||||
|
||||
In order to provide the most functionality possible the content of the menu item comes from a user-defined template (i.e. you generate your own text). This allows you to do some pretty cool things. It also makes the config a bit more complicated. This page will help you understand how to use templates.
|
||||
|
||||
- In this file anything between `<` and `>` is a placeholder. Replace it with the appropriate value.
|
||||
- Anything between `{{` and `}}` is a template. Templates are used to dynamically insert values into the content. For more info see [the docs](https://www.home-assistant.io/docs/configuration/templating/).
|
||||
|
||||
## States
|
||||
|
||||
In this example we get the battery level of the device and add the percent sign. *Very simple*
|
||||
|
||||
```json
|
||||
{
|
||||
"entity": "sensor.<device>_battery_level",
|
||||
"name": "Phone",
|
||||
"type": "template",
|
||||
"content": "{{ states('sensor.<device>_battery_level') }}%"
|
||||
}
|
||||
```
|
||||
|
||||
### Examples
|
||||
|
||||
The first two keep to the simple proposal above. The last combines them into a single menu item. Now you can start to see the utility of this menu item, composing your own formatted text.
|
||||
|
||||
```json
|
||||
{
|
||||
"entity": "sensor.hallway_temperature",
|
||||
"name": "Hall Temp",
|
||||
"type": "template",
|
||||
"content": "{{ states('sensor.hallway_temperature') }}°C"
|
||||
},
|
||||
{
|
||||
"entity": "sensor.hallway_humidity",
|
||||
"name": "Hall Humidity",
|
||||
"type": "template",
|
||||
"content": "{{ states('sensor.hallway_humidity') }}%"
|
||||
},
|
||||
{
|
||||
"entity": "sensor.hallway_temperature",
|
||||
"name": "Hallway",
|
||||
"type": "template",
|
||||
"content": "{{ states('sensor.hallway_temperature') }}°C {{ states('sensor.hallway_humidity') }}%"
|
||||
}
|
||||
```
|
||||
|
||||
## Conditionals
|
||||
|
||||
Anything between `{%` and `%}` is a directive (`if`, `else`, `elif`, `endif`, etc.). Conditionals are used to dynamically change the content based on the state of the entity.
|
||||
|
||||
In this example we get the battery level of the device and add the percent sign. If the device is charging we add a plus sign.
|
||||
|
||||
```json
|
||||
{
|
||||
"entity": "sensor.<device>_battery_level",
|
||||
"name": "Phone",
|
||||
"type": "template",
|
||||
"content": "{{ states('sensor.<device>_battery_level') }}%{% if is_state('binary_sensor.<device>_is_charging', 'on') %}+{% endif %}"
|
||||
}
|
||||
```
|
||||
|
||||
Here we also use the else clause as well to give proper text instead of just `on` or `off`.
|
||||
|
||||
```json
|
||||
{
|
||||
"entity": "binary_sensor.garage_doors",
|
||||
"name": "Garage Doors",
|
||||
"type": "template",
|
||||
"content": "{% if is_state('binary_sensor.<door-0>', 'on') %}Open{% else %}Closed{% endif %} {% if is_state('binary_sensor.<door-1>', 'on') %}Open{% else %}Closed{% endif %}"
|
||||
}
|
||||
```
|
||||
|
||||
## Advanced
|
||||
|
||||
Here we generate a bar graph of the battery level. We use the following steps to do this:
|
||||
|
||||
- Convert the state to a number.
|
||||
- Divide by 100 to get a fraction.
|
||||
- Multiply by the width to get the number of `#`s.
|
||||
- Multiply by the `#` char to make a string.
|
||||
- Subtract the width from the number of `#`s to get the number of `_`s.
|
||||
- Multiply by the `_` char to make a string.
|
||||
|
||||
```json
|
||||
{
|
||||
"entity": "sensor.<device>_battery_level",
|
||||
"name": "Phone",
|
||||
"type": "template",
|
||||
"content": "{{ states('sensor.<device>_battery_level') }}%{% if is_state('binary_sensor.<device>_is_charging', 'on') %}+{% endif %} {{ '#' * (((states('sensor.<device>_battery_level') | int) / 100 * <width>) | int) }}{{ '_' * (<width> - (((states('sensor.<device>_battery_level') | int) / 100 * <width>) | int)) }}"
|
||||
}
|
||||
```
|
||||
|
||||
An example of a dimmer light with 4 brightness settings 0..3. Here our light worked on a percentage, so that had to be converted to the range 0..3.
|
||||
|
||||
```json
|
||||
{
|
||||
"$schema": "./schema.json",
|
||||
"title": "Home",
|
||||
"items": [
|
||||
{
|
||||
"entity": "light.green_house",
|
||||
"name": "LEDs",
|
||||
"type": "template",
|
||||
"content": "{% if not (is_state('light.green_house', 'off') or is_state('light.green_house', 'unavailable')) %}{{ ((state_attr('light.green_house', 'brightness') | float) / 255 * 100) | int }}%{% else %}Off{% endif %}"
|
||||
},
|
||||
{
|
||||
"entity": "light.green_house",
|
||||
"name": "LEDs 0",
|
||||
"type": "template",
|
||||
"content": "{% if not (is_state('light.green_house', 'off') or is_state('light.green_house', 'unavailable')) %}{{ ((state_attr('light.green_house', 'brightness') | float) / 255 * 100) | int }}%{% else %}Off{% endif %}",
|
||||
"tap_action": {
|
||||
"service": "light.turn_on",
|
||||
"data": {
|
||||
"brightness_pct": 12
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"entity": "light.green_house",
|
||||
"name": "LEDs 1",
|
||||
"type": "tap",
|
||||
"tap_action": {
|
||||
"service": "light.turn_on",
|
||||
"data": {
|
||||
"brightness_pct": 37
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"entity": "light.green_house",
|
||||
"name": "LEDs 2",
|
||||
"type": "template",
|
||||
"content": "{% if not (is_state('light.green_house', 'off') or is_state('light.green_house', 'unavailable')) %}{{ ((state_attr('light.green_house', 'brightness') | float) / 255 * 100) | int }}%{% else %}Off{% endif %}",
|
||||
"tap_action": {
|
||||
"service": "light.turn_on",
|
||||
"data": {
|
||||
"brightness_pct": 62
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"entity": "light.green_house",
|
||||
"name": "LEDs 3",
|
||||
"type": "template",
|
||||
"content": "{% if not (is_state('light.green_house', 'off') or is_state('light.green_house', 'unavailable')) %}{{ ((state_attr('light.green_house', 'brightness') | float) / 255 * 100) | int }}%{% else %}Off{% endif %}",
|
||||
"tap_action": {
|
||||
"service": "light.turn_on",
|
||||
"data": {
|
||||
"brightness_pct": 87
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
## Warnings
|
||||
|
||||
Just remember, **you have the ability to crash the application by creating an excessive menu definition**. Older devices running as a widget can be limited in memory such that the JSON definition causes an "Out of Memory" error. Widgets have less memory than applications. Templates can require significant definition for highly customised text. Don't be silly. With the new template based sensor display, widgets are more likely to run out of memory. E.g. a Vivoactive 3 device has a memory limit of 60 kB runtime memory for widgets (compared with 124 kB for applications) and is likely to be ~90% used. This makes it very likely that a larger menu will crash the application. We cannot predict what will take the application "over the edge", but we can provide this feedback to users to raise awareness, hence the widget displays menu usage as a reminder. If the widget is crashing but the application variant is not, then your menu configuration is too big for the widget.
|
||||
|
||||
<img src="../images/Venu_Widget_sim.png" width="200" title="Venu 2" style="margin:5px"/>
|
||||
<img src="../images/app_crash.png" width="200" title="Venu 2" style="margin:5px;border: 2px solid black;"/>
|
Binary file not shown.
Before Width: | Height: | Size: 806 KiB After Width: | Height: | Size: 764 KiB |
Binary file not shown.
Before Width: | Height: | Size: 5.2 KiB After Width: | Height: | Size: 2.7 KiB |
BIN
images/app_crash.png
Normal file
BIN
images/app_crash.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.2 KiB |
BIN
images/toggle_icon.png
Normal file
BIN
images/toggle_icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.1 KiB |
@ -32,22 +32,16 @@ class BackgroundServiceDelegate extends System.ServiceDelegate {
|
||||
}
|
||||
|
||||
function onReturnBatteryUpdate(responseCode as Lang.Number, data as Null or Lang.Dictionary or Lang.String) as Void {
|
||||
if (Globals.scDebug) {
|
||||
System.println("BackgroundServiceDelegate onReturnBatteryUpdate() Response Code: " + responseCode);
|
||||
System.println("BackgroundServiceDelegate onReturnBatteryUpdate() Response Data: " + data);
|
||||
}
|
||||
// System.println("BackgroundServiceDelegate onReturnBatteryUpdate() Response Code: " + responseCode);
|
||||
// System.println("BackgroundServiceDelegate onReturnBatteryUpdate() Response Data: " + data);
|
||||
Background.exit(null);
|
||||
}
|
||||
|
||||
function onTemporalEvent() as Void {
|
||||
if (! System.getDeviceSettings().phoneConnected) {
|
||||
if (Globals.scDebug) {
|
||||
System.println("BackgroundServiceDelegate onTemporalEvent(): No Phone connection, skipping API call.");
|
||||
}
|
||||
// System.println("BackgroundServiceDelegate onTemporalEvent(): No Phone connection, skipping API call.");
|
||||
} else if (! System.getDeviceSettings().connectionAvailable) {
|
||||
if (Globals.scDebug) {
|
||||
System.println("BackgroundServiceDelegate onTemporalEvent(): No Internet connection, skipping API call.");
|
||||
}
|
||||
// System.println("BackgroundServiceDelegate onTemporalEvent(): No Internet connection, skipping API call.");
|
||||
} else {
|
||||
// Don't use Settings.* here as the object lasts < 30 secs and is recreated each time the background service is run
|
||||
Communications.makeWebRequest(
|
||||
@ -56,13 +50,13 @@ class BackgroundServiceDelegate extends System.ServiceDelegate {
|
||||
"type" => "update_sensor_states",
|
||||
"data" => [
|
||||
{
|
||||
"state" => System.getSystemStats().battery,
|
||||
"type" => "sensor",
|
||||
"state" => System.getSystemStats().battery,
|
||||
"type" => "sensor",
|
||||
"unique_id" => "battery_level"
|
||||
},
|
||||
{
|
||||
"state" => System.getSystemStats().charging,
|
||||
"type" => "binary_sensor",
|
||||
"state" => System.getSystemStats().charging,
|
||||
"type" => "binary_sensor",
|
||||
"unique_id" => "battery_is_charging"
|
||||
}
|
||||
]
|
||||
@ -70,7 +64,7 @@ class BackgroundServiceDelegate extends System.ServiceDelegate {
|
||||
{
|
||||
: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
|
||||
},
|
||||
|
@ -22,9 +22,6 @@ using Toybox.Lang;
|
||||
|
||||
(:glance)
|
||||
class Globals {
|
||||
// Enable printing of messages to the debug console (don't make this a Property
|
||||
// as the messages can't be read from a watch!)
|
||||
static const scDebug = false;
|
||||
static const scAlertTimeout = 2000; // ms
|
||||
static const scTapTimeout = 1000; // ms
|
||||
// Time to let the existing HTTP responses get serviced after a
|
||||
@ -34,5 +31,5 @@ class Globals {
|
||||
// an ErrorView.
|
||||
static const scApiResume = 200; // ms
|
||||
// Warn the user after fetching the menu if their watch is low on memory before the device crashes.
|
||||
static const scLowMem = 0.95; // percent as a fraction.
|
||||
static const scLowMem = 0.90; // percent as a fraction.
|
||||
}
|
||||
|
@ -32,8 +32,9 @@ class HomeAssistantApp extends Application.AppBase {
|
||||
private var mHaMenu as HomeAssistantView or Null;
|
||||
private var mQuitTimer as QuitTimer or Null;
|
||||
private var mTimer as Timer.Timer or Null;
|
||||
private var mItemsToUpdate as Lang.Array<HomeAssistantToggleMenuItem or HomeAssistantTemplateMenuItem> or Null; // Array initialised by onReturnFetchMenuConfig()
|
||||
private var mNextItemToUpdate as Lang.Number = 0; // Index into the above array
|
||||
// Array initialised by onReturnFetchMenuConfig()
|
||||
private var mItemsToUpdate as Lang.Array<HomeAssistantToggleMenuItem or HomeAssistantTemplateMenuItem> or Null;
|
||||
private var mNextItemToUpdate as Lang.Number = 0; // Index into the above array
|
||||
private var mIsGlance as Lang.Boolean = false;
|
||||
private var mIsApp as Lang.Boolean = false; // Or Widget
|
||||
|
||||
@ -88,41 +89,29 @@ class HomeAssistantApp extends Application.AppBase {
|
||||
function getInitialView() as Lang.Array<WatchUi.Views or WatchUi.InputDelegates>? {
|
||||
mIsApp = true;
|
||||
mQuitTimer = new QuitTimer();
|
||||
RezStrings.update();
|
||||
mApiStatus = RezStrings.getChecking();
|
||||
mMenuStatus = RezStrings.getChecking();
|
||||
// RezStrings.update();
|
||||
mApiStatus = WatchUi.loadResource($.Rez.Strings.Checking) as Lang.String;
|
||||
mMenuStatus = WatchUi.loadResource($.Rez.Strings.Checking) as Lang.String;
|
||||
Settings.update();
|
||||
|
||||
if (Settings.getApiKey().length() == 0) {
|
||||
if (Globals.scDebug) {
|
||||
System.println("HomeAssistantApp getInitialView(): No API key in the application Settings.");
|
||||
}
|
||||
return ErrorView.create(RezStrings.getNoApiKey() + ".");
|
||||
// System.println("HomeAssistantApp getInitialView(): No API key in the application Settings.");
|
||||
return ErrorView.create(WatchUi.loadResource($.Rez.Strings.NoAPIKey) as Lang.String + ".");
|
||||
} else if (Settings.getApiUrl().length() == 0) {
|
||||
if (Globals.scDebug) {
|
||||
System.println("HomeAssistantApp getInitialView(): No API URL in the application Settings.");
|
||||
}
|
||||
return ErrorView.create(RezStrings.getNoApiUrl() + ".");
|
||||
// System.println("HomeAssistantApp getInitialView(): No API URL in the application Settings.");
|
||||
return ErrorView.create(WatchUi.loadResource($.Rez.Strings.NoApiUrl) as Lang.String + ".");
|
||||
} else if (Settings.getApiUrl().substring(-1, Settings.getApiUrl().length()).equals("/")) {
|
||||
if (Globals.scDebug) {
|
||||
System.println("HomeAssistantApp getInitialView(): API URL must not have a trailing slash '/'.");
|
||||
}
|
||||
return ErrorView.create(RezStrings.getTrailingSlashErr() + ".");
|
||||
// System.println("HomeAssistantApp getInitialView(): API URL must not have a trailing slash '/'.");
|
||||
return ErrorView.create(WatchUi.loadResource($.Rez.Strings.TrailingSlashErr) as Lang.String + ".");
|
||||
} else if (Settings.getConfigUrl().length() == 0) {
|
||||
if (Globals.scDebug) {
|
||||
System.println("HomeAssistantApp getInitialView(): No configuration URL in the application settings.");
|
||||
}
|
||||
return ErrorView.create(RezStrings.getNoConfigUrl() + ".");
|
||||
// System.println("HomeAssistantApp getInitialView(): No configuration URL in the application settings.");
|
||||
return ErrorView.create(WatchUi.loadResource($.Rez.Strings.NoConfigUrl) as Lang.String + ".");
|
||||
} else if (! System.getDeviceSettings().phoneConnected) {
|
||||
if (Globals.scDebug) {
|
||||
System.println("HomeAssistantApp fetchMenuConfig(): No Phone connection, skipping API call.");
|
||||
}
|
||||
return ErrorView.create(RezStrings.getNoPhone() + ".");
|
||||
// System.println("HomeAssistantApp fetchMenuConfig(): No Phone connection, skipping API call.");
|
||||
return ErrorView.create(WatchUi.loadResource($.Rez.Strings.NoPhone) as Lang.String + ".");
|
||||
} else if (! System.getDeviceSettings().connectionAvailable) {
|
||||
if (Globals.scDebug) {
|
||||
System.println("HomeAssistantApp fetchMenuConfig(): No Internet connection, skipping API call.");
|
||||
}
|
||||
return ErrorView.create(RezStrings.getNoInternet() + ".");
|
||||
// System.println("HomeAssistantApp fetchMenuConfig(): No Internet connection, skipping API call.");
|
||||
return ErrorView.create(WatchUi.loadResource($.Rez.Strings.NoInternet) as Lang.String + ".");
|
||||
} else {
|
||||
var isCached = fetchMenuConfig();
|
||||
fetchApiStatus();
|
||||
@ -142,65 +131,53 @@ class HomeAssistantApp extends Application.AppBase {
|
||||
//
|
||||
(:glance)
|
||||
function onReturnFetchMenuConfig(responseCode as Lang.Number, data as Null or Lang.Dictionary or Lang.String) as Void {
|
||||
if (Globals.scDebug) {
|
||||
System.println("HomeAssistantApp onReturnFetchMenuConfig() Response Code: " + responseCode);
|
||||
System.println("HomeAssistantApp onReturnFetchMenuConfig() Response Data: " + data);
|
||||
}
|
||||
// System.println("HomeAssistantApp onReturnFetchMenuConfig() Response Code: " + responseCode);
|
||||
// System.println("HomeAssistantApp onReturnFetchMenuConfig() Response Data: " + data);
|
||||
|
||||
mMenuStatus = RezStrings.getUnavailable();
|
||||
mMenuStatus = WatchUi.loadResource($.Rez.Strings.Unavailable) as Lang.String;
|
||||
switch (responseCode) {
|
||||
case Communications.BLE_HOST_TIMEOUT:
|
||||
case Communications.BLE_CONNECTION_UNAVAILABLE:
|
||||
if (Globals.scDebug) {
|
||||
System.println("HomeAssistantApp onReturnFetchMenuConfig() Response Code: BLE_HOST_TIMEOUT or BLE_CONNECTION_UNAVAILABLE, Bluetooth connection severed.");
|
||||
}
|
||||
// System.println("HomeAssistantApp onReturnFetchMenuConfig() Response Code: BLE_HOST_TIMEOUT or BLE_CONNECTION_UNAVAILABLE, Bluetooth connection severed.");
|
||||
if (!mIsGlance) {
|
||||
ErrorView.show(RezStrings.getNoPhone() + ".");
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.NoPhone) as Lang.String + ".");
|
||||
}
|
||||
break;
|
||||
|
||||
case Communications.BLE_QUEUE_FULL:
|
||||
if (Globals.scDebug) {
|
||||
System.println("HomeAssistantApp onReturnFetchMenuConfig() Response Code: BLE_QUEUE_FULL, API calls too rapid.");
|
||||
}
|
||||
// System.println("HomeAssistantApp onReturnFetchMenuConfig() Response Code: BLE_QUEUE_FULL, API calls too rapid.");
|
||||
if (!mIsGlance) {
|
||||
ErrorView.show(RezStrings.getApiFlood());
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.ApiFlood) as Lang.String);
|
||||
}
|
||||
break;
|
||||
|
||||
case Communications.NETWORK_REQUEST_TIMED_OUT:
|
||||
if (Globals.scDebug) {
|
||||
System.println("HomeAssistantApp onReturnFetchMenuConfig() Response Code: NETWORK_REQUEST_TIMED_OUT, check Internet connection.");
|
||||
}
|
||||
// System.println("HomeAssistantApp onReturnFetchMenuConfig() Response Code: NETWORK_REQUEST_TIMED_OUT, check Internet connection.");
|
||||
if (!mIsGlance) {
|
||||
ErrorView.show(RezStrings.getNoResponse());
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.NoResponse) as Lang.String);
|
||||
}
|
||||
break;
|
||||
|
||||
case Communications.INVALID_HTTP_BODY_IN_NETWORK_RESPONSE:
|
||||
if (Globals.scDebug) {
|
||||
System.println("HomeAssistantApp onReturnFetchMenuConfig() Response Code: INVALID_HTTP_BODY_IN_NETWORK_RESPONSE, check JSON is returned.");
|
||||
}
|
||||
// System.println("HomeAssistantApp onReturnFetchMenuConfig() Response Code: INVALID_HTTP_BODY_IN_NETWORK_RESPONSE, check JSON is returned.");
|
||||
if (!mIsGlance) {
|
||||
ErrorView.show(RezStrings.getNoJson());
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.NoJson) as Lang.String);
|
||||
}
|
||||
break;
|
||||
|
||||
case 404:
|
||||
if (Globals.scDebug) {
|
||||
System.println("HomeAssistantApp onReturnFetchMenuConfig() Response Code: 404, page not found. Check Configuration URL setting.");
|
||||
}
|
||||
// System.println("HomeAssistantApp onReturnFetchMenuConfig() Response Code: 404, page not found. Check Configuration URL setting.");
|
||||
if (!mIsGlance) {
|
||||
ErrorView.show(RezStrings.getConfigUrlNotFound());
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.ConfigUrlNotFound) as Lang.String);
|
||||
}
|
||||
break;
|
||||
|
||||
case 200:
|
||||
if (Settings.getCacheConfig()) {
|
||||
Storage.setValue("menu", data as Lang.Dictionary);
|
||||
mMenuStatus = RezStrings.getCached();
|
||||
mMenuStatus = WatchUi.loadResource($.Rez.Strings.Cached) as Lang.String;
|
||||
} else {
|
||||
mMenuStatus = RezStrings.getAvailable();
|
||||
mMenuStatus = WatchUi.loadResource($.Rez.Strings.Available) as Lang.String;
|
||||
}
|
||||
if (!mIsGlance) {
|
||||
buildMenu(data);
|
||||
@ -211,11 +188,9 @@ class HomeAssistantApp extends Application.AppBase {
|
||||
break;
|
||||
|
||||
default:
|
||||
if (Globals.scDebug) {
|
||||
System.println("HomeAssistantApp onReturnFetchMenuConfig(): Unhandled HTTP response code = " + responseCode);
|
||||
}
|
||||
// System.println("HomeAssistantApp onReturnFetchMenuConfig(): Unhandled HTTP response code = " + responseCode);
|
||||
if (!mIsGlance) {
|
||||
ErrorView.show(RezStrings.getUnhandledHttpErr() + responseCode);
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.UnhandledHttpErr) as Lang.String + responseCode);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -227,7 +202,7 @@ class HomeAssistantApp extends Application.AppBase {
|
||||
(:glance)
|
||||
function fetchMenuConfig() as Lang.Boolean {
|
||||
if (Settings.getConfigUrl().equals("")) {
|
||||
mMenuStatus = RezStrings.getUnconfigured();
|
||||
mMenuStatus = WatchUi.loadResource($.Rez.Strings.Unconfigured) as Lang.String;
|
||||
WatchUi.requestUpdate();
|
||||
} else {
|
||||
var menu = Storage.getValue("menu") as Lang.Dictionary;
|
||||
@ -238,25 +213,21 @@ class HomeAssistantApp extends Application.AppBase {
|
||||
}
|
||||
if (menu == null) {
|
||||
if (! System.getDeviceSettings().phoneConnected) {
|
||||
if (Globals.scDebug) {
|
||||
System.println("HomeAssistantToggleMenuItem getState(): No Phone connection, skipping API call.");
|
||||
}
|
||||
// System.println("HomeAssistantToggleMenuItem getState(): No Phone connection, skipping API call.");
|
||||
if (mIsGlance) {
|
||||
WatchUi.requestUpdate();
|
||||
} else {
|
||||
ErrorView.show(RezStrings.getNoPhone() + ".");
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.NoPhone) as Lang.String + ".");
|
||||
}
|
||||
mMenuStatus = RezStrings.getUnavailable();
|
||||
mMenuStatus = WatchUi.loadResource($.Rez.Strings.Unavailable) as Lang.String;
|
||||
} else if (! System.getDeviceSettings().connectionAvailable) {
|
||||
if (Globals.scDebug) {
|
||||
System.println("HomeAssistantToggleMenuItem getState(): No Internet connection, skipping API call.");
|
||||
}
|
||||
// System.println("HomeAssistantToggleMenuItem getState(): No Internet connection, skipping API call.");
|
||||
if (mIsGlance) {
|
||||
WatchUi.requestUpdate();
|
||||
} else {
|
||||
ErrorView.show(RezStrings.getNoInternet() + ".");
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.NoInternet) as Lang.String + ".");
|
||||
}
|
||||
mMenuStatus = RezStrings.getUnavailable();
|
||||
mMenuStatus = WatchUi.loadResource($.Rez.Strings.Unavailable) as Lang.String;
|
||||
} else {
|
||||
Communications.makeWebRequest(
|
||||
Settings.getConfigUrl(),
|
||||
@ -269,7 +240,7 @@ class HomeAssistantApp extends Application.AppBase {
|
||||
);
|
||||
}
|
||||
} else {
|
||||
mMenuStatus = RezStrings.getCached();
|
||||
mMenuStatus = WatchUi.loadResource($.Rez.Strings.Cached) as Lang.String;
|
||||
WatchUi.requestUpdate();
|
||||
if (!mIsGlance) {
|
||||
buildMenu(menu);
|
||||
@ -301,56 +272,44 @@ class HomeAssistantApp extends Application.AppBase {
|
||||
//
|
||||
(:glance)
|
||||
function onReturnFetchApiStatus(responseCode as Lang.Number, data as Null or Lang.Dictionary or Lang.String) as Void {
|
||||
if (Globals.scDebug) {
|
||||
System.println("HomeAssistantApp onReturnFetchApiStatus() Response Code: " + responseCode);
|
||||
System.println("HomeAssistantApp onReturnFetchApiStatus() Response Data: " + data);
|
||||
}
|
||||
// System.println("HomeAssistantApp onReturnFetchApiStatus() Response Code: " + responseCode);
|
||||
// System.println("HomeAssistantApp onReturnFetchApiStatus() Response Data: " + data);
|
||||
|
||||
mApiStatus = RezStrings.getUnavailable();
|
||||
mApiStatus = WatchUi.loadResource($.Rez.Strings.Unavailable) as Lang.String;
|
||||
switch (responseCode) {
|
||||
case Communications.BLE_HOST_TIMEOUT:
|
||||
case Communications.BLE_CONNECTION_UNAVAILABLE:
|
||||
if (Globals.scDebug) {
|
||||
System.println("HomeAssistantApp onReturnFetchApiStatus() Response Code: BLE_HOST_TIMEOUT or BLE_CONNECTION_UNAVAILABLE, Bluetooth connection severed.");
|
||||
}
|
||||
// System.println("HomeAssistantApp onReturnFetchApiStatus() Response Code: BLE_HOST_TIMEOUT or BLE_CONNECTION_UNAVAILABLE, Bluetooth connection severed.");
|
||||
if (!mIsGlance) {
|
||||
ErrorView.show(RezStrings.getNoPhone() + ".");
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.NoPhone) as Lang.String + ".");
|
||||
}
|
||||
break;
|
||||
|
||||
case Communications.BLE_QUEUE_FULL:
|
||||
if (Globals.scDebug) {
|
||||
System.println("HomeAssistantApp onReturnFetchApiStatus() Response Code: BLE_QUEUE_FULL, API calls too rapid.");
|
||||
}
|
||||
// System.println("HomeAssistantApp onReturnFetchApiStatus() Response Code: BLE_QUEUE_FULL, API calls too rapid.");
|
||||
if (!mIsGlance) {
|
||||
ErrorView.show(RezStrings.getApiFlood());
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.ApiFlood) as Lang.String);
|
||||
}
|
||||
break;
|
||||
|
||||
case Communications.NETWORK_REQUEST_TIMED_OUT:
|
||||
if (Globals.scDebug) {
|
||||
System.println("HomeAssistantApp onReturnFetchApiStatus() Response Code: NETWORK_REQUEST_TIMED_OUT, check Internet connection.");
|
||||
}
|
||||
// System.println("HomeAssistantApp onReturnFetchApiStatus() Response Code: NETWORK_REQUEST_TIMED_OUT, check Internet connection.");
|
||||
if (!mIsGlance) {
|
||||
ErrorView.show(RezStrings.getNoResponse());
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.NoResponse) as Lang.String);
|
||||
}
|
||||
break;
|
||||
|
||||
case Communications.INVALID_HTTP_BODY_IN_NETWORK_RESPONSE:
|
||||
if (Globals.scDebug) {
|
||||
System.println("HomeAssistantApp onReturnFetchApiStatus() Response Code: INVALID_HTTP_BODY_IN_NETWORK_RESPONSE, check JSON is returned.");
|
||||
}
|
||||
// System.println("HomeAssistantApp onReturnFetchApiStatus() Response Code: INVALID_HTTP_BODY_IN_NETWORK_RESPONSE, check JSON is returned.");
|
||||
if (!mIsGlance) {
|
||||
ErrorView.show(RezStrings.getNoJson());
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.NoJson) as Lang.String);
|
||||
}
|
||||
break;
|
||||
|
||||
case 404:
|
||||
if (Globals.scDebug) {
|
||||
System.println("HomeAssistantApp onReturnFetchApiStatus() Response Code: 404, page not found. Check Configuration URL setting.");
|
||||
}
|
||||
// System.println("HomeAssistantApp onReturnFetchApiStatus() Response Code: 404, page not found. Check Configuration URL setting.");
|
||||
if (!mIsGlance) {
|
||||
ErrorView.show(RezStrings.getConfigUrlNotFound());
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.ConfigUrlNotFound) as Lang.String);
|
||||
}
|
||||
break;
|
||||
|
||||
@ -360,7 +319,7 @@ class HomeAssistantApp extends Application.AppBase {
|
||||
msg = data.get("message");
|
||||
}
|
||||
if (msg.equals("API running.")) {
|
||||
mApiStatus = RezStrings.getAvailable();
|
||||
mApiStatus = WatchUi.loadResource($.Rez.Strings.Available) as Lang.String;
|
||||
} else {
|
||||
if (!mIsGlance) {
|
||||
ErrorView.show("API " + mApiStatus + ".");
|
||||
@ -369,11 +328,9 @@ class HomeAssistantApp extends Application.AppBase {
|
||||
break;
|
||||
|
||||
default:
|
||||
if (Globals.scDebug) {
|
||||
System.println("HomeAssistantApp onReturnFetchApiStatus(): Unhandled HTTP response code = " + responseCode);
|
||||
}
|
||||
// System.println("HomeAssistantApp onReturnFetchApiStatus(): Unhandled HTTP response code = " + responseCode);
|
||||
if (!mIsGlance) {
|
||||
ErrorView.show(RezStrings.getUnhandledHttpErr() + responseCode);
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.UnhandledHttpErr) as Lang.String + responseCode);
|
||||
}
|
||||
}
|
||||
WatchUi.requestUpdate();
|
||||
@ -382,28 +339,24 @@ class HomeAssistantApp extends Application.AppBase {
|
||||
(:glance)
|
||||
function fetchApiStatus() as Void {
|
||||
if (Settings.getApiUrl().equals("")) {
|
||||
mApiStatus = RezStrings.getUnconfigured();
|
||||
mApiStatus = WatchUi.loadResource($.Rez.Strings.Unconfigured) as Lang.String;
|
||||
WatchUi.requestUpdate();
|
||||
} else {
|
||||
if (! System.getDeviceSettings().phoneConnected) {
|
||||
if (Globals.scDebug) {
|
||||
System.println("HomeAssistantToggleMenuItem getState(): No Phone connection, skipping API call.");
|
||||
}
|
||||
mApiStatus = RezStrings.getUnavailable();
|
||||
// System.println("HomeAssistantToggleMenuItem getState(): No Phone connection, skipping API call.");
|
||||
mApiStatus = WatchUi.loadResource($.Rez.Strings.Unavailable) as Lang.String;
|
||||
if (mIsGlance) {
|
||||
WatchUi.requestUpdate();
|
||||
} else {
|
||||
ErrorView.show(RezStrings.getNoPhone() + ".");
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.NoPhone) as Lang.String + ".");
|
||||
}
|
||||
} else if (! System.getDeviceSettings().connectionAvailable) {
|
||||
if (Globals.scDebug) {
|
||||
System.println("HomeAssistantToggleMenuItem getState(): No Internet connection, skipping API call.");
|
||||
}
|
||||
mApiStatus = RezStrings.getUnavailable();
|
||||
// System.println("HomeAssistantToggleMenuItem getState(): No Internet connection, skipping API call.");
|
||||
mApiStatus = WatchUi.loadResource($.Rez.Strings.Unavailable) as Lang.String;
|
||||
if (mIsGlance) {
|
||||
WatchUi.requestUpdate();
|
||||
} else {
|
||||
ErrorView.show(RezStrings.getNoInternet() + ".");
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.NoInternet) as Lang.String + ".");
|
||||
}
|
||||
} else {
|
||||
Communications.makeWebRequest(
|
||||
@ -449,11 +402,9 @@ class HomeAssistantApp extends Application.AppBase {
|
||||
function updateNextMenuItem() as Void {
|
||||
var itu = mItemsToUpdate as Lang.Array<HomeAssistantToggleMenuItem>;
|
||||
if (itu == null) {
|
||||
if (Globals.scDebug) {
|
||||
System.println("HomeAssistantApp updateNextMenuItem(): No menu items to update");
|
||||
}
|
||||
// System.println("HomeAssistantApp updateNextMenuItem(): No menu items to update");
|
||||
if (!mIsGlance) {
|
||||
ErrorView.show(RezStrings.getConfigUrlNotFound());
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.ConfigUrlNotFound) as Lang.String);
|
||||
}
|
||||
} else {
|
||||
itu[mNextItemToUpdate].getState();
|
||||
@ -467,9 +418,9 @@ class HomeAssistantApp extends Application.AppBase {
|
||||
|
||||
function getGlanceView() as Lang.Array<WatchUi.GlanceView or WatchUi.GlanceViewDelegate> or Null {
|
||||
mIsGlance = true;
|
||||
RezStrings.update_glance();
|
||||
mApiStatus = RezStrings.getChecking();
|
||||
mMenuStatus = RezStrings.getChecking();
|
||||
// RezStrings.update_glance();
|
||||
mApiStatus = WatchUi.loadResource($.Rez.Strings.Checking) as Lang.String;
|
||||
mMenuStatus = WatchUi.loadResource($.Rez.Strings.Checking) as Lang.String;
|
||||
updateStatus();
|
||||
Settings.update();
|
||||
mTimer = new Timer.Timer();
|
||||
@ -486,9 +437,7 @@ class HomeAssistantApp extends Application.AppBase {
|
||||
// Replace this functionality with a more central settings class as proposed in
|
||||
// https://github.com/house-of-abbey/GarminHomeAssistant/pull/17.
|
||||
function onSettingsChanged() as Void {
|
||||
if (Globals.scDebug) {
|
||||
System.println("HomeAssistantApp onSettingsChanged()");
|
||||
}
|
||||
// System.println("HomeAssistantApp onSettingsChanged()");
|
||||
Settings.update();
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,7 @@ using Toybox.Application.Properties;
|
||||
class HomeAssistantConfirmation extends WatchUi.Confirmation {
|
||||
|
||||
function initialize() {
|
||||
WatchUi.Confirmation.initialize(RezStrings.getConfirm());
|
||||
WatchUi.Confirmation.initialize(WatchUi.loadResource($.Rez.Strings.Confirm) as Lang.String);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -44,10 +44,10 @@ class HomeAssistantGlanceView extends WatchUi.GlanceView {
|
||||
|
||||
function onLayout(dc as Graphics.Dc) as Void {
|
||||
var h = dc.getHeight();
|
||||
var tw = dc.getTextWidthInPixels(RezStrings.getGlanceMenu(), Graphics.FONT_XTINY);
|
||||
var tw = dc.getTextWidthInPixels(WatchUi.loadResource($.Rez.Strings.GlanceMenu) as Lang.String, Graphics.FONT_XTINY);
|
||||
|
||||
mTitle = new WatchUi.Text({
|
||||
:text => RezStrings.getAppName(),
|
||||
:text => WatchUi.loadResource($.Rez.Strings.AppName) as Lang.String,
|
||||
:color => Graphics.COLOR_WHITE,
|
||||
:font => Graphics.FONT_TINY,
|
||||
:justification => Graphics.TEXT_JUSTIFY_LEFT | Graphics.TEXT_JUSTIFY_VCENTER,
|
||||
@ -64,7 +64,7 @@ class HomeAssistantGlanceView extends WatchUi.GlanceView {
|
||||
:locY => 3 * h / 6
|
||||
});
|
||||
mApiStatus = new WatchUi.Text({
|
||||
:text => RezStrings.getChecking(),
|
||||
: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,
|
||||
@ -72,7 +72,7 @@ class HomeAssistantGlanceView extends WatchUi.GlanceView {
|
||||
:locY => 3 * h / 6
|
||||
});
|
||||
mMenuText = new WatchUi.Text({
|
||||
:text => RezStrings.getGlanceMenu() + ":",
|
||||
: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,
|
||||
@ -80,7 +80,7 @@ class HomeAssistantGlanceView extends WatchUi.GlanceView {
|
||||
:locY => 5 * h / 6
|
||||
});
|
||||
mMenuStatus = new WatchUi.Text({
|
||||
:text => RezStrings.getChecking(),
|
||||
: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,
|
||||
|
@ -44,60 +44,44 @@ class HomeAssistantService {
|
||||
context as Lang.Object
|
||||
) as Void {
|
||||
var entity_id = context as Lang.String or Null;
|
||||
if (Globals.scDebug) {
|
||||
System.println("HomeAssistantService onReturnCall() Response Code: " + responseCode);
|
||||
System.println("HomeAssistantService onReturnCall() Response Data: " + data);
|
||||
}
|
||||
// System.println("HomeAssistantService onReturnCall() Response Code: " + responseCode);
|
||||
// System.println("HomeAssistantService onReturnCall() Response Data: " + data);
|
||||
|
||||
switch (responseCode) {
|
||||
case Communications.BLE_HOST_TIMEOUT:
|
||||
case Communications.BLE_CONNECTION_UNAVAILABLE:
|
||||
if (Globals.scDebug) {
|
||||
System.println("HomeAssistantService onReturnCall() Response Code: BLE_HOST_TIMEOUT or BLE_CONNECTION_UNAVAILABLE, Bluetooth connection severed.");
|
||||
}
|
||||
ErrorView.show(RezStrings.getNoPhone() + ".");
|
||||
// System.println("HomeAssistantService onReturnCall() Response Code: BLE_HOST_TIMEOUT or BLE_CONNECTION_UNAVAILABLE, Bluetooth connection severed.");
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.NoPhone) as Lang.String + ".");
|
||||
break;
|
||||
|
||||
case Communications.BLE_QUEUE_FULL:
|
||||
if (Globals.scDebug) {
|
||||
System.println("HomeAssistantService onReturnCall() Response Code: BLE_QUEUE_FULL, API calls too rapid.");
|
||||
}
|
||||
ErrorView.show(RezStrings.getApiFlood());
|
||||
// System.println("HomeAssistantService onReturnCall() Response Code: BLE_QUEUE_FULL, API calls too rapid.");
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.ApiFlood) as Lang.String);
|
||||
break;
|
||||
|
||||
case Communications.NETWORK_REQUEST_TIMED_OUT:
|
||||
if (Globals.scDebug) {
|
||||
System.println("HomeAssistantService onReturnCall() Response Code: NETWORK_REQUEST_TIMED_OUT, check Internet connection.");
|
||||
}
|
||||
ErrorView.show(RezStrings.getNoResponse());
|
||||
// System.println("HomeAssistantService onReturnCall() Response Code: NETWORK_REQUEST_TIMED_OUT, check Internet connection.");
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.NoResponse) as Lang.String);
|
||||
break;
|
||||
|
||||
case Communications.NETWORK_RESPONSE_OUT_OF_MEMORY:
|
||||
if (Globals.scDebug) {
|
||||
System.println("HomeAssistantService onReturnCall() Response Code: NETWORK_RESPONSE_OUT_OF_MEMORY, are we going too fast?");
|
||||
}
|
||||
// System.println("HomeAssistantService onReturnCall() Response Code: NETWORK_RESPONSE_OUT_OF_MEMORY, are we going too fast?");
|
||||
// Ignore and see if we can carry on
|
||||
break;
|
||||
case Communications.INVALID_HTTP_BODY_IN_NETWORK_RESPONSE:
|
||||
if (Globals.scDebug) {
|
||||
System.println("HomeAssistantService onReturnCall() Response Code: INVALID_HTTP_BODY_IN_NETWORK_RESPONSE, check JSON is returned.");
|
||||
}
|
||||
ErrorView.show(RezStrings.getNoJson());
|
||||
// System.println("HomeAssistantService onReturnCall() Response Code: INVALID_HTTP_BODY_IN_NETWORK_RESPONSE, check JSON is returned.");
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.NoJson) as Lang.String);
|
||||
break;
|
||||
|
||||
case 404:
|
||||
if (Globals.scDebug) {
|
||||
System.println("HomeAssistantService onReturnCall() Response Code: 404, page not found. Check API URL setting.");
|
||||
}
|
||||
ErrorView.show(RezStrings.getApiUrlNotFound());
|
||||
// System.println("HomeAssistantService onReturnCall() Response Code: 404, page not found. Check API URL setting.");
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.ApiUrlNotFound) as Lang.String);
|
||||
break;
|
||||
|
||||
case 200:
|
||||
if (Globals.scDebug) {
|
||||
System.println("HomeAssistantService onReturnCall(): Service executed.");
|
||||
}
|
||||
// System.println("HomeAssistantService onReturnCall(): Service executed.");
|
||||
var d = data as Lang.Array;
|
||||
var toast = RezStrings.getExecuted();
|
||||
var toast = WatchUi.loadResource($.Rez.Strings.Executed) as Lang.String;
|
||||
for(var i = 0; i < d.size(); i++) {
|
||||
if ((d[i].get("entity_id") as Lang.String).equals(entity_id)) {
|
||||
toast = (d[i].get("attributes") as Lang.Dictionary).get("friendly_name") as Lang.String;
|
||||
@ -117,10 +101,8 @@ class HomeAssistantService {
|
||||
break;
|
||||
|
||||
default:
|
||||
if (Globals.scDebug) {
|
||||
System.println("HomeAssistantService onReturnCall(): Unhandled HTTP response code = " + responseCode);
|
||||
}
|
||||
ErrorView.show(RezStrings.getUnhandledHttpErr() + responseCode);
|
||||
// System.println("HomeAssistantService onReturnCall(): Unhandled HTTP response code = " + responseCode);
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.UnhandledHttpErr) as Lang.String + responseCode);
|
||||
}
|
||||
}
|
||||
|
||||
@ -129,22 +111,16 @@ class HomeAssistantService {
|
||||
data as Lang.Dictionary or Null
|
||||
) as Void {
|
||||
if (! System.getDeviceSettings().phoneConnected) {
|
||||
if (Globals.scDebug) {
|
||||
System.println("HomeAssistantService call(): No Phone connection, skipping API call.");
|
||||
}
|
||||
ErrorView.show(RezStrings.getNoPhone() + ".");
|
||||
// System.println("HomeAssistantService call(): No Phone connection, skipping API call.");
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.NoPhone) as Lang.String + ".");
|
||||
} else if (! System.getDeviceSettings().connectionAvailable) {
|
||||
if (Globals.scDebug) {
|
||||
System.println("HomeAssistantService call(): No Internet connection, skipping API call.");
|
||||
}
|
||||
ErrorView.show(RezStrings.getNoInternet() + ".");
|
||||
// System.println("HomeAssistantService call(): No Internet connection, skipping API call.");
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.NoInternet) as Lang.String + ".");
|
||||
} else {
|
||||
// Can't use null for substring() parameters due to API version level.
|
||||
var url = Settings.getApiUrl() + "/services/" + service.substring(0, service.find(".")) + "/" + service.substring(service.find(".")+1, service.length());
|
||||
if (Globals.scDebug) {
|
||||
System.println("HomeAssistantService call() URL=" + url);
|
||||
System.println("HomeAssistantService call() service=" + service);
|
||||
}
|
||||
// System.println("HomeAssistantService call() URL=" + url);
|
||||
// System.println("HomeAssistantService call() service=" + service);
|
||||
|
||||
var entity_id = data.get("entity_id");
|
||||
if (entity_id == null) {
|
||||
|
@ -84,46 +84,34 @@ class HomeAssistantTemplateMenuItem extends WatchUi.IconMenuItem {
|
||||
// error. The ErrorView cancellation will resume the call chain.
|
||||
//
|
||||
function onReturnGetState(responseCode as Lang.Number, data as Lang.String) as Void {
|
||||
if (Globals.scDebug) {
|
||||
System.println("HomeAssistantTemplateMenuItem onReturnGetState() Response Code: " + responseCode);
|
||||
System.println("HomeAssistantTemplateMenuItem onReturnGetState() Response Data: " + data);
|
||||
}
|
||||
// System.println("HomeAssistantTemplateMenuItem onReturnGetState() Response Code: " + responseCode);
|
||||
// System.println("HomeAssistantTemplateMenuItem onReturnGetState() Response Data: " + data);
|
||||
|
||||
var status = RezStrings.getUnavailable();
|
||||
var status = WatchUi.loadResource($.Rez.Strings.Unavailable) as Lang.String;
|
||||
switch (responseCode) {
|
||||
case Communications.BLE_HOST_TIMEOUT:
|
||||
case Communications.BLE_CONNECTION_UNAVAILABLE:
|
||||
if (Globals.scDebug) {
|
||||
System.println("HomeAssistantTemplateMenuItem onReturnGetState() Response Code: BLE_HOST_TIMEOUT or BLE_CONNECTION_UNAVAILABLE, Bluetooth connection severed.");
|
||||
}
|
||||
ErrorView.show(RezStrings.getNoPhone() + ".");
|
||||
// System.println("HomeAssistantTemplateMenuItem onReturnGetState() Response Code: BLE_HOST_TIMEOUT or BLE_CONNECTION_UNAVAILABLE, Bluetooth connection severed.");
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.NoPhone) as Lang.String + ".");
|
||||
break;
|
||||
|
||||
case Communications.BLE_QUEUE_FULL:
|
||||
if (Globals.scDebug) {
|
||||
System.println("HomeAssistantTemplateMenuItem onReturnGetState() Response Code: BLE_QUEUE_FULL, API calls too rapid.");
|
||||
}
|
||||
ErrorView.show(RezStrings.getApiFlood());
|
||||
// System.println("HomeAssistantTemplateMenuItem onReturnGetState() Response Code: BLE_QUEUE_FULL, API calls too rapid.");
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.ApiFlood) as Lang.String);
|
||||
break;
|
||||
|
||||
case Communications.NETWORK_REQUEST_TIMED_OUT:
|
||||
if (Globals.scDebug) {
|
||||
System.println("HomeAssistantTemplateMenuItem onReturnGetState() Response Code: NETWORK_REQUEST_TIMED_OUT, check Internet connection.");
|
||||
}
|
||||
ErrorView.show(RezStrings.getNoResponse());
|
||||
// System.println("HomeAssistantTemplateMenuItem onReturnGetState() Response Code: NETWORK_REQUEST_TIMED_OUT, check Internet connection.");
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.NoResponse) as Lang.String);
|
||||
break;
|
||||
|
||||
case Communications.INVALID_HTTP_BODY_IN_NETWORK_RESPONSE:
|
||||
if (Globals.scDebug) {
|
||||
System.println("HomeAssistantTemplateMenuItem onReturnGetState() Response Code: INVALID_HTTP_BODY_IN_NETWORK_RESPONSE, check JSON is returned.");
|
||||
}
|
||||
ErrorView.show(RezStrings.getNoJson());
|
||||
// System.println("HomeAssistantTemplateMenuItem onReturnGetState() Response Code: INVALID_HTTP_BODY_IN_NETWORK_RESPONSE, check JSON is returned.");
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.NoJson) as Lang.String);
|
||||
break;
|
||||
|
||||
case Communications.NETWORK_RESPONSE_OUT_OF_MEMORY:
|
||||
if (Globals.scDebug) {
|
||||
System.println("HomeAssistantTemplateMenuItem onReturnGetState() Response Code: NETWORK_RESPONSE_OUT_OF_MEMORY, are we going too fast?");
|
||||
}
|
||||
// System.println("HomeAssistantTemplateMenuItem onReturnGetState() Response Code: NETWORK_RESPONSE_OUT_OF_MEMORY, are we going too fast?");
|
||||
var myTimer = new Timer.Timer();
|
||||
// Now this feels very "closely coupled" to the application, but it is the most reliable method instead of using a timer.
|
||||
myTimer.start(getApp().method(:updateNextMenuItem), Globals.scApiBackoff, false);
|
||||
@ -132,21 +120,17 @@ class HomeAssistantTemplateMenuItem extends WatchUi.IconMenuItem {
|
||||
break;
|
||||
|
||||
case 404:
|
||||
if (Globals.scDebug) {
|
||||
System.println("HomeAssistantTemplateMenuItem onReturnGetState() Response Code: 404, page not found. Check API URL setting.");
|
||||
}
|
||||
ErrorView.show(RezStrings.getApiUrlNotFound());
|
||||
// System.println("HomeAssistantTemplateMenuItem onReturnGetState() Response Code: 404, page not found. Check API URL setting.");
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.ApiUrlNotFound) as Lang.String);
|
||||
break;
|
||||
|
||||
case 400:
|
||||
if (Globals.scDebug) {
|
||||
System.println("HomeAssistantTemplateMenuItem onReturnGetState() Response Code: 400, bad request. Template error.");
|
||||
}
|
||||
ErrorView.show(RezStrings.getTemplateError());
|
||||
// System.println("HomeAssistantTemplateMenuItem onReturnGetState() Response Code: 400, bad request. Template error.");
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.TemplateError) as Lang.String);
|
||||
break;
|
||||
|
||||
case 200:
|
||||
status = RezStrings.getAvailable();
|
||||
status = WatchUi.loadResource($.Rez.Strings.Available) as Lang.String;
|
||||
setSubLabel(data);
|
||||
requestUpdate();
|
||||
// Now this feels very "closely coupled" to the application, but it is the most reliable method instead of using a timer.
|
||||
@ -154,32 +138,24 @@ class HomeAssistantTemplateMenuItem extends WatchUi.IconMenuItem {
|
||||
break;
|
||||
|
||||
default:
|
||||
if (Globals.scDebug) {
|
||||
System.println("HomeAssistantTemplateMenuItem onReturnGetState(): Unhandled HTTP response code = " + responseCode);
|
||||
}
|
||||
ErrorView.show(RezStrings.getUnhandledHttpErr() + responseCode);
|
||||
// System.println("HomeAssistantTemplateMenuItem onReturnGetState(): Unhandled HTTP response code = " + responseCode);
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.UnhandledHttpErr) as Lang.String + responseCode);
|
||||
}
|
||||
getApp().setApiStatus(status);
|
||||
}
|
||||
|
||||
function getState() as Void {
|
||||
if (! System.getDeviceSettings().phoneConnected) {
|
||||
if (Globals.scDebug) {
|
||||
System.println("HomeAssistantTemplateMenuItem getState(): No Phone connection, skipping API call.");
|
||||
}
|
||||
ErrorView.show(RezStrings.getNoPhone() + ".");
|
||||
getApp().setApiStatus(RezStrings.getUnavailable());
|
||||
// System.println("HomeAssistantTemplateMenuItem getState(): No Phone connection, skipping API call.");
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.NoPhone) as Lang.String + ".");
|
||||
getApp().setApiStatus(WatchUi.loadResource($.Rez.Strings.Unavailable) as Lang.String);
|
||||
} else if (! System.getDeviceSettings().connectionAvailable) {
|
||||
if (Globals.scDebug) {
|
||||
System.println("HomeAssistantTemplateMenuItem getState(): No Internet connection, skipping API call.");
|
||||
}
|
||||
ErrorView.show(RezStrings.getNoInternet() + ".");
|
||||
getApp().setApiStatus(RezStrings.getUnavailable());
|
||||
// System.println("HomeAssistantTemplateMenuItem getState(): No Internet connection, skipping API call.");
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.NoInternet) as Lang.String + ".");
|
||||
getApp().setApiStatus(WatchUi.loadResource($.Rez.Strings.Unavailable) as Lang.String);
|
||||
} else {
|
||||
var url = Settings.getApiUrl() + "/template";
|
||||
if (Globals.scDebug) {
|
||||
System.println("HomeAssistantTemplateMenuItem getState() URL=" + url + ", Template='" + mTemplate + "'");
|
||||
}
|
||||
// System.println("HomeAssistantTemplateMenuItem getState() URL=" + url + ", Template='" + mTemplate + "'");
|
||||
Communications.makeWebRequest(
|
||||
url,
|
||||
{ "template" => mTemplate },
|
||||
|
@ -59,46 +59,34 @@ class HomeAssistantToggleMenuItem extends WatchUi.ToggleMenuItem {
|
||||
// error. The ErrorView cancellation will resume the call chain.
|
||||
//
|
||||
function onReturnGetState(responseCode as Lang.Number, data as Null or Lang.Dictionary or Lang.String) as Void {
|
||||
if (Globals.scDebug) {
|
||||
System.println("HomeAssistantToggleMenuItem onReturnGetState() Response Code: " + responseCode);
|
||||
System.println("HomeAssistantToggleMenuItem onReturnGetState() Response Data: " + data);
|
||||
}
|
||||
// System.println("HomeAssistantToggleMenuItem onReturnGetState() Response Code: " + responseCode);
|
||||
// System.println("HomeAssistantToggleMenuItem onReturnGetState() Response Data: " + data);
|
||||
|
||||
var status = RezStrings.getUnavailable();
|
||||
var status = WatchUi.loadResource($.Rez.Strings.Unavailable) as Lang.String;
|
||||
switch (responseCode) {
|
||||
case Communications.BLE_HOST_TIMEOUT:
|
||||
case Communications.BLE_CONNECTION_UNAVAILABLE:
|
||||
if (Globals.scDebug) {
|
||||
System.println("HomeAssistantToggleMenuItem onReturnGetState() Response Code: BLE_HOST_TIMEOUT or BLE_CONNECTION_UNAVAILABLE, Bluetooth connection severed.");
|
||||
}
|
||||
ErrorView.show(RezStrings.getNoPhone() + ".");
|
||||
// System.println("HomeAssistantToggleMenuItem onReturnGetState() Response Code: BLE_HOST_TIMEOUT or BLE_CONNECTION_UNAVAILABLE, Bluetooth connection severed.");
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.NoPhone) as Lang.String + ".");
|
||||
break;
|
||||
|
||||
case Communications.BLE_QUEUE_FULL:
|
||||
if (Globals.scDebug) {
|
||||
System.println("HomeAssistantToggleMenuItem onReturnGetState() Response Code: BLE_QUEUE_FULL, API calls too rapid.");
|
||||
}
|
||||
ErrorView.show(RezStrings.getApiFlood());
|
||||
// System.println("HomeAssistantToggleMenuItem onReturnGetState() Response Code: BLE_QUEUE_FULL, API calls too rapid.");
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.ApiFlood) as Lang.String);
|
||||
break;
|
||||
|
||||
case Communications.NETWORK_REQUEST_TIMED_OUT:
|
||||
if (Globals.scDebug) {
|
||||
System.println("HomeAssistantToggleMenuItem onReturnGetState() Response Code: NETWORK_REQUEST_TIMED_OUT, check Internet connection.");
|
||||
}
|
||||
ErrorView.show(RezStrings.getNoResponse());
|
||||
// System.println("HomeAssistantToggleMenuItem onReturnGetState() Response Code: NETWORK_REQUEST_TIMED_OUT, check Internet connection.");
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.NoResponse) as Lang.String);
|
||||
break;
|
||||
|
||||
case Communications.INVALID_HTTP_BODY_IN_NETWORK_RESPONSE:
|
||||
if (Globals.scDebug) {
|
||||
System.println("HomeAssistantToggleMenuItem onReturnGetState() Response Code: INVALID_HTTP_BODY_IN_NETWORK_RESPONSE, check JSON is returned.");
|
||||
}
|
||||
ErrorView.show(RezStrings.getNoJson());
|
||||
// System.println("HomeAssistantToggleMenuItem onReturnGetState() Response Code: INVALID_HTTP_BODY_IN_NETWORK_RESPONSE, check JSON is returned.");
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.NoJson) as Lang.String);
|
||||
break;
|
||||
|
||||
case Communications.NETWORK_RESPONSE_OUT_OF_MEMORY:
|
||||
if (Globals.scDebug) {
|
||||
System.println("HomeAssistantToggleMenuItem onReturnGetState() Response Code: NETWORK_RESPONSE_OUT_OF_MEMORY, are we going too fast?");
|
||||
}
|
||||
// System.println("HomeAssistantToggleMenuItem onReturnGetState() Response Code: NETWORK_RESPONSE_OUT_OF_MEMORY, are we going too fast?");
|
||||
var myTimer = new Timer.Timer();
|
||||
// Now this feels very "closely coupled" to the application, but it is the most reliable method instead of using a timer.
|
||||
myTimer.start(getApp().method(:updateNextMenuItem), Globals.scApiBackoff, false);
|
||||
@ -113,32 +101,24 @@ class HomeAssistantToggleMenuItem extends WatchUi.ToggleMenuItem {
|
||||
}
|
||||
if (msg != null) {
|
||||
// Should be an HTTP 404 according to curl queries
|
||||
if (Globals.scDebug) {
|
||||
System.println("HomeAssistantToggleMenuItem onReturnGetState() Response Code: 404. " + mData.get("entity_id") + " " + msg);
|
||||
}
|
||||
// System.println("HomeAssistantToggleMenuItem onReturnGetState() Response Code: 404. " + mData.get("entity_id") + " " + msg);
|
||||
ErrorView.show("HTTP 404, " + mData.get("entity_id") + ". " + data.get("message"));
|
||||
} else {
|
||||
if (Globals.scDebug) {
|
||||
System.println("HomeAssistantToggleMenuItem onReturnGetState() Response Code: 404, page not found. Check API URL setting.");
|
||||
}
|
||||
ErrorView.show(RezStrings.getApiUrlNotFound());
|
||||
// System.println("HomeAssistantToggleMenuItem onReturnGetState() Response Code: 404, page not found. Check API URL setting.");
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.ApiUrlNotFound) as Lang.String);
|
||||
}
|
||||
break;
|
||||
|
||||
case 405:
|
||||
if (Globals.scDebug) {
|
||||
System.println("HomeAssistantToggleMenuItem onReturnGetState() Response Code: 405. " + mData.get("entity_id") + " " + data.get("message"));
|
||||
}
|
||||
// System.println("HomeAssistantToggleMenuItem onReturnGetState() Response Code: 405. " + mData.get("entity_id") + " " + data.get("message"));
|
||||
ErrorView.show("HTTP 405, " + mData.get("entity_id") + ". " + data.get("message"));
|
||||
|
||||
break;
|
||||
|
||||
case 200:
|
||||
status = RezStrings.getAvailable();
|
||||
status = WatchUi.loadResource($.Rez.Strings.Available) as Lang.String;
|
||||
var state = data.get("state") as Lang.String;
|
||||
if (Globals.scDebug) {
|
||||
System.println((data.get("attributes") as Lang.Dictionary).get("friendly_name") + " State=" + state);
|
||||
}
|
||||
// System.println((data.get("attributes") as Lang.Dictionary).get("friendly_name") + " State=" + state);
|
||||
if (getLabel().equals("...")) {
|
||||
setLabel((data.get("attributes") as Lang.Dictionary).get("friendly_name") as Lang.String);
|
||||
}
|
||||
@ -148,32 +128,24 @@ class HomeAssistantToggleMenuItem extends WatchUi.ToggleMenuItem {
|
||||
break;
|
||||
|
||||
default:
|
||||
if (Globals.scDebug) {
|
||||
System.println("HomeAssistantToggleMenuItem onReturnGetState(): Unhandled HTTP response code = " + responseCode);
|
||||
}
|
||||
ErrorView.show(RezStrings.getUnhandledHttpErr() + responseCode);
|
||||
// System.println("HomeAssistantToggleMenuItem onReturnGetState(): Unhandled HTTP response code = " + responseCode);
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.UnhandledHttpErr) as Lang.String + responseCode);
|
||||
}
|
||||
getApp().setApiStatus(status);
|
||||
}
|
||||
|
||||
function getState() as Void {
|
||||
if (! System.getDeviceSettings().phoneConnected) {
|
||||
if (Globals.scDebug) {
|
||||
System.println("HomeAssistantToggleMenuItem getState(): No Phone connection, skipping API call.");
|
||||
}
|
||||
ErrorView.show(RezStrings.getNoPhone() + ".");
|
||||
getApp().setApiStatus(RezStrings.getUnavailable());
|
||||
// System.println("HomeAssistantToggleMenuItem getState(): No Phone connection, skipping API call.");
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.NoPhone) as Lang.String + ".");
|
||||
getApp().setApiStatus(WatchUi.loadResource($.Rez.Strings.Unavailable) as Lang.String);
|
||||
} else if (! System.getDeviceSettings().connectionAvailable) {
|
||||
if (Globals.scDebug) {
|
||||
System.println("HomeAssistantToggleMenuItem getState(): No Internet connection, skipping API call.");
|
||||
}
|
||||
ErrorView.show(RezStrings.getNoInternet() + ".");
|
||||
getApp().setApiStatus(RezStrings.getUnavailable());
|
||||
// System.println("HomeAssistantToggleMenuItem getState(): No Internet connection, skipping API call.");
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.NoInternet) as Lang.String + ".");
|
||||
getApp().setApiStatus(WatchUi.loadResource($.Rez.Strings.Unavailable) as Lang.String);
|
||||
} else {
|
||||
var url = Settings.getApiUrl() + "/states/" + mData.get("entity_id");
|
||||
if (Globals.scDebug) {
|
||||
System.println("HomeAssistantToggleMenuItem getState() URL=" + url);
|
||||
}
|
||||
// System.println("HomeAssistantToggleMenuItem getState() URL=" + url);
|
||||
Communications.makeWebRequest(
|
||||
url,
|
||||
null,
|
||||
@ -192,47 +164,35 @@ class HomeAssistantToggleMenuItem extends WatchUi.ToggleMenuItem {
|
||||
// Callback function after completing the POST request to set the status.
|
||||
//
|
||||
function onReturnSetState(responseCode as Lang.Number, data as Null or Lang.Dictionary or Lang.String) as Void {
|
||||
if (Globals.scDebug) {
|
||||
System.println("HomeAssistantToggleMenuItem onReturnSetState() Response Code: " + responseCode);
|
||||
System.println("HomeAssistantToggleMenuItem onReturnSetState() Response Data: " + data);
|
||||
}
|
||||
// System.println("HomeAssistantToggleMenuItem onReturnSetState() Response Code: " + responseCode);
|
||||
// System.println("HomeAssistantToggleMenuItem onReturnSetState() Response Data: " + data);
|
||||
|
||||
var status = RezStrings.getUnavailable();
|
||||
var status = WatchUi.loadResource($.Rez.Strings.Unavailable) as Lang.String;
|
||||
switch (responseCode) {
|
||||
case Communications.BLE_HOST_TIMEOUT:
|
||||
case Communications.BLE_CONNECTION_UNAVAILABLE:
|
||||
if (Globals.scDebug) {
|
||||
System.println("HomeAssistantToggleMenuItem onReturnSetState() Response Code: BLE_HOST_TIMEOUT or BLE_CONNECTION_UNAVAILABLE, Bluetooth connection severed.");
|
||||
}
|
||||
ErrorView.show(RezStrings.getNoPhone() + ".");
|
||||
// System.println("HomeAssistantToggleMenuItem onReturnSetState() Response Code: BLE_HOST_TIMEOUT or BLE_CONNECTION_UNAVAILABLE, Bluetooth connection severed.");
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.NoPhone) as Lang.String + ".");
|
||||
break;
|
||||
|
||||
case Communications.BLE_QUEUE_FULL:
|
||||
if (Globals.scDebug) {
|
||||
System.println("HomeAssistantToggleMenuItem onReturnSetState() Response Code: BLE_QUEUE_FULL, API calls too rapid.");
|
||||
}
|
||||
ErrorView.show(RezStrings.getApiFlood());
|
||||
// System.println("HomeAssistantToggleMenuItem onReturnSetState() Response Code: BLE_QUEUE_FULL, API calls too rapid.");
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.ApiFlood) as Lang.String);
|
||||
break;
|
||||
|
||||
case Communications.NETWORK_REQUEST_TIMED_OUT:
|
||||
if (Globals.scDebug) {
|
||||
System.println("HomeAssistantToggleMenuItem onReturnSetState() Response Code: NETWORK_REQUEST_TIMED_OUT, check Internet connection.");
|
||||
}
|
||||
ErrorView.show(RezStrings.getNoResponse());
|
||||
// System.println("HomeAssistantToggleMenuItem onReturnSetState() Response Code: NETWORK_REQUEST_TIMED_OUT, check Internet connection.");
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.NoResponse) as Lang.String);
|
||||
break;
|
||||
|
||||
case Communications.INVALID_HTTP_BODY_IN_NETWORK_RESPONSE:
|
||||
if (Globals.scDebug) {
|
||||
System.println("HomeAssistantToggleMenuItem onReturnSetState() Response Code: INVALID_HTTP_BODY_IN_NETWORK_RESPONSE, check JSON is returned.");
|
||||
}
|
||||
ErrorView.show(RezStrings.getNoJson());
|
||||
// System.println("HomeAssistantToggleMenuItem onReturnSetState() Response Code: INVALID_HTTP_BODY_IN_NETWORK_RESPONSE, check JSON is returned.");
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.NoJson) as Lang.String);
|
||||
break;
|
||||
|
||||
case 404:
|
||||
if (Globals.scDebug) {
|
||||
System.println("HomeAssistantToggleMenuItem onReturnSetState() Response Code: 404, page not found. Check API URL setting.");
|
||||
}
|
||||
ErrorView.show(RezStrings.getApiUrlNotFound());
|
||||
// System.println("HomeAssistantToggleMenuItem onReturnSetState() Response Code: 404, page not found. Check API URL setting.");
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.ApiUrlNotFound) as Lang.String);
|
||||
break;
|
||||
|
||||
case 200:
|
||||
@ -241,39 +201,31 @@ class HomeAssistantToggleMenuItem extends WatchUi.ToggleMenuItem {
|
||||
for(var i = 0; i < d.size(); i++) {
|
||||
if ((d[i].get("entity_id") as Lang.String).equals(mData.get("entity_id"))) {
|
||||
state = d[i].get("state") as Lang.String;
|
||||
if (Globals.scDebug) {
|
||||
System.println((d[i].get("attributes") as Lang.Dictionary).get("friendly_name") + " State=" + state);
|
||||
}
|
||||
// System.println((d[i].get("attributes") as Lang.Dictionary).get("friendly_name") + " State=" + state);
|
||||
setUiToggle(state);
|
||||
}
|
||||
}
|
||||
status = RezStrings.getAvailable();
|
||||
status = WatchUi.loadResource($.Rez.Strings.Available) as Lang.String;
|
||||
break;
|
||||
|
||||
default:
|
||||
if (Globals.scDebug) {
|
||||
System.println("HomeAssistantToggleMenuItem onReturnSetState(): Unhandled HTTP response code = " + responseCode);
|
||||
}
|
||||
ErrorView.show(RezStrings.getUnhandledHttpErr() + responseCode);
|
||||
// System.println("HomeAssistantToggleMenuItem onReturnSetState(): Unhandled HTTP response code = " + responseCode);
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.UnhandledHttpErr) as Lang.String + responseCode);
|
||||
}
|
||||
getApp().setApiStatus(status);
|
||||
}
|
||||
|
||||
function setState(s as Lang.Boolean) as Void {
|
||||
if (! System.getDeviceSettings().phoneConnected) {
|
||||
if (Globals.scDebug) {
|
||||
System.println("HomeAssistantToggleMenuItem getState(): No Phone connection, skipping API call.");
|
||||
}
|
||||
// System.println("HomeAssistantToggleMenuItem getState(): No Phone connection, skipping API call.");
|
||||
// Toggle the UI back
|
||||
setEnabled(!isEnabled());
|
||||
ErrorView.show(RezStrings.getNoPhone() + ".");
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.NoPhone) as Lang.String + ".");
|
||||
} else if (! System.getDeviceSettings().connectionAvailable) {
|
||||
if (Globals.scDebug) {
|
||||
System.println("HomeAssistantToggleMenuItem getState(): No Internet connection, skipping API call.");
|
||||
}
|
||||
// System.println("HomeAssistantToggleMenuItem getState(): No Internet connection, skipping API call.");
|
||||
// Toggle the UI back
|
||||
setEnabled(!isEnabled());
|
||||
ErrorView.show(RezStrings.getNoInternet() + ".");
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.NoInternet) as Lang.String + ".");
|
||||
} else {
|
||||
// Updated SDK and got a new error
|
||||
// ERROR: venu: Cannot find symbol ':substring' on type 'PolyType<Null or $.Toybox.Lang.Object>'.
|
||||
@ -284,10 +236,8 @@ class HomeAssistantToggleMenuItem extends WatchUi.ToggleMenuItem {
|
||||
} else {
|
||||
url = url + id.substring(0, id.find(".")) + "/turn_off";
|
||||
}
|
||||
if (Globals.scDebug) {
|
||||
System.println("HomeAssistantToggleMenuItem setState() URL = " + url);
|
||||
System.println("HomeAssistantToggleMenuItem setState() entity_id = " + id);
|
||||
}
|
||||
// System.println("HomeAssistantToggleMenuItem setState() URL = " + url);
|
||||
// System.println("HomeAssistantToggleMenuItem setState() entity_id = " + id);
|
||||
Communications.makeWebRequest(
|
||||
url,
|
||||
mData,
|
||||
|
@ -34,11 +34,8 @@ class HomeAssistantView extends WatchUi.Menu2 {
|
||||
:theme as WatchUi.MenuTheme or Null
|
||||
} or Null
|
||||
) {
|
||||
|
||||
if (options == null) {
|
||||
options = {
|
||||
:title => definition.get("title") as Lang.String
|
||||
};
|
||||
options = { :title => definition.get("title") as Lang.String };
|
||||
} else {
|
||||
options.put(:title, definition.get("title") as Lang.String);
|
||||
}
|
||||
@ -146,32 +143,22 @@ class HomeAssistantViewDelegate extends WatchUi.Menu2InputDelegate {
|
||||
mTimer.reset();
|
||||
if (item instanceof HomeAssistantToggleMenuItem) {
|
||||
var haToggleItem = item as HomeAssistantToggleMenuItem;
|
||||
if (Globals.scDebug) {
|
||||
System.println(haToggleItem.getLabel() + " " + haToggleItem.getId() + " " + haToggleItem.isEnabled());
|
||||
}
|
||||
// System.println(haToggleItem.getLabel() + " " + haToggleItem.getId() + " " + haToggleItem.isEnabled());
|
||||
haToggleItem.callService(haToggleItem.isEnabled());
|
||||
} else if (item instanceof HomeAssistantTapMenuItem) {
|
||||
var haItem = item as HomeAssistantTapMenuItem;
|
||||
if (Globals.scDebug) {
|
||||
System.println(haItem.getLabel() + " " + haItem.getId());
|
||||
}
|
||||
// System.println(haItem.getLabel() + " " + haItem.getId());
|
||||
haItem.callService();
|
||||
} else if (item instanceof HomeAssistantTemplateMenuItem) {
|
||||
var haItem = item as HomeAssistantTemplateMenuItem;
|
||||
if (Globals.scDebug) {
|
||||
System.println(haItem.getLabel() + " " + haItem.getId());
|
||||
}
|
||||
// System.println(haItem.getLabel() + " " + haItem.getId());
|
||||
haItem.callService();
|
||||
} else if (item instanceof HomeAssistantGroupMenuItem) {
|
||||
var haMenuItem = item as HomeAssistantGroupMenuItem;
|
||||
if (Globals.scDebug) {
|
||||
System.println("IconMenu: " + haMenuItem.getLabel() + " " + haMenuItem.getId());
|
||||
}
|
||||
// System.println("IconMenu: " + haMenuItem.getLabel() + " " + haMenuItem.getId());
|
||||
WatchUi.pushView(haMenuItem.getMenuView(), new HomeAssistantViewDelegate(false), WatchUi.SLIDE_LEFT);
|
||||
} else {
|
||||
if (Globals.scDebug) {
|
||||
System.println(item.getLabel() + " " + item.getId());
|
||||
}
|
||||
// } else {
|
||||
// System.println(item.getLabel() + " " + item.getId());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -30,9 +30,7 @@ class QuitTimer extends Timer.Timer {
|
||||
}
|
||||
|
||||
function exitApp() as Void {
|
||||
if (Globals.scDebug) {
|
||||
System.println("QuitTimer exitApp(): Exiting");
|
||||
}
|
||||
// System.println("QuitTimer exitApp(): Exiting");
|
||||
// This will exit the system cleanly from any point within an app.
|
||||
System.exit();
|
||||
}
|
||||
@ -45,9 +43,7 @@ class QuitTimer extends Timer.Timer {
|
||||
}
|
||||
|
||||
function reset() {
|
||||
if (Globals.scDebug) {
|
||||
System.println("QuitTimer reset(): Restarted quit timer");
|
||||
}
|
||||
// System.println("QuitTimer reset(): Restarted quit timer");
|
||||
stop();
|
||||
begin();
|
||||
}
|
||||
|
@ -1,206 +0,0 @@
|
||||
//-----------------------------------------------------------------------------------
|
||||
//
|
||||
// Distributed under MIT Licence
|
||||
// See https://github.com/house-of-abbey/GarminHomeAssistant/blob/main/LICENSE.
|
||||
//
|
||||
//-----------------------------------------------------------------------------------
|
||||
//
|
||||
// GarminHomeAssistant is a Garmin IQ application written in Monkey C and routinely
|
||||
// tested on a Venu 2 device. The source code is provided at:
|
||||
// https://github.com/house-of-abbey/GarminHomeAssistant.
|
||||
//
|
||||
// P A Abbey & J D Abbey & Someone0nEarth, 31 October 2023
|
||||
//
|
||||
//
|
||||
// Description:
|
||||
//
|
||||
// Load the strings centrally once rather than initialising locally within separate
|
||||
// classes. This is to solve a problem with out of memory errors in some devices,
|
||||
// e.g. Vivoactive 3.
|
||||
//
|
||||
//-----------------------------------------------------------------------------------
|
||||
|
||||
using Toybox.Lang;
|
||||
using Toybox.WatchUi;
|
||||
|
||||
class RezStrings {
|
||||
|
||||
(:glance)
|
||||
private static var strAppName as Lang.String or Null;
|
||||
private static var strConfirm as Lang.String or Null;
|
||||
private static var strExecuted as Lang.String or Null;
|
||||
(:glance)
|
||||
private static var strNoPhone as Lang.String or Null;
|
||||
private static var strNoInternet as Lang.String or Null;
|
||||
private static var strNoResponse as Lang.String or Null;
|
||||
(:glance)
|
||||
private static var strNoApiKey as Lang.String or Null;
|
||||
(:glance)
|
||||
private static var strNoApiUrl as Lang.String or Null;
|
||||
(:glance)
|
||||
private static var strNoConfigUrl as Lang.String or Null;
|
||||
private static var strApiFlood as Lang.String or Null;
|
||||
private static var strApiUrlNotFound as Lang.String or Null;
|
||||
private static var strConfigUrlNotFound as Lang.String or Null;
|
||||
private static var strNoJson as Lang.String or Null;
|
||||
private static var strUnhandledHttpErr as Lang.String or Null;
|
||||
private static var strTrailingSlashErr as Lang.String or Null;
|
||||
private static var strWebhookFailed as Lang.String or Null;
|
||||
private static var strTemplateError as Lang.String or Null;
|
||||
(:glance)
|
||||
private static var strAvailable as Lang.String or Null;
|
||||
(:glance)
|
||||
private static var strChecking as Lang.String or Null;
|
||||
(:glance)
|
||||
private static var strUnavailable as Lang.String or Null;
|
||||
(:glance)
|
||||
private static var strUnconfigured as Lang.String or Null;
|
||||
(:glance)
|
||||
private static var strCached as Lang.String or Null;
|
||||
(:glance)
|
||||
private static var strGlanceMenu as Lang.String or Null;
|
||||
private static var strMemory as Lang.String or Null;
|
||||
|
||||
// Can't initialise a constant directly, have to be initialised via a function
|
||||
// for 'WatchUi.loadResource' to be available.
|
||||
(:glance)
|
||||
static function update_glance() {
|
||||
strAppName = WatchUi.loadResource($.Rez.Strings.AppName);
|
||||
strNoPhone = WatchUi.loadResource($.Rez.Strings.NoPhone);
|
||||
strNoApiKey = WatchUi.loadResource($.Rez.Strings.NoAPIKey);
|
||||
strNoApiUrl = WatchUi.loadResource($.Rez.Strings.NoApiUrl);
|
||||
strNoConfigUrl = WatchUi.loadResource($.Rez.Strings.NoConfigUrl);
|
||||
strAvailable = WatchUi.loadResource($.Rez.Strings.Available);
|
||||
strChecking = WatchUi.loadResource($.Rez.Strings.Checking);
|
||||
strUnavailable = WatchUi.loadResource($.Rez.Strings.Unavailable);
|
||||
strUnconfigured = WatchUi.loadResource($.Rez.Strings.Unconfigured);
|
||||
strCached = WatchUi.loadResource($.Rez.Strings.Cached);
|
||||
strGlanceMenu = WatchUi.loadResource($.Rez.Strings.GlanceMenu);
|
||||
}
|
||||
|
||||
// Can't initialise a constant directly, have to be initialised via a function
|
||||
// for 'WatchUi.loadResource' to be available.
|
||||
static function update() {
|
||||
strAppName = WatchUi.loadResource($.Rez.Strings.AppName);
|
||||
strConfirm = WatchUi.loadResource($.Rez.Strings.Confirm);
|
||||
strExecuted = WatchUi.loadResource($.Rez.Strings.Executed);
|
||||
strNoPhone = WatchUi.loadResource($.Rez.Strings.NoPhone);
|
||||
strNoInternet = WatchUi.loadResource($.Rez.Strings.NoInternet);
|
||||
strNoResponse = WatchUi.loadResource($.Rez.Strings.NoResponse);
|
||||
strNoApiKey = WatchUi.loadResource($.Rez.Strings.NoAPIKey);
|
||||
strNoApiUrl = WatchUi.loadResource($.Rez.Strings.NoApiUrl);
|
||||
strNoConfigUrl = WatchUi.loadResource($.Rez.Strings.NoConfigUrl);
|
||||
strApiFlood = WatchUi.loadResource($.Rez.Strings.ApiFlood);
|
||||
strApiUrlNotFound = WatchUi.loadResource($.Rez.Strings.ApiUrlNotFound);
|
||||
strConfigUrlNotFound = WatchUi.loadResource($.Rez.Strings.ConfigUrlNotFound);
|
||||
strNoJson = WatchUi.loadResource($.Rez.Strings.NoJson);
|
||||
strUnhandledHttpErr = WatchUi.loadResource($.Rez.Strings.UnhandledHttpErr);
|
||||
strTrailingSlashErr = WatchUi.loadResource($.Rez.Strings.TrailingSlashErr);
|
||||
strWebhookFailed = WatchUi.loadResource($.Rez.Strings.WebhookFailed);
|
||||
strTemplateError = WatchUi.loadResource($.Rez.Strings.TemplateError);
|
||||
strAvailable = WatchUi.loadResource($.Rez.Strings.Available);
|
||||
strChecking = WatchUi.loadResource($.Rez.Strings.Checking);
|
||||
strUnavailable = WatchUi.loadResource($.Rez.Strings.Unavailable);
|
||||
strUnconfigured = WatchUi.loadResource($.Rez.Strings.Unconfigured);
|
||||
strCached = WatchUi.loadResource($.Rez.Strings.Cached);
|
||||
strGlanceMenu = WatchUi.loadResource($.Rez.Strings.GlanceMenu);
|
||||
strMemory = WatchUi.loadResource($.Rez.Strings.Memory);
|
||||
}
|
||||
|
||||
static function getAppName() as Lang.String {
|
||||
return strAppName;
|
||||
}
|
||||
|
||||
static function getConfirm() as Lang.String {
|
||||
return strConfirm;
|
||||
}
|
||||
|
||||
static function getExecuted() as Lang.String {
|
||||
return strExecuted;
|
||||
}
|
||||
|
||||
static function getNoPhone() as Lang.String {
|
||||
return strNoPhone;
|
||||
}
|
||||
|
||||
static function getNoInternet() as Lang.String {
|
||||
return strNoInternet;
|
||||
}
|
||||
|
||||
static function getNoResponse() as Lang.String {
|
||||
return strNoResponse;
|
||||
}
|
||||
|
||||
static function getNoApiKey() as Lang.String {
|
||||
return strNoApiKey;
|
||||
}
|
||||
|
||||
static function getNoApiUrl() as Lang.String {
|
||||
return strNoApiUrl;
|
||||
}
|
||||
|
||||
static function getNoConfigUrl() as Lang.String {
|
||||
return strNoConfigUrl;
|
||||
}
|
||||
|
||||
static function getApiFlood() as Lang.String {
|
||||
return strApiFlood;
|
||||
}
|
||||
|
||||
static function getApiUrlNotFound() as Lang.String {
|
||||
return strApiUrlNotFound;
|
||||
}
|
||||
|
||||
static function getConfigUrlNotFound() as Lang.String {
|
||||
return strConfigUrlNotFound;
|
||||
}
|
||||
|
||||
static function getNoJson() as Lang.String {
|
||||
return strNoJson;
|
||||
}
|
||||
|
||||
static function getUnhandledHttpErr() as Lang.String {
|
||||
return strUnhandledHttpErr;
|
||||
}
|
||||
|
||||
static function getTrailingSlashErr() as Lang.String {
|
||||
return strTrailingSlashErr;
|
||||
}
|
||||
|
||||
static function getWebhookFailed() as Lang.String {
|
||||
return strWebhookFailed;
|
||||
}
|
||||
|
||||
static function getTemplateError() as Lang.String {
|
||||
return strTemplateError;
|
||||
}
|
||||
|
||||
static function getAvailable() as Lang.String {
|
||||
return strAvailable;
|
||||
}
|
||||
|
||||
static function getChecking() as Lang.String {
|
||||
return strChecking;
|
||||
}
|
||||
|
||||
static function getUnavailable() as Lang.String {
|
||||
return strUnavailable;
|
||||
}
|
||||
|
||||
static function getUnconfigured() as Lang.String {
|
||||
return strUnconfigured;
|
||||
}
|
||||
|
||||
static function getCached() as Lang.String {
|
||||
return strCached;
|
||||
}
|
||||
|
||||
static function getGlanceMenu() as Lang.String {
|
||||
return strGlanceMenu;
|
||||
}
|
||||
|
||||
static function getMemory() as Lang.String {
|
||||
return strMemory;
|
||||
}
|
||||
|
||||
}
|
@ -61,7 +61,7 @@ class RootView extends ScalableView {
|
||||
var w = dc.getWidth();
|
||||
|
||||
mTitle = new WatchUi.Text({
|
||||
:text => RezStrings.getAppName(),
|
||||
:text => WatchUi.loadResource($.Rez.Strings.AppName) as Lang.String,
|
||||
:color => Graphics.COLOR_WHITE,
|
||||
:font => Graphics.FONT_TINY,
|
||||
:justification => Graphics.TEXT_JUSTIFY_CENTER | Graphics.TEXT_JUSTIFY_VCENTER,
|
||||
@ -78,7 +78,7 @@ class RootView extends ScalableView {
|
||||
:locY => pixelsForScreen(50.0)
|
||||
});
|
||||
mApiStatus = new WatchUi.Text({
|
||||
:text => RezStrings.getChecking(),
|
||||
: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,
|
||||
@ -86,7 +86,7 @@ class RootView extends ScalableView {
|
||||
:locY => pixelsForScreen(50.0)
|
||||
});
|
||||
mMenuText = new WatchUi.Text({
|
||||
:text => RezStrings.getGlanceMenu() + ":",
|
||||
:text => WatchUi.loadResource($.Rez.Strings.GlanceMenu) as Lang.String + ":",
|
||||
:color => Graphics.COLOR_WHITE,
|
||||
:font => Graphics.FONT_XTINY,
|
||||
:justification => Graphics.TEXT_JUSTIFY_RIGHT | Graphics.TEXT_JUSTIFY_VCENTER,
|
||||
@ -94,7 +94,7 @@ class RootView extends ScalableView {
|
||||
:locY => pixelsForScreen(60.0)
|
||||
});
|
||||
mMenuStatus = new WatchUi.Text({
|
||||
:text => RezStrings.getChecking(),
|
||||
: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,
|
||||
@ -102,7 +102,7 @@ class RootView extends ScalableView {
|
||||
:locY => pixelsForScreen(60.0)
|
||||
});
|
||||
mMemText = new WatchUi.Text({
|
||||
:text => RezStrings.getMemory() + ":",
|
||||
:text => WatchUi.loadResource($.Rez.Strings.Memory) as Lang.String + ":",
|
||||
:color => Graphics.COLOR_WHITE,
|
||||
:font => Graphics.FONT_XTINY,
|
||||
:justification => Graphics.TEXT_JUSTIFY_RIGHT | Graphics.TEXT_JUSTIFY_VCENTER,
|
||||
@ -110,7 +110,7 @@ class RootView extends ScalableView {
|
||||
:locY => pixelsForScreen(70.0)
|
||||
});
|
||||
mMemStatus = new WatchUi.Text({
|
||||
:text => RezStrings.getChecking(),
|
||||
: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,
|
||||
@ -139,7 +139,7 @@ class RootView extends ScalableView {
|
||||
mMenuStatus.draw(dc);
|
||||
mMemText.draw(dc);
|
||||
var stats = System.getSystemStats();
|
||||
var memUsed = (100 * stats.usedMemory) / stats.totalMemory;
|
||||
var memUsed = (100f * stats.usedMemory) / stats.totalMemory;
|
||||
mMemStatus.setText(memUsed.format("%.1f") + "%");
|
||||
if (stats.usedMemory > Globals.scLowMem * stats.totalMemory) {
|
||||
mMemStatus.setColor(Graphics.COLOR_RED);
|
||||
|
@ -42,7 +42,6 @@ class Settings {
|
||||
private static var mBatteryRefreshRate as Lang.Number = 15; // minutes
|
||||
private static var mIsApp as Lang.Boolean = false;
|
||||
private static var mHasService as Lang.Boolean = false;
|
||||
|
||||
// Must keep the object so it doesn't get garbage collected.
|
||||
private static var mWebhookManager as WebhookManager or Null;
|
||||
|
||||
@ -75,7 +74,8 @@ class Settings {
|
||||
} else if (
|
||||
mHasService and
|
||||
((Background.getTemporalEventRegisteredTime() == null) or
|
||||
(Background.getTemporalEventRegisteredTime() != (mBatteryRefreshRate * 60)))) {
|
||||
(Background.getTemporalEventRegisteredTime() != (mBatteryRefreshRate * 60)))
|
||||
) {
|
||||
Background.registerForTemporalEvent(new Time.Duration(mBatteryRefreshRate * 60)); // Convert to seconds
|
||||
}
|
||||
} else {
|
||||
@ -86,14 +86,12 @@ class Settings {
|
||||
unsetWebhookId();
|
||||
}
|
||||
}
|
||||
if (Globals.scDebug) {
|
||||
System.println("Settings update(): getTemporalEventRegisteredTime() = " + Background.getTemporalEventRegisteredTime());
|
||||
if (Background.getTemporalEventRegisteredTime() != null) {
|
||||
System.println("Settings update(): getTemporalEventRegisteredTime().value() = " + Background.getTemporalEventRegisteredTime().value().format("%d") + " seconds");
|
||||
} else {
|
||||
System.println("Settings update(): getTemporalEventRegisteredTime() = null");
|
||||
}
|
||||
}
|
||||
// System.println("Settings update(): getTemporalEventRegisteredTime() = " + Background.getTemporalEventRegisteredTime());
|
||||
// if (Background.getTemporalEventRegisteredTime() != null) {
|
||||
// System.println("Settings update(): getTemporalEventRegisteredTime().value() = " + Background.getTemporalEventRegisteredTime().value().format("%d") + " seconds");
|
||||
// } else {
|
||||
// System.println("Settings update(): getTemporalEventRegisteredTime() = null");
|
||||
// }
|
||||
}
|
||||
|
||||
static function getApiKey() as Lang.String {
|
||||
|
@ -20,7 +20,7 @@
|
||||
// larger submissions in order to prevent overflow of the blue tooth stack.
|
||||
//
|
||||
//-----------------------------------------------------------------------------------
|
||||
//
|
||||
//
|
||||
// Usage:
|
||||
// wl = new WebLog();
|
||||
// wl.clear();
|
||||
@ -28,7 +28,7 @@
|
||||
// wl.flush();
|
||||
//
|
||||
// https://domain.name/path/log.php
|
||||
//
|
||||
//
|
||||
// <?php
|
||||
// $myfile = fopen("log", "a");
|
||||
// $queries = array();
|
||||
@ -36,11 +36,11 @@
|
||||
// fwrite($myfile, $queries['log']);
|
||||
// print "Success";
|
||||
// ?>
|
||||
//
|
||||
//
|
||||
// Logs published to: https://domain.name/path/log
|
||||
//
|
||||
// https://domain.name/path/log_clear.php
|
||||
//
|
||||
//
|
||||
// <?php
|
||||
// $myfile = fopen("log", "w");
|
||||
// fwrite($myfile, "");
|
||||
@ -78,9 +78,7 @@ class WebLog {
|
||||
var myTime = System.getClockTime();
|
||||
buffer += myTime.hour.format("%02d") + ":" + myTime.min.format("%02d") + ":" + myTime.sec.format("%02d") + " " + str;
|
||||
numCalls++;
|
||||
if (Globals.scDebug) {
|
||||
System.println("WebLog print() str = " + str);
|
||||
}
|
||||
// System.println("WebLog print() str = " + str);
|
||||
if (numCalls >= callsbuffer) {
|
||||
doPrint();
|
||||
}
|
||||
@ -97,9 +95,7 @@ class WebLog {
|
||||
// submission level set by 'callsbuffer'.
|
||||
//
|
||||
function flush() {
|
||||
if (Globals.scDebug) {
|
||||
System.println("WebLog flush()");
|
||||
}
|
||||
// System.println("WebLog flush()");
|
||||
if (numCalls > 0) {
|
||||
doPrint();
|
||||
}
|
||||
@ -108,15 +104,11 @@ class WebLog {
|
||||
// Perform the submission to the online logger.
|
||||
//
|
||||
function doPrint() {
|
||||
if (Globals.scDebug) {
|
||||
System.println("WebLog doPrint()");
|
||||
System.println(buffer);
|
||||
}
|
||||
// System.println("WebLog doPrint()");
|
||||
// System.println(buffer);
|
||||
Communications.makeWebRequest(
|
||||
ClientId.webLogUrl,
|
||||
{
|
||||
"log" => buffer
|
||||
},
|
||||
{ "log" => buffer },
|
||||
{
|
||||
:method => Communications.HTTP_REQUEST_METHOD_GET,
|
||||
:headers => {
|
||||
@ -134,9 +126,7 @@ class WebLog {
|
||||
// execution.
|
||||
//
|
||||
function clear() {
|
||||
if (Globals.scDebug) {
|
||||
System.println("WebLog clear()");
|
||||
}
|
||||
// System.println("WebLog clear()");
|
||||
Communications.makeWebRequest(
|
||||
ClientId.webLogClearUrl,
|
||||
{},
|
||||
@ -156,24 +146,20 @@ class WebLog {
|
||||
// Callback function to print the outcome of a doPrint() method.
|
||||
//
|
||||
function onLog(responseCode as Lang.Number, data as Null or Lang.Dictionary or Lang.String) as Void {
|
||||
if (Globals.scDebug) {
|
||||
if (responseCode != 200) {
|
||||
System.println("WebLog onLog() Failed");
|
||||
System.println("WebLog onLog() Response Code: " + responseCode);
|
||||
System.println("WebLog onLog() Response Data: " + data);
|
||||
}
|
||||
}
|
||||
// if (responseCode != 200) {
|
||||
// System.println("WebLog onLog() Failed");
|
||||
// System.println("WebLog onLog() Response Code: " + responseCode);
|
||||
// System.println("WebLog onLog() Response Data: " + data);
|
||||
// }
|
||||
}
|
||||
|
||||
// Callback function to print the outcome of a clear() method.
|
||||
//
|
||||
function onClear(responseCode as Lang.Number, data as Null or Lang.Dictionary or Lang.String) as Void {
|
||||
if (Globals.scDebug) {
|
||||
if (responseCode != 200) {
|
||||
System.println("WebLog onClear() Failed");
|
||||
System.println("WebLog onClear() Response Code: " + responseCode);
|
||||
System.println("WebLog onClear() Response Data: " + data);
|
||||
}
|
||||
}
|
||||
// if (responseCode != 200) {
|
||||
// System.println("WebLog onClear() Failed");
|
||||
// System.println("WebLog onClear() Response Code: " + responseCode);
|
||||
// System.println("WebLog onClear() Response Data: " + data);
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
@ -32,46 +32,34 @@ class WebhookManager {
|
||||
switch (responseCode) {
|
||||
case Communications.BLE_HOST_TIMEOUT:
|
||||
case Communications.BLE_CONNECTION_UNAVAILABLE:
|
||||
if (Globals.scDebug) {
|
||||
System.println("WebhookManager onReturnRequestWebhookId() Response Code: BLE_HOST_TIMEOUT or BLE_CONNECTION_UNAVAILABLE, Bluetooth connection severed.");
|
||||
}
|
||||
ErrorView.show(RezStrings.getWebhookFailed() + "\n" + RezStrings.getNoPhone() + ".");
|
||||
// System.println("WebhookManager onReturnRequestWebhookId() Response Code: BLE_HOST_TIMEOUT or BLE_CONNECTION_UNAVAILABLE, Bluetooth connection severed.");
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.WebhookFailed) as Lang.String + "\n" + WatchUi.loadResource($.Rez.Strings.NoPhone) as Lang.String + ".");
|
||||
break;
|
||||
|
||||
case Communications.BLE_QUEUE_FULL:
|
||||
if (Globals.scDebug) {
|
||||
System.println("WebhookManager onReturnRequestWebhookId() Response Code: BLE_QUEUE_FULL, API calls too rapid.");
|
||||
}
|
||||
ErrorView.show(RezStrings.getWebhookFailed() + "\n" + RezStrings.getApiFlood());
|
||||
// System.println("WebhookManager onReturnRequestWebhookId() Response Code: BLE_QUEUE_FULL, API calls too rapid.");
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.WebhookFailed) as Lang.String + "\n" + WatchUi.loadResource($.Rez.Strings.ApiFlood) as Lang.String);
|
||||
break;
|
||||
|
||||
case Communications.NETWORK_REQUEST_TIMED_OUT:
|
||||
if (Globals.scDebug) {
|
||||
System.println("WebhookManager onReturnRequestWebhookId() Response Code: NETWORK_REQUEST_TIMED_OUT, check Internet connection.");
|
||||
}
|
||||
ErrorView.show(RezStrings.getWebhookFailed() + "\n" + RezStrings.getNoResponse());
|
||||
// System.println("WebhookManager onReturnRequestWebhookId() Response Code: NETWORK_REQUEST_TIMED_OUT, check Internet connection.");
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.WebhookFailed) as Lang.String + "\n" + WatchUi.loadResource($.Rez.Strings.NoResponse) as Lang.String);
|
||||
break;
|
||||
|
||||
case Communications.NETWORK_RESPONSE_OUT_OF_MEMORY:
|
||||
if (Globals.scDebug) {
|
||||
System.println("WebhookManager onReturnRequestWebhookId() Response Code: NETWORK_RESPONSE_OUT_OF_MEMORY, are we going too fast?");
|
||||
}
|
||||
// System.println("WebhookManager onReturnRequestWebhookId() Response Code: NETWORK_RESPONSE_OUT_OF_MEMORY, are we going too fast?");
|
||||
// Ignore and see if we can carry on
|
||||
break;
|
||||
case Communications.INVALID_HTTP_BODY_IN_NETWORK_RESPONSE:
|
||||
if (Globals.scDebug) {
|
||||
System.println("WebhookManager onReturnRequestWebhookId() Response Code: INVALID_HTTP_BODY_IN_NETWORK_RESPONSE, check JSON is returned.");
|
||||
}
|
||||
// System.println("WebhookManager onReturnRequestWebhookId() Response Code: INVALID_HTTP_BODY_IN_NETWORK_RESPONSE, check JSON is returned.");
|
||||
Settings.unsetIsBatteryLevelEnabled();
|
||||
ErrorView.show(RezStrings.getWebhookFailed() + "\n" + RezStrings.getNoJson());
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.WebhookFailed) as Lang.String + "\n" + WatchUi.loadResource($.Rez.Strings.NoJson) as Lang.String);
|
||||
break;
|
||||
|
||||
case 404:
|
||||
if (Globals.scDebug) {
|
||||
System.println("WebhookManager onReturnRequestWebhookId() Response Code: 404, page not found. Check API URL setting.");
|
||||
}
|
||||
// System.println("WebhookManager onReturnRequestWebhookId() Response Code: 404, page not found. Check API URL setting.");
|
||||
Settings.unsetIsBatteryLevelEnabled();
|
||||
ErrorView.show(RezStrings.getWebhookFailed() + "\n" + RezStrings.getApiUrlNotFound());
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.WebhookFailed) as Lang.String + "\n" + WatchUi.loadResource($.Rez.Strings.ApiUrlNotFound) as Lang.String);
|
||||
break;
|
||||
|
||||
case 201:
|
||||
@ -99,33 +87,27 @@ class WebhookManager {
|
||||
"disabled" => false
|
||||
});
|
||||
} else {
|
||||
if (Globals.scDebug) {
|
||||
System.println("WebhookManager onReturnRequestWebhookId(): No webhook id in response data.");
|
||||
}
|
||||
// System.println("WebhookManager onReturnRequestWebhookId(): No webhook id in response data.");
|
||||
Settings.unsetIsBatteryLevelEnabled();
|
||||
ErrorView.show(RezStrings.getWebhookFailed());
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.WebhookFailed) as Lang.String);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
if (Globals.scDebug) {
|
||||
System.println("WebhookManager onReturnRequestWebhookId(): Unhandled HTTP response code = " + responseCode);
|
||||
}
|
||||
// System.println("WebhookManager onReturnRequestWebhookId(): Unhandled HTTP response code = " + responseCode);
|
||||
Settings.unsetIsBatteryLevelEnabled();
|
||||
ErrorView.show(RezStrings.getWebhookFailed() + "\n" + RezStrings.getUnhandledHttpErr() + responseCode);
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.WebhookFailed) as Lang.String + "\n" + WatchUi.loadResource($.Rez.Strings.UnhandledHttpErr) as Lang.String + responseCode);
|
||||
}
|
||||
}
|
||||
|
||||
function requestWebhookId() {
|
||||
if (Globals.scDebug) {
|
||||
System.println("WebhookManager requestWebhookId(): Requesting webhook id");
|
||||
}
|
||||
// System.println("WebhookManager requestWebhookId(): Requesting webhook id");
|
||||
Communications.makeWebRequest(
|
||||
Settings.getApiUrl() + "/mobile_app/registrations",
|
||||
{
|
||||
"device_id" => System.getDeviceSettings().uniqueIdentifier,
|
||||
"app_id" => "garmin_home_assistant",
|
||||
"app_name" => RezStrings.getAppName(),
|
||||
"app_name" => WatchUi.loadResource($.Rez.Strings.AppName) as Lang.String,
|
||||
"app_version" => "",
|
||||
"device_name" => "Garmin Watch",
|
||||
"manufacturer" => "Garmin",
|
||||
@ -151,83 +133,64 @@ class WebhookManager {
|
||||
switch (responseCode) {
|
||||
case Communications.BLE_HOST_TIMEOUT:
|
||||
case Communications.BLE_CONNECTION_UNAVAILABLE:
|
||||
if (Globals.scDebug) {
|
||||
System.println("WebhookManager onReturnRegisterWebhookSensor() Response Code: BLE_HOST_TIMEOUT or BLE_CONNECTION_UNAVAILABLE, Bluetooth connection severed.");
|
||||
}
|
||||
// System.println("WebhookManager onReturnRegisterWebhookSensor() Response Code: BLE_HOST_TIMEOUT or BLE_CONNECTION_UNAVAILABLE, Bluetooth connection severed.");
|
||||
Settings.unsetWebhookId();
|
||||
ErrorView.show(RezStrings.getWebhookFailed() + "\n" + RezStrings.getNoPhone() + ".");
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.WebhookFailed) as Lang.String + "\n" + WatchUi.loadResource($.Rez.Strings.NoPhone) as Lang.String + ".");
|
||||
break;
|
||||
|
||||
case Communications.BLE_QUEUE_FULL:
|
||||
if (Globals.scDebug) {
|
||||
System.println("WebhookManager onReturnRegisterWebhookSensor() Response Code: BLE_QUEUE_FULL, API calls too rapid.");
|
||||
}
|
||||
// System.println("WebhookManager onReturnRegisterWebhookSensor() Response Code: BLE_QUEUE_FULL, API calls too rapid.");
|
||||
Settings.unsetWebhookId();
|
||||
ErrorView.show(RezStrings.getWebhookFailed() + "\n" + RezStrings.getApiFlood());
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.WebhookFailed) as Lang.String + "\n" + WatchUi.loadResource($.Rez.Strings.ApiFlood) as Lang.String);
|
||||
break;
|
||||
|
||||
case Communications.NETWORK_REQUEST_TIMED_OUT:
|
||||
if (Globals.scDebug) {
|
||||
System.println("WebhookManager onReturnRegisterWebhookSensor() Response Code: NETWORK_REQUEST_TIMED_OUT, check Internet connection.");
|
||||
}
|
||||
// System.println("WebhookManager onReturnRegisterWebhookSensor() Response Code: NETWORK_REQUEST_TIMED_OUT, check Internet connection.");
|
||||
Settings.unsetWebhookId();
|
||||
ErrorView.show(RezStrings.getWebhookFailed() + "\n" + RezStrings.getNoResponse());
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.WebhookFailed) as Lang.String + "\n" + WatchUi.loadResource($.Rez.Strings.NoResponse) as Lang.String);
|
||||
break;
|
||||
|
||||
case Communications.NETWORK_RESPONSE_OUT_OF_MEMORY:
|
||||
if (Globals.scDebug) {
|
||||
System.println("WebhookManager onReturnRegisterWebhookSensor() Response Code: NETWORK_RESPONSE_OUT_OF_MEMORY, are we going too fast?");
|
||||
}
|
||||
// System.println("WebhookManager onReturnRegisterWebhookSensor() Response Code: NETWORK_RESPONSE_OUT_OF_MEMORY, are we going too fast?");
|
||||
Settings.unsetWebhookId();
|
||||
// Ignore and see if we can carry on
|
||||
break;
|
||||
case Communications.INVALID_HTTP_BODY_IN_NETWORK_RESPONSE:
|
||||
if (Globals.scDebug) {
|
||||
System.println("WebhookManager onReturnRegisterWebhookSensor() Response Code: INVALID_HTTP_BODY_IN_NETWORK_RESPONSE, check JSON is returned.");
|
||||
}
|
||||
// System.println("WebhookManager onReturnRegisterWebhookSensor() Response Code: INVALID_HTTP_BODY_IN_NETWORK_RESPONSE, check JSON is returned.");
|
||||
Settings.unsetWebhookId();
|
||||
Settings.unsetIsBatteryLevelEnabled();
|
||||
ErrorView.show(RezStrings.getWebhookFailed() + "\n" + RezStrings.getNoJson());
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.WebhookFailed) as Lang.String + "\n" + WatchUi.loadResource($.Rez.Strings.NoJson) as Lang.String);
|
||||
break;
|
||||
|
||||
case 404:
|
||||
if (Globals.scDebug) {
|
||||
System.println("WebhookManager onReturnRequestWebhookId() Response Code: 404, page not found. Check API URL setting.");
|
||||
}
|
||||
// System.println("WebhookManager onReturnRequestWebhookId() Response Code: 404, page not found. Check API URL setting.");
|
||||
Settings.unsetWebhookId();
|
||||
Settings.unsetIsBatteryLevelEnabled();
|
||||
ErrorView.show(RezStrings.getWebhookFailed() + "\n" + RezStrings.getApiUrlNotFound());
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.WebhookFailed) as Lang.String + "\n" + WatchUi.loadResource($.Rez.Strings.ApiUrlNotFound) as Lang.String);
|
||||
break;
|
||||
|
||||
case 201:
|
||||
if ((data.get("success") as Lang.Boolean or Null) == true) {
|
||||
if (Globals.scDebug) {
|
||||
System.println("WebhookManager onReturnRegisterWebhookSensor(): Success");
|
||||
}
|
||||
} else {
|
||||
if (Globals.scDebug) {
|
||||
System.println("WebhookManager onReturnRegisterWebhookSensor(): Failure");
|
||||
}
|
||||
if ((data.get("success") as Lang.Boolean or Null) != true) {
|
||||
// When uncommenting, invert the condition above.
|
||||
// System.println("WebhookManager onReturnRegisterWebhookSensor(): Success");
|
||||
// } else {
|
||||
// System.println("WebhookManager onReturnRegisterWebhookSensor(): Failure");
|
||||
Settings.unsetWebhookId();
|
||||
Settings.unsetIsBatteryLevelEnabled();
|
||||
ErrorView.show(RezStrings.getWebhookFailed());
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.WebhookFailed) as Lang.String);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
if (Globals.scDebug) {
|
||||
System.println("WebhookManager onReturnRequestWebhookId(): Unhandled HTTP response code = " + responseCode);
|
||||
}
|
||||
// System.println("WebhookManager onReturnRequestWebhookId(): Unhandled HTTP response code = " + responseCode);
|
||||
Settings.unsetWebhookId();
|
||||
Settings.unsetIsBatteryLevelEnabled();
|
||||
ErrorView.show(RezStrings.getWebhookFailed() + "\n" + RezStrings.getUnhandledHttpErr() + responseCode);
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.WebhookFailed) as Lang.String + "\n" + WatchUi.loadResource($.Rez.Strings.UnhandledHttpErr) as Lang.String + responseCode);
|
||||
}
|
||||
}
|
||||
|
||||
function registerWebhookSensor(sensor as Lang.Object) {
|
||||
if (Globals.scDebug) {
|
||||
System.println("WebhookManager registerWebhookSensor(): Registering webhook sensor: " + sensor.toString());
|
||||
}
|
||||
// System.println("WebhookManager registerWebhookSensor(): Registering webhook sensor: " + sensor.toString());
|
||||
Communications.makeWebRequest(
|
||||
Settings.getApiUrl() + "/webhook/" + Settings.getWebhookId(),
|
||||
{
|
||||
|
Reference in New Issue
Block a user