Clean-up relay mode select
This commit is contained in:
@@ -244,5 +244,4 @@ select:
|
|||||||
entity_category: config
|
entity_category: config
|
||||||
disabled_by_default: false
|
disabled_by_default: false
|
||||||
icon: mdi:dip-switch
|
icon: mdi:dip-switch
|
||||||
|
|
||||||
...
|
...
|
||||||
|
|||||||
@@ -82,40 +82,52 @@ script:
|
|||||||
mode: restart
|
mode: restart
|
||||||
then:
|
then:
|
||||||
- lambda: |-
|
- lambda: |-
|
||||||
return;
|
|
||||||
show_relay_status->stop();
|
|
||||||
auto model_format = sl_tx_model_format->active_index();
|
auto model_format = sl_tx_model_format->active_index();
|
||||||
std::vector<esphome::select::Select*> relay_modes;
|
if (!model_format.has_value()) return; // Early return if no model format
|
||||||
|
|
||||||
if (model_format.has_value() and model_format.value() == 0) {
|
std::vector<esphome::select::Select*> relay_modes;
|
||||||
relay_modes = {sl_relay_1_light_mode_eu, sl_relay_2_light_mode_eu, sl_relay_3_light_mode_eu, sl_relay_4_light_mode_eu};
|
const bool is_eu_model = model_format.value() == 0;
|
||||||
|
|
||||||
|
// Select appropriate light mode selectors based on model
|
||||||
|
if (is_eu_model) {
|
||||||
|
relay_modes = {sl_relay_1_light_mode_eu, sl_relay_2_light_mode_eu,
|
||||||
|
sl_relay_3_light_mode_eu, sl_relay_4_light_mode_eu};
|
||||||
} else {
|
} else {
|
||||||
relay_modes = {sl_relay_1_light_mode_us, sl_relay_2_light_mode_us, sl_relay_3_light_mode_us, sl_relay_4_light_mode_us};
|
relay_modes = {sl_relay_1_light_mode_us, sl_relay_2_light_mode_us,
|
||||||
|
sl_relay_3_light_mode_us, sl_relay_4_light_mode_us};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<switch_::Switch*> switches = {sw_relay_1, sw_relay_2, sw_relay_3, sw_relay_4};
|
// Get switch states
|
||||||
for (int i = 0; i < relay_modes.size(); ++i) {
|
const std::vector<switch_::Switch*> switches = {sw_relay_1, sw_relay_2, sw_relay_3, sw_relay_4};
|
||||||
|
|
||||||
|
// Update lights based on relay states
|
||||||
|
for (size_t i = 0; i < relay_modes.size(); ++i) {
|
||||||
auto light_index = relay_modes[i]->active_index();
|
auto light_index = relay_modes[i]->active_index();
|
||||||
if (light_index.has_value()) {
|
if (!light_index.has_value()) continue;
|
||||||
uint8_t light_idx = light_index.value();
|
|
||||||
bool switch_state = switches[i]->state;
|
const uint8_t light_idx = light_index.value();
|
||||||
|
const bool switch_state = switches[i]->state;
|
||||||
|
|
||||||
|
// Update first light group (bottom/left)
|
||||||
if (light_idx == 1 || light_idx == 3) {
|
if (light_idx == 1 || light_idx == 3) {
|
||||||
if (switch_state)
|
if (switch_state)
|
||||||
id(gb_lights_1)[i]->turn_on().perform();
|
id(gb_lights_1)[i]->turn_on();
|
||||||
else
|
else
|
||||||
id(gb_lights_1)[i]->turn_off().perform();
|
id(gb_lights_1)[i]->turn_off();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update second light group (top/right)
|
||||||
if (light_idx == 2 || light_idx == 3) {
|
if (light_idx == 2 || light_idx == 3) {
|
||||||
if (switch_state)
|
if (switch_state)
|
||||||
id(gb_lights_2)[i]->turn_on().perform();
|
id(gb_lights_2)[i]->turn_on();
|
||||||
else
|
else
|
||||||
id(gb_lights_2)[i]->turn_off().perform();
|
id(gb_lights_2)[i]->turn_off();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
select:
|
select:
|
||||||
- id: sl_relay_1_mode
|
- &relay_mode_base
|
||||||
|
id: sl_relay_1_mode
|
||||||
name: Relay 1 mode
|
name: Relay 1 mode
|
||||||
platform: template
|
platform: template
|
||||||
options:
|
options:
|
||||||
@@ -131,45 +143,15 @@ select:
|
|||||||
|
|
||||||
- id: sl_relay_2_mode
|
- id: sl_relay_2_mode
|
||||||
name: Relay 2 mode
|
name: Relay 2 mode
|
||||||
platform: template
|
<<: *relay_mode_base
|
||||||
options:
|
|
||||||
- "Relay"
|
|
||||||
- "Light"
|
|
||||||
- "Not in use"
|
|
||||||
optimistic: true
|
|
||||||
restore_value: true
|
|
||||||
internal: true
|
|
||||||
entity_category: config
|
|
||||||
disabled_by_default: false
|
|
||||||
icon: mdi:dip-switch
|
|
||||||
|
|
||||||
- id: sl_relay_3_mode
|
- id: sl_relay_3_mode
|
||||||
name: Relay 3 mode
|
name: Relay 3 mode
|
||||||
platform: template
|
<<: *relay_mode_base
|
||||||
options:
|
|
||||||
- "Relay"
|
|
||||||
- "Light"
|
|
||||||
- "Not in use"
|
|
||||||
optimistic: true
|
|
||||||
restore_value: true
|
|
||||||
internal: true
|
|
||||||
entity_category: config
|
|
||||||
disabled_by_default: false
|
|
||||||
icon: mdi:dip-switch
|
|
||||||
|
|
||||||
- id: sl_relay_4_mode
|
- id: sl_relay_4_mode
|
||||||
name: Relay 4 mode
|
name: Relay 4 mode
|
||||||
platform: template
|
<<: *relay_mode_base
|
||||||
options:
|
|
||||||
- "Relay"
|
|
||||||
- "Light"
|
|
||||||
- "Not in use"
|
|
||||||
optimistic: true
|
|
||||||
restore_value: true
|
|
||||||
internal: true
|
|
||||||
entity_category: config
|
|
||||||
disabled_by_default: false
|
|
||||||
icon: mdi:dip-switch
|
|
||||||
|
|
||||||
switch:
|
switch:
|
||||||
- &relay_switch_base
|
- &relay_switch_base
|
||||||
|
|||||||
Reference in New Issue
Block a user