Single request to update

This commit is contained in:
Joseph Abbey
2024-08-26 18:59:17 +01:00
parent d387152593
commit e9a0c5d137
7 changed files with 167 additions and 462 deletions

View File

@ -26,8 +26,9 @@ using Toybox.Lang;
using Toybox.WatchUi;
using Toybox.Graphics;
class HomeAssistantTemplateMenuItem extends TemplateMenuItem {
class HomeAssistantTemplateMenuItem extends WatchUi.IconMenuItem {
private var mHomeAssistantService as HomeAssistantService;
private var mTemplate as Lang.String;
private var mService as Lang.String or Null;
private var mConfirm as Lang.Boolean;
private var mData as Lang.Dictionary or Null;
@ -44,21 +45,30 @@ class HomeAssistantTemplateMenuItem extends TemplateMenuItem {
} or Null,
haService as HomeAssistantService
) {
TemplateMenuItem.initialize(
WatchUi.IconMenuItem.initialize(
label,
template,
// Now this feels very "closely coupled" to the application, but it is the most reliable method instead of using a timer.
getApp().method(:updateNextMenuItem),
null,
null,
icon,
options
);
mHomeAssistantService = haService;
mTemplate = template;
mService = service;
mConfirm = confirm;
mData = data;
}
function buildTemplate() as Lang.String or Null {
return mTemplate;
}
function updateState(data as Lang.String or Null) as Void {
setSubLabel(data);
WatchUi.requestUpdate();
}
function callService() as Void {
if (mConfirm) {
WatchUi.pushView(