NEWS
setState als Schrittkette ausführen
-
Hi,
wie bekomme ich es elegant hin, dass die States nacheinander abgearbeitet werden, auch wenn einer der States aufgrund der Bedingungen nicht ausgeführt wird?
Mit dem Callback tue ich mir schwer, da ja SetState teilweise nicht ausgeführt wird, wenn es sich nicht um einen neuen Wert handelt.
Die Abfrage, ob der alte Wert dem Neuen entspricht habe ich eingebaut, um keine unnötige Befehle über Zigbee und Homeatic zu senden.Im Grunde genommen soll das letzte SetState (pathControl) erst ausgeführt werden, wenn alle Vorgegangene durchgeführt sind.
arrLights[i].setLightOn = async function(group){ if (group.buttonPress == this.buttonPress) { if (this.pathTransistion) { var oldVal = await getState(this.pathTransistion).val; (oldVal != this.defaultTransition) setState(this.pathTransistion, this.defaultTransition); } if (this.pathColortemp) { var oldVal = await getState(this.pathColortemp).val; if(oldVal != this.defaultColorTemp) setState(this.pathColortemp, this.defaultColorTemp); } if (this.pathColor) { var oldVal = await getState(this.pathColor).val; //if(oldVal != this.defaultColor) setState(this.pathColor, this.defaultColor); } if (this.pathControl) { var oldVal = await getState(this.pathControl).val; if(oldVal != (this.pathControlType == 'number') ? this.defaultLevel : true) { setState(this.pathControl, (this.pathControlType == 'number') ? this.defaultLevel : true); if (extLogging) console.log(`${scriptname}: Licht wird eingeschaltet: ${this.name} // Pfad: ${this.pathControl} // Wert: ${(this.pathControlType == 'number') ? this.defaultLevel : true}`); } }
Grüße
Schmakus -
@schmakus
Muss das nicht "await getStateAsync()" heissen?
Genauso kannst Du "await setStateAsync()" verwenden -
@ente34 Ich stelle keinen Unterschied fest. Egal ob
SetState
odersetStateAsync
Hab nun folgendes Code und laut Log wird alles nacheinander abgearbeitet so wie ich es gerne hätte.
Gibt es vielleicht eine elegantere Lösung?if(this.pathColortemp) { await setState(this.pathTransistion, this.defaultTransition) console.warn('1: Set Transition') } if(this.pathColortemp) { await setState(this.pathColortemp, this.defaultColorTemp) console.warn('2: Set Colortemp') } if(this.pathColor) { await setState(this.pathColor, this.defaultColor) console.warn('3: Set Color') } if(this.pathControl) { await setState(this.pathControl, (this.pathControlType == 'number') ? this.defaultLevel : true) console.warn('4: Set Control') setState(this.pathLastValue, (this.pathControlType == 'number') ? this.defaultLevel : true, true); console.warn('5: Set Light State') setState(this.pathLightState, true, true); console.warn('6: Set Group Light State') if (extLogging) console.log(`${scriptname}: Licht wird eingeschaltet: ${this.name} // Pfad: ${this.pathControl} // Wert: ${(this.pathControlType == 'number') ? this.defaultLevel : true}`); }