1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-21 19:23:45 +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: |- lambda: |-
if (millis() > 10000) { if (millis() > 10000) {
return 0.6; return 0.6;
} else {
return 0.0;
} }
return 0.0;
- platform: template - platform: template
id: template_temperature id: template_temperature
lambda: |- lambda: |-
if (millis() > 10000) { if (millis() > 10000) {
return 42.0; return 42.0;
} else {
return 0.0;
} }
return 0.0;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -34,10 +34,9 @@ binary_sensor:
ESP_LOGD("test", "Button ON at %u", now); ESP_LOGD("test", "Button ON at %u", now);
} }
return true; 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;