Skip to content

Commit

Permalink
1.6.2
Browse files Browse the repository at this point in the history
Small technical fixes.
  • Loading branch information
RonnyWinkler committed Jul 18, 2024
1 parent 2bb93b0 commit 1069681
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 14 deletions.
4 changes: 4 additions & 0 deletions .homeychangelog.json
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}

}
2 changes: 1 addition & 1 deletion .homeycompose/app.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion app.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
39 changes: 29 additions & 10 deletions drivers/basedevice.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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") ){
Expand Down Expand Up @@ -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)});
}
}
}
Expand Down
9 changes: 7 additions & 2 deletions lib/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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);
}
}
Expand Down

0 comments on commit 1069681

Please sign in to comment.