Skip to content

Commit f1d3d47

Browse files
committed
fix(sec_touch): allow to turn on a fan when turned off (and use 1 for speed as default)
closes #11
1 parent 6c0ad93 commit f1d3d47

1 file changed

Lines changed: 16 additions & 5 deletions

File tree

components/sec_touch/fan/sec_touch_fan.cpp

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,22 @@ void SecTouchFan::control(const fan::FanCall &call) {
137137

138138
// if new state and no speed
139139
if (call.get_state().has_value() && !call.get_speed().has_value()) {
140-
// OFF
141-
ESP_LOGI(TAG, "[State Update for %d] - Requesting just state OFF but device is already OFF. Requesting anyway",
142-
this->level_id);
143-
turn_off_sec_touch_hardware_fan();
144-
return;
140+
if (call.get_state().value() == 0 && old_state == 0) {
141+
// OFF
142+
ESP_LOGI(TAG, "[State Update for %d] - Requesting just state OFF but device is already OFF. Requesting anyway",
143+
this->level_id);
144+
turn_off_sec_touch_hardware_fan();
145+
return;
146+
}
147+
148+
if (call.get_state().value() == 1 && old_state == 0) {
149+
// ON
150+
ESP_LOGI(TAG, "[State Update for %d] - Requesting just state ON", this->level_id);
151+
// Use the current speed if it exists, otherwise use 1
152+
// TODO Use a configuration https://github.com/distante/esphome-components/issues/10
153+
int speed_to_set = (this->speed > 0) ? this->speed : 1;
154+
this->speed = speed_to_set;
155+
}
145156
}
146157

147158
// ON

0 commit comments

Comments
 (0)