diff --git a/.homeychangelog.json b/.homeychangelog.json index 23050c1..460c1db 100644 --- a/.homeychangelog.json +++ b/.homeychangelog.json @@ -634,6 +634,10 @@ "1.8.4": { "en": "Fix for reading initial energy settings for new devices.", "de": "Korrektur beim Lesen der Energie-Einstellungen für neue Geräte." + }, + "1.8.5": { + "en": "Fixed error on device init after changing device entities.", + "de": "Fehler beim Initialisieren eines Gerätes nach einer Entitaten-Aktualisierung korrigiert." } } diff --git a/.homeycompose/app.json b/.homeycompose/app.json index 7c13d9a..b21429f 100644 --- a/.homeycompose/app.json +++ b/.homeycompose/app.json @@ -1,6 +1,6 @@ { "id": "io.home-assistant.community", - "version": "1.8.3", + "version": "1.8.5", "compatibility": ">=12.2.0", "sdk": 3, "brandColor": "#0DA6EA", diff --git a/app.json b/app.json index 544fad4..6d458c7 100644 --- a/app.json +++ b/app.json @@ -1,7 +1,7 @@ { "_comment": "This file is generated. Please edit .homeycompose/app.json instead.", "id": "io.home-assistant.community", - "version": "1.8.3", + "version": "1.8.5", "compatibility": ">=12.2.0", "sdk": 3, "brandColor": "#0DA6EA", diff --git a/drivers/basedevice.js b/drivers/basedevice.js index 88e166b..ba7709f 100644 --- a/drivers/basedevice.js +++ b/drivers/basedevice.js @@ -9,6 +9,7 @@ const CAPABILITIES_SET_DEBOUNCE = 100; // Device init timeout (sec). Reads entity data with a delay to get ready on app start const DEVICE_INIT_TIMEOUT = 4; +const DEVICE_ONSETTINGS_TIMEOUT = 2; const DEVICE_MAX_DEVICE_ENTITIES = 20; const defaultValueConverter = { @@ -46,14 +47,26 @@ class BaseDevice extends Homey.Device { // // update settings from device attributes try{ - this.setSettings({class: this.getClass()}); + try{ + await this.setSettings({class: this.getClass()}); + } + catch(error){ + // catch error for setSettings() while onSettings() is still pending + this.log("basedevice.onInit(): Error setting device class: "+error.message); + } let energy = this.getEnergy() || {}; let settings = {}; settings["set_energy_cumulative"] = energy["cumulative"] != undefined ? energy["cumulative"] : false; settings["set_energy_home_battery"] = energy["homeBattery"] != undefined ? energy["homeBattery"] : false; settings["set_energy_cumulative_imported_capability"] = energy["cumulativeImportedCapability"] != undefined ? energy["cumulativeImportedCapability"] : ""; settings["set_energy_cumulative_exported_capability"] = energy["cumulativeExportedCapability"] != undefined ? energy["cumulativeExportedCapability"] : ""; - await this.setSettings(settings); + try{ + await this.setSettings(settings); + } + catch(error){ + // catch error for setSettings() while onSettings() is still pending + this.log("basedevice.onInit(): Error setting device class: "+error.message); + } } catch(error){ this.error("Error updating device enrergy settings: "+error.message); @@ -430,7 +443,16 @@ class BaseDevice extends Homey.Device { } } - await this.onInit(); + this.homey.setTimeout( async () => + { + try{ + await this.onInit(); + } + catch(error){ + this.log("baseDevice.addDeviceEntities() onInit() error: "+error.message); + } + }, + DEVICE_ONSETTINGS_TIMEOUT * 1000 ); } async removeDeviceEntities(type=null){ diff --git a/locales/de.json b/locales/de.json index 1b73010..90b933e 100644 --- a/locales/de.json +++ b/locales/de.json @@ -100,7 +100,7 @@ "converter_code_03": "(value) => {\nreturn new Date(value).toLocaleString(\n 'de-DE',\n {\n hour12s: false,\n hour: '2-digit',\n minute: '2-digit',\n day: '2-digit',\n month: '2-digit',\n year: 'numeric'\n });\n}", "converter_text_04": "Temperatur-Konvertierung °F=>°C", "converter_code_04": "(value) => { return (parseFloat(value) - 32) * 5/9; }", - "converter_text_05": "Extrahiere Wert aus Test: 'In 3 minutes' => 3", + "converter_text_05": "Extrahiere Wert aus Text: 'In 3 minutes' => 3", "converter_code_05": "(value) => { return value.split(' ')[1]; }", "add_as_main_capability": "Als Haupt-Capability hinzufügen", "result_count_01": "Zeige",