1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-20 18:53:47 +01:00

[tests] Remove superfluous else-blocks from lambdas (#11322)

Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
Juan Antonio Aldea
2025-10-18 09:40:54 +02:00
committed by GitHub
parent 85f1019d90
commit d5c36eaf2a
13 changed files with 37 additions and 69 deletions

View File

@@ -8,14 +8,12 @@ sensor:
lambda: |-
if (millis() > 10000) {
return 0.6;
} else {
return 0.0;
}
return 0.0;
- platform: template
id: template_temperature
lambda: |-
if (millis() > 10000) {
return 42.0;
} else {
return 0.0;
}
return 0.0;

View File

@@ -5,9 +5,8 @@ sensor:
lambda: |-
if (millis() > 10000) {
return 42.0;
} else {
return 0.0;
}
return 0.0;
update_interval: 15s
binary_sensor:

View File

@@ -23,9 +23,8 @@ binary_sensor:
- lambda: |-
if (id(some_binary_sensor).state) {
return x;
} else {
return {};
}
return {};
- settle: 100ms
- timeout: 10s

View File

@@ -4,25 +4,22 @@ binary_sensor:
lambda: |-
if (millis() > 10000) {
return true;
} else {
return false;
}
return false;
- platform: template
id: bin2
lambda: |-
if (millis() > 20000) {
return true;
} else {
return false;
}
return false;
- platform: template
id: bin3
lambda: |-
if (millis() > 30000) {
return true;
} else {
return false;
}
return false;
sensor:
- platform: binary_sensor_map

View File

@@ -4,17 +4,15 @@ sensor:
lambda: |-
if (millis() > 10000) {
return 0.6;
} else {
return 0.0;
}
return 0.0;
- platform: template
id: template_temperature2
lambda: |-
if (millis() > 20000) {
return 0.8;
} else {
return 0.0;
}
return 0.0;
- platform: combination
type: kalman
name: Kalman-filtered temperature

View File

@@ -4,9 +4,8 @@ binary_sensor:
lambda: |-
if (millis() > 10000) {
return true;
} else {
return false;
}
return false;
sensor:
- platform: duty_time

View File

@@ -4,9 +4,8 @@ binary_sensor:
lambda: |-
if (millis() > 10000) {
return true;
} else {
return false;
}
return false;
switch:
- platform: template

View File

@@ -17,9 +17,8 @@ lock:
lambda: |-
if (millis() > 10000) {
return LOCK_STATE_LOCKED;
} else {
return LOCK_STATE_UNLOCKED;
}
return LOCK_STATE_UNLOCKED;
optimistic: true
assumed_state: false
on_unlock:

View File

@@ -72,10 +72,9 @@ binary_sensor:
if (id(template_sens).state > 30) {
// Garage Door is open.
return true;
} else {
// Garage Door is closed.
return false;
}
// Garage Door is closed.
return false;
on_state:
- mqtt.publish:
topic: some/topic/binary_sensor
@@ -217,9 +216,8 @@ cover:
lambda: |-
if (id(some_binary_sensor).state) {
return COVER_OPEN;
} else {
return COVER_CLOSED;
}
return COVER_CLOSED;
open_action:
- logger.log: open_action
close_action:
@@ -321,9 +319,8 @@ lock:
lambda: |-
if (id(some_binary_sensor).state) {
return LOCK_STATE_LOCKED;
} else {
return LOCK_STATE_UNLOCKED;
}
return LOCK_STATE_UNLOCKED;
lock_action:
- logger.log: lock_action
unlock_action:
@@ -360,9 +357,8 @@ sensor:
lambda: |-
if (id(some_binary_sensor).state) {
return 42.0;
} else {
return 0.0;
}
return 0.0;
update_interval: 60s
on_value:
- mqtt.publish:
@@ -390,9 +386,8 @@ switch:
lambda: |-
if (id(some_binary_sensor).state) {
return true;
} else {
return false;
}
return false;
turn_on_action:
- logger.log: turn_on_action
turn_off_action:
@@ -436,9 +431,8 @@ valve:
lambda: |-
if (id(some_binary_sensor).state) {
return VALVE_OPEN;
} else {
return VALVE_CLOSED;
}
return VALVE_CLOSED;
alarm_control_panel:
- platform: template

View File

@@ -27,9 +27,8 @@ sensor:
lambda: |-
if (millis() > 10000) {
return 42.0;
} else {
return 0.0;
}
return 0.0;
update_interval: 60s
climate:

View File

@@ -35,9 +35,8 @@ sensor:
lambda: |-
if (millis() > 10000) {
return 42.0;
} else {
return 0.0;
}
return 0.0;
update_interval: 60s
text_sensor:
@@ -49,9 +48,8 @@ text_sensor:
lambda: |-
if (millis() > 10000) {
return {"Hello World"};
} else {
return {"Goodbye (cruel) World"};
}
return {"Goodbye (cruel) World"};
update_interval: 60s
binary_sensor:
@@ -60,9 +58,8 @@ binary_sensor:
lambda: |-
if (millis() > 10000) {
return true;
} else {
return false;
}
return false;
switch:
- platform: template
@@ -70,9 +67,8 @@ switch:
lambda: |-
if (millis() > 10000) {
return true;
} else {
return false;
}
return false;
optimistic: true
fan:
@@ -85,9 +81,8 @@ cover:
lambda: |-
if (millis() > 10000) {
return COVER_OPEN;
} else {
return COVER_CLOSED;
}
return COVER_CLOSED;
lock:
- platform: template
@@ -95,9 +90,8 @@ lock:
lambda: |-
if (millis() > 10000) {
return LOCK_STATE_LOCKED;
} else {
return LOCK_STATE_UNLOCKED;
}
return LOCK_STATE_UNLOCKED;
optimistic: true
select:

View File

@@ -59,9 +59,8 @@ binary_sensor:
- lambda: |-
if (id(other_binary_sensor).state) {
return x;
} else {
return {};
}
return {};
- settle: 500ms
- timeout: 5s
@@ -72,9 +71,8 @@ sensor:
lambda: |-
if (id(some_binary_sensor).state) {
return 42.0;
} else {
return 0.0;
}
return 0.0;
update_interval: 60s
filters:
- calibrate_linear:
@@ -183,9 +181,8 @@ switch:
lambda: |-
if (id(some_binary_sensor).state) {
return true;
} else {
return false;
}
return false;
turn_on_action:
- logger.log: "turn_on_action"
turn_off_action:
@@ -203,9 +200,8 @@ cover:
lambda: |-
if (id(some_binary_sensor).state) {
return COVER_OPEN;
} else {
return COVER_CLOSED;
}
return COVER_CLOSED;
open_action:
- logger.log: open_action
close_action:
@@ -238,9 +234,8 @@ lock:
lambda: |-
if (id(some_binary_sensor).state) {
return LOCK_STATE_LOCKED;
} else {
return LOCK_STATE_UNLOCKED;
}
return LOCK_STATE_UNLOCKED;
lock_action:
- logger.log: lock_action
unlock_action:
@@ -255,9 +250,8 @@ valve:
lambda: |-
if (id(some_binary_sensor).state) {
return VALVE_OPEN;
} else {
return VALVE_CLOSED;
}
return VALVE_CLOSED;
open_action:
- logger.log: open_action
close_action:

View File

@@ -34,10 +34,9 @@ binary_sensor:
ESP_LOGD("test", "Button ON at %u", now);
}
return true;
} else {
// Only log state change
if (id(ir_remote_button).state) {
ESP_LOGD("test", "Button OFF at %u", now);
}
return false;
}
// Only log state change
if (id(ir_remote_button).state) {
ESP_LOGD("test", "Button OFF at %u", now);
}
return false;