From b90e6c7130308cd043637e823172e026f5a4b823 Mon Sep 17 00:00:00 2001 From: Philip Abbey Date: Sat, 18 Nov 2023 15:52:02 +0000 Subject: [PATCH 1/2] Connection reporting improvements and update resumption Separation of phone connectivity and Internet access tests for finer grained feedback to the user. Updates no longer stop on absence of Internet connectivity. --- .gitignore | 1 + manifest.xml | 2 +- resources-ara/strings/strings.xml | 2 + resources-bul/strings/strings.xml | 2 + resources-ces/strings/strings.xml | 2 + resources-dan/strings/strings.xml | 4 +- resources-deu/strings/strings.xml | 6 +- resources-dut/strings/strings.xml | 2 + resources-est/strings/strings.xml | 4 +- resources-fin/strings/strings.xml | 4 +- resources-fre/strings/strings.xml | 6 +- resources-gre/strings/strings.xml | 2 + resources-heb/strings/strings.xml | 2 + resources-hrv/strings/strings.xml | 2 + resources-hun/strings/strings.xml | 2 + resources-ind/strings/strings.xml | 2 + resources-ita/strings/strings.xml | 2 + resources-jpn/strings/strings.xml | 2 + resources-kor/strings/strings.xml | 4 +- resources-lav/strings/strings.xml | 2 + resources-lit/strings/strings.xml | 2 + resources-nob/strings/strings.xml | 2 + resources-pol/strings/strings.xml | 2 + resources-por/strings/strings.xml | 2 + resources-ron/strings/strings.xml | 2 + resources-slo/strings/strings.xml | 2 + resources-slv/strings/strings.xml | 2 + resources-spa/strings/strings.xml | 2 + resources-swe/strings/strings.xml | 4 +- resources-tha/strings/strings.xml | 2 + resources-tur/strings/strings.xml | 2 + resources-ukr/strings/strings.xml | 2 + resources-vie/strings/strings.xml | 2 + resources-zhs/strings/strings.xml | 2 + resources-zht/strings/strings.xml | 2 + resources-zsm/strings/strings.xml | 2 + resources/strings/strings.xml | 2 + source/HomeAssistantApp.mc | 33 +++++-- source/HomeAssistantMenuItem.mc | 36 ++++++-- source/HomeAssistantToggleMenuItem.mc | 120 ++++++++++++++++++++------ translate.py | 2 +- 41 files changed, 226 insertions(+), 56 deletions(-) diff --git a/.gitignore b/.gitignore index dbd8c634..3605b502 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ bin/ export/ **/Thumbs.db settings.txt +export.cmd diff --git a/manifest.xml b/manifest.xml index 3f2a12b5..6c011ed8 100644 --- a/manifest.xml +++ b/manifest.xml @@ -21,7 +21,7 @@ Use "Monkey C: Edit Application" from the Visual Studio Code command palette to update the application attributes. --> - + @@ -24,7 +24,9 @@ Väljas Puudutage Menüü + Telefoniühendus puudub Interneti-ühendus puudub + Ei reageeri, kontrollige Interneti-ühendust Menüü toomise viga Rakenduse seadetes pole API-võtit Rakenduse seadetes pole API URL-i diff --git a/resources-fin/strings/strings.xml b/resources-fin/strings/strings.xml index b6c91eb2..a6bc81e5 100644 --- a/resources-fin/strings/strings.xml +++ b/resources-fin/strings/strings.xml @@ -24,9 +24,11 @@ Vinossa Napauta Valikko + Ei puhelinyhteyttä Ei Internet-yhteyttä + Ei vastausta, tarkista Internet-yhteys Valikkohakuvirhe - Sovellusasetuksissa ei ole API-avainta + Sovelluksen asetuksissa ei ole API-avainta Sovellusasetuksissa ei ole API URL-osoitetta Sovelluksen asetuksissa ei ole konfigurointi-URL-osoitetta API-kutsut liian nopeita. Hidasta pyyntöjäsi. diff --git a/resources-fre/strings/strings.xml b/resources-fre/strings/strings.xml index 356945d7..dc5321d4 100644 --- a/resources-fre/strings/strings.xml +++ b/resources-fre/strings/strings.xml @@ -20,16 +20,18 @@ HomeAssistant - Activé + Activé Désactivé Clic Menu + Pas de connexion téléphonique Pas de connexion Internet + Pas de réponse, vérifiez la connexion Internet Erreur de récupération du menu Pas de clé API dans les paramètres de l'application Aucune URL API dans les paramètres de l'application Aucune URL de configuration dans les paramètres de l'application - Appels API trop rapide. Veuillez signaler cette erreur avec les détails de l'appareil. + Appels API trop rapide. Veuillez signaler cette erreur avec les détails de l'appareil. URL introuvable. Erreur potentielle d'URL d'API dans les paramètres. URL introuvable. Erreur potentielle d'URL de configuration dans les paramètres. La requête HTTP a renvoyé un code d'erreur = diff --git a/resources-gre/strings/strings.xml b/resources-gre/strings/strings.xml index 98528b09..baa25a76 100644 --- a/resources-gre/strings/strings.xml +++ b/resources-gre/strings/strings.xml @@ -24,7 +24,9 @@ Μακριά από Παρακέντηση Μενού + Δεν υπάρχει σύνδεση τηλεφώνου Δεν υπάρχει σύνδεση στο διαδίκτυο + Καμία απάντηση, ελέγξτε τη σύνδεση στο Διαδίκτυο Σφάλμα ανάκτησης μενού Δεν υπάρχει κλειδί API στις ρυθμίσεις της εφαρμογής Δεν υπάρχει URL API στις ρυθμίσεις της εφαρμογής diff --git a/resources-heb/strings/strings.xml b/resources-heb/strings/strings.xml index bcbeaf7b..f17e60d8 100644 --- a/resources-heb/strings/strings.xml +++ b/resources-heb/strings/strings.xml @@ -24,7 +24,9 @@ כבוי בֶּרֶז תַפרִיט + אין חיבור לטלפון אין חיבור אינטרנט + אין תגובה, בדוק חיבור לאינטרנט שגיאת אחזור תפריט אין מפתח API בהגדרות האפליקציה אין כתובת API בהגדרות האפליקציה diff --git a/resources-hrv/strings/strings.xml b/resources-hrv/strings/strings.xml index 2ce08f4e..f483f239 100644 --- a/resources-hrv/strings/strings.xml +++ b/resources-hrv/strings/strings.xml @@ -24,7 +24,9 @@ Isključeno Dodirnite Jelovnik + Nema telefonske veze Nema internetske veze + Nema odgovora, provjerite internetsku vezu Pogreška dohvaćanja izbornika Nema API ključa u postavkama aplikacije Nema API URL-a u postavkama aplikacije diff --git a/resources-hun/strings/strings.xml b/resources-hun/strings/strings.xml index efe2c4b9..2a9b120c 100644 --- a/resources-hun/strings/strings.xml +++ b/resources-hun/strings/strings.xml @@ -24,7 +24,9 @@ Ki Koppintson a Menü + Nincs telefonkapcsolat Nincs internetkapcsolat + Nincs válasz, ellenőrizze az internetkapcsolatot Menü Lekérési hiba Nincs API kulcs az alkalmazás beállításaiban Nincs API URL az alkalmazás beállításai között diff --git a/resources-ind/strings/strings.xml b/resources-ind/strings/strings.xml index c3625908..eec89766 100644 --- a/resources-ind/strings/strings.xml +++ b/resources-ind/strings/strings.xml @@ -24,7 +24,9 @@ Mati Mengetuk Menu + Tidak ada koneksi Telepon Tidak ada koneksi internet + Tidak Ada Respon, periksa koneksi Internet Kesalahan Pengambilan Menu Tidak ada kunci API di pengaturan aplikasi Tidak ada URL API di pengaturan aplikasi diff --git a/resources-ita/strings/strings.xml b/resources-ita/strings/strings.xml index 0bdbc51b..f0fc0eac 100644 --- a/resources-ita/strings/strings.xml +++ b/resources-ita/strings/strings.xml @@ -24,7 +24,9 @@ Spento Rubinetto Menù + Nessuna connessione telefonica Nessuna connessione internet + Nessuna risposta, controlla la connessione Internet Errore di recupero del menu Nessuna chiave API nelle impostazioni dell'applicazione Nessun URL API nelle impostazioni dell'applicazione diff --git a/resources-jpn/strings/strings.xml b/resources-jpn/strings/strings.xml index d6bf3947..5cb64610 100644 --- a/resources-jpn/strings/strings.xml +++ b/resources-jpn/strings/strings.xml @@ -24,7 +24,9 @@ オフ タップ メニュー + 電話が接続されていません インターネット接続なし + 応答がありません。インターネット接続を確認してください メニューフェッチエラー アプリケーション設定に API キーがありません アプリケーション設定に API URL がありません diff --git a/resources-kor/strings/strings.xml b/resources-kor/strings/strings.xml index ce8e6b04..1905dde1 100644 --- a/resources-kor/strings/strings.xml +++ b/resources-kor/strings/strings.xml @@ -24,7 +24,9 @@ 끄다 수도꼭지 메뉴 + 전화 연결 없음 인터넷에 연결되지 않음 + 응답이 없습니다. 인터넷 연결을 확인하세요. 메뉴 가져오기 오류 애플리케이션 설정에 API 키가 없습니다. 애플리케이션 설정에 API URL이 없습니다. @@ -33,5 +35,5 @@ URL을 찾을 수 없습니다. 설정에 잠재적인 API URL 오류가 있습니다. URL을 찾을 수 없습니다. 설정에 잠재적인 구성 URL 오류가 있습니다. HTTP 요청이 오류 코드를 반환했습니다 = - API URL에는 후행 슬래시 '/'가 없어야 합니다. + API URL에는 후행 슬래시 '/'가 있어서는 안 됩니다. \ No newline at end of file diff --git a/resources-lav/strings/strings.xml b/resources-lav/strings/strings.xml index 6b3b24b1..727c7f75 100644 --- a/resources-lav/strings/strings.xml +++ b/resources-lav/strings/strings.xml @@ -24,7 +24,9 @@ Izslēgts Krāns Izvēlne + Nav tālruņa savienojuma Nav interneta savienojuma + Nav atbildes, pārbaudiet interneta savienojumu Izvēlnes ielādes kļūda Lietojumprogrammas iestatījumos nav API atslēgas Lietojumprogrammas iestatījumos nav API URL diff --git a/resources-lit/strings/strings.xml b/resources-lit/strings/strings.xml index 98d316b6..8627cf64 100644 --- a/resources-lit/strings/strings.xml +++ b/resources-lit/strings/strings.xml @@ -24,7 +24,9 @@ Išjungta Bakstelėkite Meniu + Nėra telefono ryšio Nėra interneto ryšio + Neatsako, patikrinkite interneto ryšį Meniu gavimo klaida Programos nustatymuose nėra API rakto Programos nustatymuose nėra API URL diff --git a/resources-nob/strings/strings.xml b/resources-nob/strings/strings.xml index 93235d4e..3974ee76 100644 --- a/resources-nob/strings/strings.xml +++ b/resources-nob/strings/strings.xml @@ -24,7 +24,9 @@ Av Trykk på Meny + Ingen telefonforbindelse Ingen Internett-tilkobling + Ingen svar, sjekk Internett-tilkoblingen Menyhentingsfeil Ingen API-nøkkel i applikasjonsinnstillingene Ingen API-URL i applikasjonsinnstillingene diff --git a/resources-pol/strings/strings.xml b/resources-pol/strings/strings.xml index 5d72ce2e..a1b68c0b 100644 --- a/resources-pol/strings/strings.xml +++ b/resources-pol/strings/strings.xml @@ -24,7 +24,9 @@ Wyłączony Uzyskiwać Menu + Brak połączenia telefonicznego Brak połączenia z internetem + Brak odpowiedzi, sprawdź połączenie internetowe Błąd pobierania menu Brak klucza API w ustawieniach aplikacji Brak adresu API w ustawieniach aplikacji diff --git a/resources-por/strings/strings.xml b/resources-por/strings/strings.xml index 76e8186c..e1b248d3 100644 --- a/resources-por/strings/strings.xml +++ b/resources-por/strings/strings.xml @@ -24,7 +24,9 @@ Desligado Tocar Cardápio + Sem conexão telefônica Sem conexão com a Internet + Sem resposta, verifique a conexão com a Internet Erro ao buscar menu Nenhuma chave de API nas configurações do aplicativo Nenhum URL de API nas configurações do aplicativo diff --git a/resources-ron/strings/strings.xml b/resources-ron/strings/strings.xml index a2b08b06..31ebd980 100644 --- a/resources-ron/strings/strings.xml +++ b/resources-ron/strings/strings.xml @@ -24,7 +24,9 @@ Oprit Atingeți Meniul + Fără conexiune telefonică Fără conexiune internet + Niciun răspuns, verificați conexiunea la internet Eroare de preluare a meniului Nicio cheie API în setările aplicației Nicio adresă URL API în setările aplicației diff --git a/resources-slo/strings/strings.xml b/resources-slo/strings/strings.xml index ad337c34..67c02d1c 100644 --- a/resources-slo/strings/strings.xml +++ b/resources-slo/strings/strings.xml @@ -24,7 +24,9 @@ Vypnuté Klepnite Ponuka + Žiadne telefónne spojenie Žiadne internetové pripojenie + Žiadna odpoveď, skontrolujte internetové pripojenie Chyba načítania ponuky V nastaveniach aplikácie nie je žiadny kľúč API V nastaveniach aplikácie nie je žiadna adresa URL rozhrania API diff --git a/resources-slv/strings/strings.xml b/resources-slv/strings/strings.xml index a4d9dc3f..57a321c1 100644 --- a/resources-slv/strings/strings.xml +++ b/resources-slv/strings/strings.xml @@ -24,7 +24,9 @@ Izključeno Tapnite meni + Ni telefonske povezave Ni internetne povezave + Ni odgovora, preverite internetno povezavo Napaka pri pridobivanju menija V nastavitvah aplikacije ni ključa API V nastavitvah aplikacije ni URL-ja API-ja diff --git a/resources-spa/strings/strings.xml b/resources-spa/strings/strings.xml index 81f7572a..95fe1f01 100644 --- a/resources-spa/strings/strings.xml +++ b/resources-spa/strings/strings.xml @@ -24,7 +24,9 @@ Apagado Grifo Menú + Sin conexión telefónica Sin conexión a Internet + No hay respuesta, verifique la conexión a Internet Error de recuperación del menú Sin clave API en la configuración de la aplicación No hay URL de API en la configuración de la aplicación diff --git a/resources-swe/strings/strings.xml b/resources-swe/strings/strings.xml index 2cdacffc..e0e131a2 100644 --- a/resources-swe/strings/strings.xml +++ b/resources-swe/strings/strings.xml @@ -24,10 +24,12 @@ Av Knacka Meny + Ingen telefonanslutning Ingen internetanslutning + Inget svar, kontrollera internetanslutningen Menyhämtningsfel Ingen API-nyckel i applikationsinställningarna - Ingen API-URL i programinställningarna + Ingen API-URL i applikationsinställningarna Ingen konfigurations-URL i programinställningarna API-anrop för snabba. Vänligen sakta ner dina förfrågningar. Webbadressen hittades inte. Potentiellt API-URL-fel i inställningarna. diff --git a/resources-tha/strings/strings.xml b/resources-tha/strings/strings.xml index a9e2fc1f..9b12cc71 100644 --- a/resources-tha/strings/strings.xml +++ b/resources-tha/strings/strings.xml @@ -24,7 +24,9 @@ ปิด แตะ เมนู + ไม่มีการเชื่อมต่อโทรศัพท์ ไม่มีการเชื่อมต่ออินเทอร์เน็ต + ไม่มีการตอบสนอง ตรวจสอบการเชื่อมต่ออินเทอร์เน็ต เมนูดึงข้อมูลผิดพลาด ไม่มีคีย์ API ในการตั้งค่าแอปพลิเคชัน ไม่มี URL API ในการตั้งค่าแอปพลิเคชัน diff --git a/resources-tur/strings/strings.xml b/resources-tur/strings/strings.xml index d37b8f9a..690aeb20 100644 --- a/resources-tur/strings/strings.xml +++ b/resources-tur/strings/strings.xml @@ -24,7 +24,9 @@ Kapalı Musluk Menü + Telefon bağlantısı yok İnternet bağlantısı yok + Yanıt Yok, İnternet bağlantısını kontrol edin Menü Alma Hatası Uygulama ayarlarında API anahtarı yok Uygulama ayarlarında API URL'si yok diff --git a/resources-ukr/strings/strings.xml b/resources-ukr/strings/strings.xml index 17794739..4916e321 100644 --- a/resources-ukr/strings/strings.xml +++ b/resources-ukr/strings/strings.xml @@ -24,7 +24,9 @@ Вимкнено Торкніться Меню + Немає телефонного зв'язку Немає підключення до Інтернету + Немає відповіді, перевірте підключення до Інтернету Помилка вибірки меню У налаштуваннях програми немає ключа API У налаштуваннях програми немає URL-адреси API diff --git a/resources-vie/strings/strings.xml b/resources-vie/strings/strings.xml index 20d15ff3..782fee7e 100644 --- a/resources-vie/strings/strings.xml +++ b/resources-vie/strings/strings.xml @@ -24,7 +24,9 @@ Tắt Vỗ nhẹ Thực đơn + Không có kết nối điện thoại Không có kết nối Internet + Không có phản hồi, kiểm tra kết nối Internet Lỗi tìm nạp menu Không có khóa API trong cài đặt ứng dụng Không có URL API trong cài đặt ứng dụng diff --git a/resources-zhs/strings/strings.xml b/resources-zhs/strings/strings.xml index dfdee430..9d603cf3 100644 --- a/resources-zhs/strings/strings.xml +++ b/resources-zhs/strings/strings.xml @@ -24,7 +24,9 @@ 离开 轻敲 菜单 + 没有电话连接 没有网络连接 + 无响应,请检查互联网连接 菜单获取错误 应用程序设置中没有 API 密钥 应用程序设置中没有 API URL diff --git a/resources-zht/strings/strings.xml b/resources-zht/strings/strings.xml index 83884371..2aa3c345 100644 --- a/resources-zht/strings/strings.xml +++ b/resources-zht/strings/strings.xml @@ -24,7 +24,9 @@ 離開 輕敲 選單 + 沒有電話連接 沒有網路連線 + 無響應,請檢查互聯網連接 選單取得錯誤 應用程式設定中沒有 API 金鑰 應用程式設定中沒有 API URL diff --git a/resources-zsm/strings/strings.xml b/resources-zsm/strings/strings.xml index 72fd8754..c8059033 100644 --- a/resources-zsm/strings/strings.xml +++ b/resources-zsm/strings/strings.xml @@ -24,7 +24,9 @@ Mati Ketik Menu + Tiada sambungan Telefon Tiada sambungan internet + Tiada Respons, semak sambungan Internet Ralat Pengambilan Menu Tiada kunci API dalam tetapan aplikasi Tiada URL API dalam tetapan aplikasi diff --git a/resources/strings/strings.xml b/resources/strings/strings.xml index 753dce20..057cac98 100644 --- a/resources/strings/strings.xml +++ b/resources/strings/strings.xml @@ -18,7 +18,9 @@ Off Tap Menu + No Phone connection No Internet connection + No Response, check Internet connection Menu Fetch Error No API key in the application settings No API URL in the application settings diff --git a/source/HomeAssistantApp.mc b/source/HomeAssistantApp.mc index 9cc5937e..16f44616 100644 --- a/source/HomeAssistantApp.mc +++ b/source/HomeAssistantApp.mc @@ -22,14 +22,15 @@ using Toybox.Application; using Toybox.Lang; using Toybox.WatchUi; using Toybox.Application.Properties; -using Toybox.Timer; class HomeAssistantApp extends Application.AppBase { hidden var mHaMenu; hidden var strNoApiKey as Lang.String; hidden var strNoApiUrl as Lang.String; hidden var strNoConfigUrl as Lang.String; + hidden var strNoPhone as Lang.String; hidden var strNoInternet as Lang.String; + hidden var strNoResponse as Lang.String; hidden var strNoMenu as Lang.String; hidden var strApiFlood as Lang.String; hidden var strConfigUrlNotFound as Lang.String; @@ -43,7 +44,9 @@ class HomeAssistantApp extends Application.AppBase { strNoApiKey = WatchUi.loadResource($.Rez.Strings.NoAPIKey); strNoApiUrl = WatchUi.loadResource($.Rez.Strings.NoApiUrl); strNoConfigUrl = WatchUi.loadResource($.Rez.Strings.NoConfigUrl); + strNoPhone = WatchUi.loadResource($.Rez.Strings.NoPhone); strNoInternet = WatchUi.loadResource($.Rez.Strings.NoInternet); + strNoResponse = WatchUi.loadResource($.Rez.Strings.NoResponse); strNoMenu = WatchUi.loadResource($.Rez.Strings.NoMenu); strApiFlood = WatchUi.loadResource($.Rez.Strings.ApiFlood); strConfigUrlNotFound = WatchUi.loadResource($.Rez.Strings.ConfigUrlNotFound); @@ -82,14 +85,19 @@ class HomeAssistantApp extends Application.AppBase { System.println("HomeAssistantMenuItem execScript(): No configuration URL in the application settings."); } return [new ErrorView(strNoConfigUrl + "."), new ErrorDelegate()] as Lang.Array; - } else if (System.getDeviceSettings().phoneConnected && System.getDeviceSettings().connectionAvailable) { - fetchMenuConfig(); - return [new WatchUi.View(), new WatchUi.BehaviorDelegate()] as Lang.Array; - } else { + } else if (! System.getDeviceSettings().phoneConnected) { + if (Globals.scDebug) { + System.println("HomeAssistantApp fetchMenuConfig(): No Phone connection, skipping API call."); + } + return [new ErrorView(strNoPhone + "."), new ErrorDelegate()] as Lang.Array; + } else if (! System.getDeviceSettings().connectionAvailable) { if (Globals.scDebug) { System.println("HomeAssistantApp fetchMenuConfig(): No Internet connection, skipping API call."); } return [new ErrorView(strNoInternet + "."), new ErrorDelegate()] as Lang.Array; + } else { + fetchMenuConfig(); + return [new WatchUi.View(), new WatchUi.BehaviorDelegate()] as Lang.Array; } } @@ -100,15 +108,24 @@ class HomeAssistantApp extends Application.AppBase { System.println("HomeAssistantApp onReturnFetchMenuConfig() Response Code: " + responseCode); System.println("HomeAssistantApp onReturnFetchMenuConfig() Response Data: " + data); } - if (responseCode == Communications.BLE_QUEUE_FULL) { + if (responseCode == Communications.BLE_HOST_TIMEOUT || responseCode == Communications.BLE_CONNECTION_UNAVAILABLE) { + if (Globals.scDebug) { + System.println("HomeAssistantApp onReturnFetchMenuConfig() Response Code: BLE_HOST_TIMEOUT or BLE_CONNECTION_UNAVAILABLE, Bluetooth connection severed."); + } + WatchUi.pushView(new ErrorView(strNoPhone + "."), new ErrorDelegate(), WatchUi.SLIDE_UP); + } else if (responseCode == Communications.BLE_QUEUE_FULL) { if (Globals.scDebug) { System.println("HomeAssistantApp onReturnFetchMenuConfig() Response Code: BLE_QUEUE_FULL, API calls too rapid."); } - var cw = WatchUi.getCurrentView(); - if (!(cw[0] instanceof ErrorView)) { + if (!(WatchUi.getCurrentView()[0] instanceof ErrorView)) { // Avoid pushing multiple ErrorViews WatchUi.pushView(new ErrorView(strApiFlood), new ErrorDelegate(), WatchUi.SLIDE_UP); } + } else if (responseCode == Communications.NETWORK_REQUEST_TIMED_OUT) { + if (Globals.scDebug) { + System.println("HomeAssistantApp onReturnFetchMenuConfig() Response Code: NETWORK_REQUEST_TIMED_OUT, check Internet connection."); + } + WatchUi.pushView(new ErrorView(strNoResponse), new ErrorDelegate(), WatchUi.SLIDE_UP); } else if (responseCode == 404) { if (Globals.scDebug) { System.println("HomeAssistantApp onReturnFetchMenuConfig() Response Code: 404, page not found. Check Configuration URL setting."); diff --git a/source/HomeAssistantMenuItem.mc b/source/HomeAssistantMenuItem.mc index eebe1e5b..ddb3d632 100644 --- a/source/HomeAssistantMenuItem.mc +++ b/source/HomeAssistantMenuItem.mc @@ -25,7 +25,9 @@ using Toybox.Application.Properties; class HomeAssistantMenuItem extends WatchUi.MenuItem { hidden var mApiKey as Lang.String; + hidden var strNoPhone as Lang.String; hidden var strNoInternet as Lang.String; + hidden var strNoResponse as Lang.String; hidden var strApiFlood as Lang.String; hidden var strApiUrlNotFound as Lang.String; hidden var strUnhandledHttpErr as Lang.String; @@ -41,7 +43,9 @@ class HomeAssistantMenuItem extends WatchUi.MenuItem { :icon as Graphics.BitmapType or WatchUi.Drawable or Lang.Symbol } or Null ) { + strNoPhone = WatchUi.loadResource($.Rez.Strings.NoPhone); strNoInternet = WatchUi.loadResource($.Rez.Strings.NoInternet); + strNoResponse = WatchUi.loadResource($.Rez.Strings.NoResponse); strApiFlood = WatchUi.loadResource($.Rez.Strings.ApiFlood); strApiUrlNotFound = WatchUi.loadResource($.Rez.Strings.ApiUrlNotFound); strUnhandledHttpErr = WatchUi.loadResource($.Rez.Strings.UnhandledHttpErr); @@ -62,15 +66,24 @@ class HomeAssistantMenuItem extends WatchUi.MenuItem { System.println("HomeAssistantMenuItem onReturnExecScript() Response Code: " + responseCode); System.println("HomeAssistantMenuItem onReturnExecScript() Response Data: " + data); } - if (responseCode == Communications.BLE_QUEUE_FULL) { + if (responseCode == Communications.BLE_HOST_TIMEOUT || responseCode == Communications.BLE_CONNECTION_UNAVAILABLE) { + if (Globals.scDebug) { + System.println("HomeAssistantMenuItem onReturnExecScript() Response Code: BLE_HOST_TIMEOUT or BLE_CONNECTION_UNAVAILABLE, Bluetooth connection severed."); + } + WatchUi.pushView(new ErrorView(strNoPhone + "."), new ErrorDelegate(), WatchUi.SLIDE_UP); + } else if (responseCode == Communications.BLE_QUEUE_FULL) { if (Globals.scDebug) { System.println("HomeAssistantMenuItem onReturnExecScript() Response Code: BLE_QUEUE_FULL, API calls too rapid."); } - var cw = WatchUi.getCurrentView(); - if (!(cw[0] instanceof ErrorView)) { + if (!(WatchUi.getCurrentView()[0] instanceof ErrorView)) { // Avoid pushing multiple ErrorViews WatchUi.pushView(new ErrorView(strApiFlood), new ErrorDelegate(), WatchUi.SLIDE_UP); } + } else if (responseCode == Communications.NETWORK_REQUEST_TIMED_OUT) { + if (Globals.scDebug) { + System.println("HomeAssistantMenuItem onReturnExecScript() Response Code: NETWORK_REQUEST_TIMED_OUT, check Internet connection."); + } + WatchUi.pushView(new ErrorView(strNoResponse), new ErrorDelegate(), WatchUi.SLIDE_UP); } else if (responseCode == 404) { if (Globals.scDebug) { System.println("HomeAssistantMenuItem onReturnExecScript() Response Code: 404, page not found. Check API URL setting."); @@ -115,7 +128,17 @@ class HomeAssistantMenuItem extends WatchUi.MenuItem { }, :responseType => Communications.HTTP_RESPONSE_CONTENT_TYPE_JSON }; - if (System.getDeviceSettings().phoneConnected && System.getDeviceSettings().connectionAvailable) { + if (! System.getDeviceSettings().phoneConnected) { + if (Globals.scDebug) { + System.println("HomeAssistantMenuItem execScript(): No Phone connection, skipping API call."); + } + WatchUi.pushView(new ErrorView(strNoPhone + "."), new ErrorDelegate(), WatchUi.SLIDE_UP); + } else if (! System.getDeviceSettings().connectionAvailable) { + if (Globals.scDebug) { + System.println("HomeAssistantMenuItem execScript(): No Internet connection, skipping API call."); + } + WatchUi.pushView(new ErrorView(strNoInternet + "."), new ErrorDelegate(), WatchUi.SLIDE_UP); + } else { // Updated SDK and got a new error // ERROR: venu: Cannot find symbol ':substring' on type 'PolyType'. var id = mIdentifier as Lang.String; @@ -153,11 +176,6 @@ class HomeAssistantMenuItem extends WatchUi.MenuItem { new Attention.VibeProfile(50, 100) // On for 100ms ]); } - } else { - if (Globals.scDebug) { - System.println("HomeAssistantMenuItem execScript(): No Internet connection, skipping API call."); - } - WatchUi.pushView(new ErrorView(strNoInternet + "."), new ErrorDelegate(), WatchUi.SLIDE_UP); } } diff --git a/source/HomeAssistantToggleMenuItem.mc b/source/HomeAssistantToggleMenuItem.mc index 7c080cc4..538ae5a0 100644 --- a/source/HomeAssistantToggleMenuItem.mc +++ b/source/HomeAssistantToggleMenuItem.mc @@ -22,10 +22,13 @@ using Toybox.Lang; using Toybox.WatchUi; using Toybox.Graphics; using Toybox.Application.Properties; +using Toybox.Timer; class HomeAssistantToggleMenuItem extends WatchUi.ToggleMenuItem { hidden var mApiKey as Lang.String; + hidden var strNoPhone as Lang.String; hidden var strNoInternet as Lang.String; + hidden var strNoResponse as Lang.String; hidden var strApiFlood as Lang.String; hidden var strApiUrlNotFound as Lang.String; hidden var strUnhandledHttpErr as Lang.String; @@ -43,7 +46,9 @@ class HomeAssistantToggleMenuItem extends WatchUi.ToggleMenuItem { :icon as Graphics.BitmapType or WatchUi.Drawable or Lang.Symbol } or Null ) { + strNoPhone = WatchUi.loadResource($.Rez.Strings.NoPhone); strNoInternet = WatchUi.loadResource($.Rez.Strings.NoInternet); + strNoResponse = WatchUi.loadResource($.Rez.Strings.NoResponse); strApiFlood = WatchUi.loadResource($.Rez.Strings.ApiFlood); strApiUrlNotFound = WatchUi.loadResource($.Rez.Strings.ApiUrlNotFound); strUnhandledHttpErr = WatchUi.loadResource($.Rez.Strings.UnhandledHttpErr); @@ -70,26 +75,41 @@ class HomeAssistantToggleMenuItem extends WatchUi.ToggleMenuItem { System.println("HomeAssistantToggleMenuItem onReturnGetState() Response Code: " + responseCode); System.println("HomeAssistantToggleMenuItem onReturnGetState() Response Data: " + data); } - if (responseCode == Communications.BLE_QUEUE_FULL) { + // Provide the ability to terminate updating chain of calls for a permanent network error. + var keepUpdating = true; + if (responseCode == Communications.BLE_HOST_TIMEOUT || responseCode == Communications.BLE_CONNECTION_UNAVAILABLE) { + if (Globals.scDebug) { + System.println("HomeAssistantToggleMenuItem onReturnGetState() Response Code: BLE_HOST_TIMEOUT or BLE_CONNECTION_UNAVAILABLE, Bluetooth connection severed."); + } + if (!(WatchUi.getCurrentView()[0] instanceof ErrorView)) { + // Avoid pushing multiple ErrorViews + WatchUi.pushView(new ErrorView(strNoPhone + "."), new ErrorDelegate(), WatchUi.SLIDE_UP); + } + } else if (responseCode == Communications.BLE_QUEUE_FULL) { if (Globals.scDebug) { System.println("HomeAssistantToggleMenuItem onReturnGetState() Response Code: BLE_QUEUE_FULL, API calls too rapid."); } - var cw = WatchUi.getCurrentView(); - if (!(cw[0] instanceof ErrorView)) { + if (!(WatchUi.getCurrentView()[0] instanceof ErrorView)) { // Avoid pushing multiple ErrorViews WatchUi.pushView(new ErrorView(strApiFlood), new ErrorDelegate(), WatchUi.SLIDE_UP); } - // Now this feels very "closely coupled" to the application, but it is the most reliable method instead of using a timer. - getApp().updateNextMenuItem(); + } else if (responseCode == Communications.NETWORK_REQUEST_TIMED_OUT) { + if (Globals.scDebug) { + System.println("HomeAssistantToggleMenuItem onReturnGetState() Response Code: NETWORK_REQUEST_TIMED_OUT, check Internet connection."); + } + if (!(WatchUi.getCurrentView()[0] instanceof ErrorView)) { + // Avoid pushing multiple ErrorViews + WatchUi.pushView(new ErrorView(strNoResponse), new ErrorDelegate(), WatchUi.SLIDE_UP); + } } else if (responseCode == 404) { if (Globals.scDebug) { System.println("HomeAssistantToggleMenuItem onReturnGetState() Response Code: 404, page not found. Check API URL setting."); } - var cw = WatchUi.getCurrentView(); - if (!(cw[0] instanceof ErrorView)) { + if (!(WatchUi.getCurrentView()[0] instanceof ErrorView)) { // Avoid pushing multiple ErrorViews WatchUi.pushView(new ErrorView(strApiUrlNotFound), new ErrorDelegate(), WatchUi.SLIDE_UP); } + keepUpdating = false; } else if (responseCode == 200) { var state = data.get("state") as Lang.String; if (Globals.scDebug) { @@ -99,13 +119,19 @@ class HomeAssistantToggleMenuItem extends WatchUi.ToggleMenuItem { setLabel((data.get("attributes") as Lang.Dictionary).get("friendly_name") as Lang.String); } setUiToggle(state); - // Now this feels very "closely coupled" to the application, but it is the most reliable method instead of using a timer. - getApp().updateNextMenuItem(); } else { if (Globals.scDebug) { System.println("HomeAssistantToggleMenuItem onReturnGetState(): Unhandled HTTP response code = " + responseCode); } - WatchUi.pushView(new ErrorView(strUnhandledHttpErr + responseCode ), new ErrorDelegate(), WatchUi.SLIDE_UP); + if (!(WatchUi.getCurrentView()[0] instanceof ErrorView)) { + // Avoid pushing multiple ErrorViews + WatchUi.pushView(new ErrorView(strUnhandledHttpErr + responseCode ), new ErrorDelegate(), WatchUi.SLIDE_UP); + } + } + if (keepUpdating) { + // Now this feels very "closely coupled" to the application, but it is the most reliable method instead of using a timer. + getApp().updateNextMenuItem(); + System.println("HomeAssistantToggleMenuItem onReturnGetState(): Updated " + mIdentifier); } } @@ -117,7 +143,24 @@ class HomeAssistantToggleMenuItem extends WatchUi.ToggleMenuItem { }, :responseType => Communications.HTTP_RESPONSE_CONTENT_TYPE_JSON }; - if (System.getDeviceSettings().phoneConnected && System.getDeviceSettings().connectionAvailable) { + var keepUpdating = true; + if (! System.getDeviceSettings().phoneConnected) { + if (Globals.scDebug) { + System.println("HomeAssistantToggleMenuItem getState(): No Phone connection, skipping API call."); + } + if (!(WatchUi.getCurrentView()[0] instanceof ErrorView)) { + // Avoid pushing multiple ErrorViews + WatchUi.pushView(new ErrorView(strNoPhone + "."), new ErrorDelegate(), WatchUi.SLIDE_UP); + } + } else if (! System.getDeviceSettings().connectionAvailable) { + if (Globals.scDebug) { + System.println("HomeAssistantToggleMenuItem getState(): No Internet connection, skipping API call."); + } + if (!(WatchUi.getCurrentView()[0] instanceof ErrorView)) { + // Avoid pushing multiple ErrorViews + WatchUi.pushView(new ErrorView(strNoInternet + "."), new ErrorDelegate(), WatchUi.SLIDE_UP); + } + } else { var url = Properties.getValue("api_url") + "/states/" + mIdentifier; if (Globals.scDebug) { System.println("HomeAssistantToggleMenuItem getState() URL=" + url); @@ -128,11 +171,17 @@ class HomeAssistantToggleMenuItem extends WatchUi.ToggleMenuItem { options, method(:onReturnGetState) ); - } else { - if (Globals.scDebug) { - System.println("HomeAssistantToggleMenuItem getState(): No Internet connection, skipping API call."); - } - WatchUi.pushView(new ErrorView(strNoInternet + "."), new ErrorDelegate(), WatchUi.SLIDE_UP); + // The update is called by onReturnGetState() instead + keepUpdating = false; + } + // On temporary failure, keep the updating going. + if (keepUpdating) { + // Need to avoid an infinite loop where the pushed ErrorView does not appear before getState() is called again + // and the call stack overflows. So continue the call chain from somewhere asynchronous. + 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), 500, false); + System.println("HomeAssistantToggleMenuItem getState(): Updated failed " + mIdentifier); } } @@ -143,20 +192,26 @@ class HomeAssistantToggleMenuItem extends WatchUi.ToggleMenuItem { System.println("HomeAssistantToggleMenuItem onReturnSetState() Response Code: " + responseCode); System.println("HomeAssistantToggleMenuItem onReturnSetState() Response Data: " + data); } - if (responseCode == Communications.BLE_QUEUE_FULL) { + if (responseCode == Communications.BLE_HOST_TIMEOUT || responseCode == Communications.BLE_CONNECTION_UNAVAILABLE) { + if (Globals.scDebug) { + System.println("HomeAssistantToggleMenuItem onReturnSetState() Response Code: BLE_HOST_TIMEOUT or BLE_CONNECTION_UNAVAILABLE, Bluetooth connection severed."); + } + WatchUi.pushView(new ErrorView(strNoPhone + "."), new ErrorDelegate(), WatchUi.SLIDE_UP); + } else if (responseCode == Communications.BLE_QUEUE_FULL) { if (Globals.scDebug) { System.println("HomeAssistantToggleMenuItem onReturnSetState() Response Code: BLE_QUEUE_FULL, API calls too rapid."); } WatchUi.pushView(new ErrorView(strApiFlood), new ErrorDelegate(), WatchUi.SLIDE_UP); + } else if (responseCode == Communications.NETWORK_REQUEST_TIMED_OUT) { + if (Globals.scDebug) { + System.println("HomeAssistantToggleMenuItem onReturnSetState() Response Code: NETWORK_REQUEST_TIMED_OUT, check Internet connection."); + } + WatchUi.pushView(new ErrorView(strNoResponse), new ErrorDelegate(), WatchUi.SLIDE_UP); } else if (responseCode == 404) { if (Globals.scDebug) { System.println("HomeAssistantToggleMenuItem onReturnSetState() Response Code: 404, page not found. Check API URL setting."); } - var cw = WatchUi.getCurrentView(); - if (!(cw[0] instanceof ErrorView)) { - // Avoid pushing multiple ErrorViews - WatchUi.pushView(new ErrorView(strApiUrlNotFound), new ErrorDelegate(), WatchUi.SLIDE_UP); - } + WatchUi.pushView(new ErrorView(strApiUrlNotFound), new ErrorDelegate(), WatchUi.SLIDE_UP); } else if (responseCode == 200) { var state; var d = data as Lang.Array; @@ -186,7 +241,21 @@ class HomeAssistantToggleMenuItem extends WatchUi.ToggleMenuItem { }, :responseType => Communications.HTTP_RESPONSE_CONTENT_TYPE_JSON }; - if (System.getDeviceSettings().phoneConnected && System.getDeviceSettings().connectionAvailable) { + if (! System.getDeviceSettings().phoneConnected) { + if (Globals.scDebug) { + System.println("HomeAssistantToggleMenuItem getState(): No Phone connection, skipping API call."); + } + // Toggle the UI back + setEnabled(!isEnabled()); + WatchUi.pushView(new ErrorView(strNoPhone + "."), new ErrorDelegate(), WatchUi.SLIDE_UP); + } else if (! System.getDeviceSettings().connectionAvailable) { + if (Globals.scDebug) { + System.println("HomeAssistantToggleMenuItem getState(): No Internet connection, skipping API call."); + } + // Toggle the UI back + setEnabled(!isEnabled()); + WatchUi.pushView(new ErrorView(strNoInternet + "."), new ErrorDelegate(), WatchUi.SLIDE_UP); + } else { // Updated SDK and got a new error // ERROR: venu: Cannot find symbol ':substring' on type 'PolyType'. var id = mIdentifier as Lang.String; @@ -208,11 +277,6 @@ class HomeAssistantToggleMenuItem extends WatchUi.ToggleMenuItem { options, method(:onReturnSetState) ); - } else { - if (Globals.scDebug) { - System.println("HomeAssistantToggleMenuItem setState(): No Internet connection, skipping API call."); - } - WatchUi.pushView(new ErrorView(strNoInternet + "."), new ErrorDelegate(), WatchUi.SLIDE_UP); } } diff --git a/translate.py b/translate.py index 1ba9746d..1c5f013b 100644 --- a/translate.py +++ b/translate.py @@ -81,7 +81,7 @@ langLength = len(languages) exceptionIds: list[str] = ["AppName", "AppVersionTitle"] -titleIds: list[str] = ["setMode", "tapIcon"] +titleIds: list[str] = [] i = 1 with open("./resources/strings/strings.xml", "r") as f: From d6c6657ade2af17f9e30d2797e1023b7e2fbe125 Mon Sep 17 00:00:00 2001 From: philipabbey Date: Sat, 18 Nov 2023 16:01:19 +0000 Subject: [PATCH 2/2] Apply automatic changes --- resources-deu/strings/strings.xml | 4 ++-- resources-est/strings/strings.xml | 2 +- resources-fin/strings/strings.xml | 2 +- resources-fre/strings/strings.xml | 4 ++-- resources-ind/strings/strings.xml | 2 +- resources-kor/strings/strings.xml | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/resources-deu/strings/strings.xml b/resources-deu/strings/strings.xml index f150d41a..f57ddb4f 100644 --- a/resources-deu/strings/strings.xml +++ b/resources-deu/strings/strings.xml @@ -23,7 +23,7 @@ An Aus Antippen - Menü + Menü Keine Telefonverbindung Keine Internetverbindung Keine Antwort, überprüfen Sie die Internetverbindung @@ -34,6 +34,6 @@ API-Aufrufe zu schnell. Bitte verlangsamen Sie Ihre Anfragen. URL nicht gefunden. Möglicher API-URL-Fehler in den Einstellungen. URL nicht gefunden. Möglicher Konfigurations-URL-Fehler in den Einstellungen. - Die HTTP-Anfrage gab folgenden Fehlercode zurück = + Die HTTP-Anfrage gab folgenden Fehlercode zurück = Die API-URL darf keinen abschließenden Schrägstrich „/“ enthalten. \ No newline at end of file diff --git a/resources-est/strings/strings.xml b/resources-est/strings/strings.xml index 01ec6bd5..ab47973e 100644 --- a/resources-est/strings/strings.xml +++ b/resources-est/strings/strings.xml @@ -31,7 +31,7 @@ Rakenduse seadetes pole API-võtit Rakenduse seadetes pole API URL-i Rakenduse seadetes pole konfiguratsiooni URL-i - API-kutsed liiga kiired. Palun aeglustage taotluste esitamist. + API-kõned liiga kiired. Palun aeglustage oma taotlusi. URL-i ei leitud. Võimalik API URL-i viga seadetes. URL-i ei leitud. Võimalik konfiguratsiooni URL-i viga seadetes. HTTP päring tagastas veakoodi = diff --git a/resources-fin/strings/strings.xml b/resources-fin/strings/strings.xml index a6bc81e5..fa32bf2e 100644 --- a/resources-fin/strings/strings.xml +++ b/resources-fin/strings/strings.xml @@ -28,7 +28,7 @@ Ei Internet-yhteyttä Ei vastausta, tarkista Internet-yhteys Valikkohakuvirhe - Sovelluksen asetuksissa ei ole API-avainta + Sovellusasetuksissa ei ole API-avainta Sovellusasetuksissa ei ole API URL-osoitetta Sovelluksen asetuksissa ei ole konfigurointi-URL-osoitetta API-kutsut liian nopeita. Hidasta pyyntöjäsi. diff --git a/resources-fre/strings/strings.xml b/resources-fre/strings/strings.xml index dc5321d4..1efc9eaa 100644 --- a/resources-fre/strings/strings.xml +++ b/resources-fre/strings/strings.xml @@ -20,7 +20,7 @@ HomeAssistant - Activé + Activé Désactivé Clic Menu @@ -31,7 +31,7 @@ Pas de clé API dans les paramètres de l'application Aucune URL API dans les paramètres de l'application Aucune URL de configuration dans les paramètres de l'application - Appels API trop rapide. Veuillez signaler cette erreur avec les détails de l'appareil. + Appels API trop rapide. Veuillez signaler cette erreur avec les détails de l'appareil. URL introuvable. Erreur potentielle d'URL d'API dans les paramètres. URL introuvable. Erreur potentielle d'URL de configuration dans les paramètres. La requête HTTP a renvoyé un code d'erreur = diff --git a/resources-ind/strings/strings.xml b/resources-ind/strings/strings.xml index eec89766..f2f617a9 100644 --- a/resources-ind/strings/strings.xml +++ b/resources-ind/strings/strings.xml @@ -30,7 +30,7 @@ Kesalahan Pengambilan Menu Tidak ada kunci API di pengaturan aplikasi Tidak ada URL API di pengaturan aplikasi - Tidak ada URL konfigurasi di pengaturan aplikasi + Tidak ada URL konfigurasi dalam pengaturan aplikasi Panggilan API terlalu cepat. Harap memperlambat permintaan Anda. URL tidak ditemukan. Potensi kesalahan URL API dalam pengaturan. URL tidak ditemukan. Potensi kesalahan URL Konfigurasi dalam pengaturan. diff --git a/resources-kor/strings/strings.xml b/resources-kor/strings/strings.xml index 1905dde1..b65012ea 100644 --- a/resources-kor/strings/strings.xml +++ b/resources-kor/strings/strings.xml @@ -35,5 +35,5 @@ URL을 찾을 수 없습니다. 설정에 잠재적인 API URL 오류가 있습니다. URL을 찾을 수 없습니다. 설정에 잠재적인 구성 URL 오류가 있습니다. HTTP 요청이 오류 코드를 반환했습니다 = - API URL에는 후행 슬래시 '/'가 있어서는 안 됩니다. + API URL에는 후행 슬래시 '/'가 없어야 합니다. \ No newline at end of file