- } else {
- // temp < threshold temp, call set_switch if trigger is LEVEL, or if we were not lower and FALLING
- if (this->trigger == LEVEL || (!this->lower && this->trigger == FALLING)) {
- this->lower= true;
- set_switch(false);
- current_delay = temperatureswitch_heatup_poll;
- }
- if(!this->lower && this->trigger == RISING) {
- this->lower= true;
- }
- }
+void TemperatureSwitch::set_state(STATE state)
+{
+ if(state == this->current_state) return; // state did not change
+
+ // state has changed
+ switch(this->trigger) {
+ case LEVEL:
+ // switch on or off depending on HIGH or LOW
+ set_switch(state == HIGH_TEMP);
+ break;
+
+ case RISING:
+ // switch on if rising edge
+ if(this->current_state == LOW_TEMP && state == HIGH_TEMP) set_switch(true);
+ break;
+
+ case FALLING:
+ // switch off if falling edge
+ if(this->current_state == HIGH_TEMP && state == LOW_TEMP) set_switch(false);
+ break;