CodeRabbitAI suggestions
This commit is contained in:
@@ -56,129 +56,15 @@ esphome:
|
||||
on_boot:
|
||||
- priority: 700
|
||||
then:
|
||||
- wait_until:
|
||||
condition:
|
||||
- lambda: return sl_tx_model_format->active_index().has_value();
|
||||
- lambda: return sl_tx_model_gang->active_index().has_value();
|
||||
- lambda: |-
|
||||
const bool us_model = sl_tx_model_format->active_index().has_value() and
|
||||
sl_tx_model_format->active_index().value() == 1;
|
||||
const uint8_t num_gangs = (sl_tx_model_gang->active_index().has_value()) ?
|
||||
(sl_tx_model_gang->active_index().value() + 1) : 0;
|
||||
bs_button_1->publish_state(false);
|
||||
bs_button_1->set_internal(num_gangs < 1);
|
||||
sl_button_1_action->set_internal(num_gangs < 1);
|
||||
bs_button_2->publish_state(false);
|
||||
bs_button_2->set_internal(num_gangs < 2);
|
||||
sl_button_2_action->set_internal(num_gangs < 2);
|
||||
bs_button_3->publish_state(false);
|
||||
bs_button_3->set_internal(num_gangs < 3);
|
||||
sl_button_3_action->set_internal(num_gangs < 3);
|
||||
bs_button_4->publish_state(false);
|
||||
bs_button_4->set_internal(num_gangs < 4);
|
||||
sl_button_4_action->set_internal(num_gangs < 4);
|
||||
bs_multi_touch->publish_state(false);
|
||||
bs_swipe_down->publish_state(false);
|
||||
bs_swipe_down->set_internal(!us_model);
|
||||
bs_swipe_left->publish_state(false);
|
||||
bs_swipe_left->set_internal(us_model);
|
||||
bs_swipe_right->publish_state(false);
|
||||
bs_swipe_right->set_internal(us_model);
|
||||
bs_swipe_up->publish_state(false);
|
||||
bs_swipe_up->set_internal(!us_model);
|
||||
light_28->set_internal(!us_model);
|
||||
light_29->set_internal(!us_model);
|
||||
light_30->set_internal(!us_model);
|
||||
light_31->set_internal(!us_model);
|
||||
light_eu->set_internal(us_model);
|
||||
light_eu_bottom->set_internal(us_model);
|
||||
light_eu_left->set_internal(us_model);
|
||||
light_eu_right->set_internal(us_model);
|
||||
light_eu_top->set_internal(us_model);
|
||||
light_us->set_internal(!us_model);
|
||||
light_us_bottom->set_internal(!us_model);
|
||||
light_us_left->set_internal(!us_model);
|
||||
light_us_right->set_internal(!us_model);
|
||||
light_us_top->set_internal(!us_model);
|
||||
sl_relay_1_mode->set_internal(num_gangs < 1);
|
||||
sl_relay_1_light_mode_eu->set_internal(us_model or num_gangs < 1);
|
||||
sl_relay_1_light_mode_us->set_internal(!us_model or num_gangs < 1);
|
||||
sl_relay_2_mode->set_internal(num_gangs < 2);
|
||||
sl_relay_2_light_mode_eu->set_internal(us_model or num_gangs < 2);
|
||||
sl_relay_2_light_mode_us->set_internal(!us_model or num_gangs < 2);
|
||||
sl_relay_3_mode->set_internal(num_gangs < 3);
|
||||
sl_relay_3_light_mode_eu->set_internal(us_model or num_gangs < 3);
|
||||
sl_relay_3_light_mode_us->set_internal(!us_model or num_gangs < 3);
|
||||
sl_relay_4_mode->set_internal(num_gangs < 4);
|
||||
sl_relay_4_light_mode_eu->set_internal(us_model or num_gangs < 4);
|
||||
sl_relay_4_light_mode_us->set_internal(!us_model or num_gangs < 4);
|
||||
auto relay_mode_index = sl_relay_1_mode->active_index();
|
||||
if (relay_mode_index.has_value()) {
|
||||
ligth_output_1->set_internal(false or relay_mode_index.value() != 1);
|
||||
sw_relay_1->set_internal(false or relay_mode_index.value() != 0);
|
||||
}
|
||||
relay_mode_index = sl_relay_2_mode->active_index();
|
||||
if (relay_mode_index.has_value()) {
|
||||
ligth_output_2->set_internal(num_gangs < 2 or relay_mode_index.value() != 1);
|
||||
sw_relay_2->set_internal(num_gangs < 2 or relay_mode_index.value() != 0);
|
||||
}
|
||||
relay_mode_index = sl_relay_3_mode->active_index();
|
||||
if (relay_mode_index.has_value()) {
|
||||
ligth_output_3->set_internal(num_gangs < 3 or relay_mode_index.value() != 1);
|
||||
sw_relay_3->set_internal(num_gangs < 3 or relay_mode_index.value() != 0);
|
||||
}
|
||||
relay_mode_index = sl_relay_4_mode->active_index();
|
||||
if (relay_mode_index.has_value()) {
|
||||
ligth_output_4->set_internal(num_gangs < 4 or relay_mode_index.value() != 1);
|
||||
sw_relay_4->set_internal(num_gangs < 4 or relay_mode_index.value() != 0);
|
||||
}
|
||||
switch (num_gangs) {
|
||||
case 1: // 1 Gang
|
||||
if (us_model) {
|
||||
id(gb_lights_1) = { light_us_rl_1_1_left };
|
||||
id(gb_lights_2) = { light_us_rl_1_1_right };
|
||||
} else {
|
||||
id(gb_lights_1) = { light_eu_rl_1_1_bottom };
|
||||
id(gb_lights_2) = { light_eu_rl_1_1_top };
|
||||
}
|
||||
break;
|
||||
case 2: // 2 Gang
|
||||
if (us_model) {
|
||||
id(gb_lights_1) = { light_us_rl_1_2_left, light_us_rl_2_2_left };
|
||||
id(gb_lights_2) = { light_us_rl_1_2_right, light_us_rl_2_2_right };
|
||||
} else {
|
||||
id(gb_lights_1) = { light_eu_rl_1_2_bottom, light_eu_rl_2_2_bottom };
|
||||
id(gb_lights_2) = { light_eu_rl_1_2_top, light_eu_rl_2_2_top };
|
||||
}
|
||||
break;
|
||||
case 3: // 3 Gang
|
||||
if (us_model) {
|
||||
id(gb_lights_1) = { light_us_rl_1_3_left, light_us_rl_2_3_left, light_us_rl_3_3_left };
|
||||
id(gb_lights_2) = { light_us_rl_1_3_right, light_us_rl_2_3_right, light_us_rl_3_3_right };
|
||||
} else {
|
||||
id(gb_lights_1) = { light_eu_rl_1_3_bottom, light_eu_rl_2_3_bottom, light_eu_rl_3_3_bottom };
|
||||
id(gb_lights_2) = { light_eu_rl_1_3_top, light_eu_rl_2_3_top, light_eu_rl_3_3_top };
|
||||
}
|
||||
break;
|
||||
case 4: // 3 Gang
|
||||
if (us_model) {
|
||||
id(gb_lights_1) = { light_us_rl_1_4_left, light_us_rl_2_4_left, light_us_rl_3_4_left, light_us_rl_4_4_left };
|
||||
id(gb_lights_2) = { light_us_rl_1_4_right, light_us_rl_2_4_right, light_us_rl_3_4_right, light_us_rl_4_4_right };
|
||||
} else {
|
||||
id(gb_lights_1) = { light_eu_rl_1_4_bottom, light_eu_rl_2_4_bottom, light_eu_rl_3_4_bottom, light_eu_rl_4_4_bottom };
|
||||
id(gb_lights_2) = { light_eu_rl_1_4_top, light_eu_rl_2_4_top, light_eu_rl_3_4_top, light_eu_rl_4_4_top };
|
||||
}
|
||||
break;
|
||||
}
|
||||
- script.execute: boot_initialize
|
||||
|
||||
- priority: 600 # This is where most sensors are set up.
|
||||
then:
|
||||
- lambda: |-
|
||||
tx_fw_version->publish_state("${version}");
|
||||
tx_device_name->publish_state("${name}");
|
||||
- script.execute: boot_sequence
|
||||
|
||||
- priority: -100 # At this priority, pretty much everything should already be initialized.
|
||||
then:
|
||||
- lambda: send_event_to_ha->execute("boot", "done");
|
||||
- script.execute: boot_done
|
||||
|
||||
improv_serial:
|
||||
id: serial_improv
|
||||
@@ -191,9 +77,25 @@ ota:
|
||||
psram:
|
||||
|
||||
script:
|
||||
- id: boot_done
|
||||
mode: restart
|
||||
then:
|
||||
- lambda: send_event_to_ha->execute("boot", "done");
|
||||
|
||||
- id: boot_initialize
|
||||
mode: restart
|
||||
then: # There's nothing here so far
|
||||
# Extended by:
|
||||
# - HW Buttons
|
||||
# - HW Relays
|
||||
# - HW Touch
|
||||
|
||||
- id: boot_sequence
|
||||
mode: restart
|
||||
then:
|
||||
- lambda: |-
|
||||
tx_fw_version->publish_state("${version}");
|
||||
tx_device_name->publish_state("${name}");
|
||||
|
||||
select:
|
||||
- id: sl_tx_model_format
|
||||
|
||||
Reference in New Issue
Block a user