From 10696819a886473ee84a72314abdfef3d402d9b2 Mon Sep 17 00:00:00 2001 From: RonnyWinkler Date: Thu, 18 Jul 2024 19:13:36 +0200 Subject: [PATCH] 1.6.2 Small technical fixes. --- .homeychangelog.json | 4 ++++ .homeycompose/app.json | 2 +- app.json | 2 +- drivers/basedevice.js | 39 +++++++++++++++++++++++++++++---------- lib/Client.js | 9 +++++++-- 5 files changed, 42 insertions(+), 14 deletions(-) diff --git a/.homeychangelog.json b/.homeychangelog.json index b76a91a..fa18f90 100644 --- a/.homeychangelog.json +++ b/.homeychangelog.json @@ -590,6 +590,10 @@ "1.6.1": { "en": "Fixed capability update (manually added, power).", "de": "Capability-Aktualisierung korrigiert (manuell hinzugefĆ¼gt, Energie)." + }, + "1.6.2": { + "en": "Small technical fixes.", + "de": "Kleine technische Korrekturen." } } diff --git a/.homeycompose/app.json b/.homeycompose/app.json index 5ff90dd..b998049 100644 --- a/.homeycompose/app.json +++ b/.homeycompose/app.json @@ -1,6 +1,6 @@ { "id": "io.home-assistant.community", - "version": "1.6.1", + "version": "1.6.2", "compatibility": ">=8.1.0", "sdk": 3, "brandColor": "#0DA6EA", diff --git a/app.json b/app.json index 56af961..69ecae2 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.6.1", + "version": "1.6.2", "compatibility": ">=8.1.0", "sdk": 3, "brandColor": "#0DA6EA", diff --git a/drivers/basedevice.js b/drivers/basedevice.js index 981b7c8..5f9d739 100644 --- a/drivers/basedevice.js +++ b/drivers/basedevice.js @@ -7,7 +7,7 @@ const lodashget = require('lodash.get'); 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 = 3; +const DEVICE_INIT_TIMEOUT = 4; const DEVICE_MAX_DEVICE_ENTITIES = 20; const defaultValueConverter = { @@ -65,11 +65,13 @@ class BaseDevice extends Homey.Device { } // Init device with a short timeout to wait for initial entities - // this.timeoutInitDevice = this.homey.setTimeout( async () => - // this.onInitDevice().catch(e => console.log(e)), - // DEVICE_INIT_TIMEOUT * 1000 ); + this.timeoutInitDevice = this.homey.setTimeout( async () => + // this.onInitDevice().catch(e => console.log(e)), + this.homey.app.enqueueDeviceInit(this.onInitDevice.bind(this)), + DEVICE_INIT_TIMEOUT * 1000 ); + // Queue device init in a queue to process sequential - this.homey.app.enqueueDeviceInit(this.onInitDevice.bind(this)); + // this.homey.app.enqueueDeviceInit(this.onInitDevice.bind(this)); } async onAdded() { @@ -471,6 +473,12 @@ class BaseDevice extends Homey.Device { else{ newValue = entityValue; } + if (newValue == undefined ){ + newValue = ''; + } + if (oldValue == undefined ){ + oldValue = ''; + } tokens.value_string_old = oldValue; tokens.value_string = newValue; await this.setCapabilityValue(keys[i], newValue); @@ -503,8 +511,19 @@ class BaseDevice extends Homey.Device { else{ newValue = parseFloat(entityValue); } - tokens.value_number_old = oldValue; - tokens.value_number = newValue; + // set value to "0" to prevent flow trigger error + if (oldValue == null || oldValue == undefined){ + tokens.value_number_old = 0; + } + else{ + tokens.value_number_old = oldValue; + } + if (newValue == null || newValue == undefined){ + tokens.value_number = 0; + } + else{ + tokens.value_number = newValue; + } await this.setCapabilityValue(keys[i], newValue); } else if (keys[i].startsWith("onoff") || keys[i].startsWith("onoff_button") || keys[i].startsWith("onoff_state") ){ @@ -550,14 +569,14 @@ class BaseDevice extends Homey.Device { // trigger flow if (this.homey.app){ // Standard capaility changed trigger - this.homey.app._flowTriggerCapabilityChanged.trigger(this, tokens, state).catch(error => {this.log("Error triggering flow [capability_changed]: "+error.message)}); + this.homey.app._flowTriggerCapabilityChanged.trigger(this, tokens, state).catch(error => {this.log("Error triggering flow [capability_changed] for capability "+tokens.capability+": "+error.message)}); // additional alarm on/off trigger if (keys[i].startsWith("alarm") || keys[i].startsWith("onoff")){ if (newValue){ - this.homey.app._flowTriggerGenericAlarmTrue.trigger(this, tokens, state).catch(error => {this.log("Error triggering flow [generic_alarm_true]: "+error.message)}); + this.homey.app._flowTriggerGenericAlarmTrue.trigger(this, tokens, state).catch(error => {this.log("Error triggering flow [generic_alarm_true] for capability "+tokens.capability+": "+error.message)}); } else{ - this.homey.app._flowTriggerGenericAlarmFalse.trigger(this, tokens, state).catch(error => {this.log("Error triggering flow [generic_alarm_false]: "+error.message)}); + this.homey.app._flowTriggerGenericAlarmFalse.trigger(this, tokens, state).catch(error => {this.log("Error triggering flow [generic_alarm_false] for capability "+tokens.capability+": "+error.message)}); } } } diff --git a/lib/Client.js b/lib/Client.js index 9ea338f..d92f2c6 100644 --- a/lib/Client.js +++ b/lib/Client.js @@ -581,7 +581,12 @@ class Client extends Homey.SimpleClass { this._app.log("Connection event: ready"); // Read all entity states into buffer - await this._getStates(); + try{ + await this._getStates(); + } + catch(error){ + this._app.log("_onEventConnectionReady(): Error reading entity states after connection ready: ", error); + } } async _onEventConnectionDisconnected(connection, data) { // possible events: "ready" | "disconnected" | "reconnect-error"; @@ -641,7 +646,7 @@ class Client extends Homey.SimpleClass { // Get additional power entity for device by entityId let powerEntity = this._powerEntityRegistration.get(entityId); - if(powerEntity != null) { + if(powerEntity != null && powerEntity != undefined) { await powerEntity.onEntityUpdate(data.new_state); } }