Merge pull request #63 from edwardtfn/button-failsafe-action
Adds "Relay n (API failsafe only)" to button's actions
This commit is contained in:
@@ -235,5 +235,6 @@ time:
|
|||||||
web_server:
|
web_server:
|
||||||
|
|
||||||
wifi:
|
wifi:
|
||||||
|
id: wifi_component
|
||||||
ap:
|
ap:
|
||||||
...
|
...
|
||||||
|
|||||||
@@ -19,6 +19,10 @@ substitutions:
|
|||||||
BUTTON_2_ACTION_TEXT: "Relay 2 (toggle)"
|
BUTTON_2_ACTION_TEXT: "Relay 2 (toggle)"
|
||||||
BUTTON_3_ACTION_TEXT: "Relay 3 (toggle)"
|
BUTTON_3_ACTION_TEXT: "Relay 3 (toggle)"
|
||||||
BUTTON_4_ACTION_TEXT: "Relay 4 (toggle)"
|
BUTTON_4_ACTION_TEXT: "Relay 4 (toggle)"
|
||||||
|
BUTTON_1_ACTION_FAILSAFE_TEXT: "Relay 1 (API failsafe only)"
|
||||||
|
BUTTON_2_ACTION_FAILSAFE_TEXT: "Relay 2 (API failsafe only)"
|
||||||
|
BUTTON_3_ACTION_FAILSAFE_TEXT: "Relay 3 (API failsafe only)"
|
||||||
|
BUTTON_4_ACTION_FAILSAFE_TEXT: "Relay 4 (API failsafe only)"
|
||||||
|
|
||||||
BUTTON_CLICK_MIN_LENGTH: '50' # The minimum duration the click should last, in msec
|
BUTTON_CLICK_MIN_LENGTH: '50' # The minimum duration the click should last, in msec
|
||||||
BUTTON_CLICK_MAX_LENGTH: '350' # The maximum duration the click should last, in msec
|
BUTTON_CLICK_MAX_LENGTH: '350' # The maximum duration the click should last, in msec
|
||||||
@@ -289,6 +293,7 @@ select:
|
|||||||
options:
|
options:
|
||||||
- "${BUTTON_ACTION_NONE_TEXT}"
|
- "${BUTTON_ACTION_NONE_TEXT}"
|
||||||
- "${BUTTON_1_ACTION_TEXT}"
|
- "${BUTTON_1_ACTION_TEXT}"
|
||||||
|
- "${BUTTON_1_ACTION_FAILSAFE_TEXT}"
|
||||||
initial_option: "${BUTTON_1_ACTION_TEXT}"
|
initial_option: "${BUTTON_1_ACTION_TEXT}"
|
||||||
optimistic: true
|
optimistic: true
|
||||||
restore_value: true
|
restore_value: true
|
||||||
@@ -303,6 +308,7 @@ select:
|
|||||||
options:
|
options:
|
||||||
- "${BUTTON_ACTION_NONE_TEXT}"
|
- "${BUTTON_ACTION_NONE_TEXT}"
|
||||||
- "${BUTTON_2_ACTION_TEXT}"
|
- "${BUTTON_2_ACTION_TEXT}"
|
||||||
|
- "${BUTTON_2_ACTION_FAILSAFE_TEXT}"
|
||||||
initial_option: "${BUTTON_2_ACTION_TEXT}"
|
initial_option: "${BUTTON_2_ACTION_TEXT}"
|
||||||
<<: *button_select_action_base
|
<<: *button_select_action_base
|
||||||
|
|
||||||
@@ -312,6 +318,7 @@ select:
|
|||||||
options:
|
options:
|
||||||
- "${BUTTON_ACTION_NONE_TEXT}"
|
- "${BUTTON_ACTION_NONE_TEXT}"
|
||||||
- "${BUTTON_3_ACTION_TEXT}"
|
- "${BUTTON_3_ACTION_TEXT}"
|
||||||
|
- "${BUTTON_3_ACTION_FAILSAFE_TEXT}"
|
||||||
initial_option: "${BUTTON_3_ACTION_TEXT}"
|
initial_option: "${BUTTON_3_ACTION_TEXT}"
|
||||||
<<: *button_select_action_base
|
<<: *button_select_action_base
|
||||||
|
|
||||||
@@ -321,6 +328,7 @@ select:
|
|||||||
options:
|
options:
|
||||||
- "${BUTTON_ACTION_NONE_TEXT}"
|
- "${BUTTON_ACTION_NONE_TEXT}"
|
||||||
- "${BUTTON_4_ACTION_TEXT}"
|
- "${BUTTON_4_ACTION_TEXT}"
|
||||||
|
- "${BUTTON_4_ACTION_FAILSAFE_TEXT}"
|
||||||
initial_option: "${BUTTON_4_ACTION_TEXT}"
|
initial_option: "${BUTTON_4_ACTION_TEXT}"
|
||||||
<<: *button_select_action_base
|
<<: *button_select_action_base
|
||||||
...
|
...
|
||||||
|
|||||||
@@ -191,57 +191,57 @@ script:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Toggle relay if corresponding button action is enabled
|
// Toggle relay if corresponding button action is enabled
|
||||||
ESP_LOGVV("core_hw_relays", "Toggle relays: (${BUTTON_ACTION_NONE_TEXT})");
|
const bool api_disconnected = !global_api_server->is_connected() or
|
||||||
ESP_LOGVV("core_hw_relays", " Relay 1: %s (%s)",
|
!wifi_component->is_connected();
|
||||||
YESNO(sl_button_1_action->state != "${BUTTON_ACTION_NONE_TEXT}"),
|
std::string select_state;
|
||||||
sl_button_1_action->state.c_str());
|
bool toggle_relay = false;
|
||||||
ESP_LOGVV("core_hw_relays", " Relay 2: %s (%s)",
|
if (api_disconnected) {
|
||||||
YESNO(sl_button_2_action->state != "${BUTTON_ACTION_NONE_TEXT}"),
|
ESP_LOGW("core_hw_relays", "Toggle relays:");
|
||||||
sl_button_2_action->state.c_str());
|
ESP_LOGW("core_hw_relays", " API state: DISCONNECTED");
|
||||||
ESP_LOGVV("core_hw_relays", " Relay 3: %s (%s)",
|
ESP_LOGW("core_hw_relays", " Button: %" PRIu8, button);
|
||||||
YESNO(sl_button_3_action->state != "${BUTTON_ACTION_NONE_TEXT}"),
|
} else {
|
||||||
sl_button_3_action->state.c_str());
|
ESP_LOGVV("core_hw_relays", "Toggle relays:");
|
||||||
ESP_LOGVV("core_hw_relays", " Relay 4: %s (%s)",
|
ESP_LOGVV("core_hw_relays", " API state: Connected");
|
||||||
YESNO(sl_button_4_action->state != "${BUTTON_ACTION_NONE_TEXT}"),
|
ESP_LOGVV("core_hw_relays", " Button: %" PRIu8, button);
|
||||||
sl_button_4_action->state.c_str());
|
}
|
||||||
switch (button) {
|
switch (button) {
|
||||||
case ${BUTTON_1_ID}:
|
case ${BUTTON_1_ID}:
|
||||||
if (sl_button_1_action->state != "${BUTTON_ACTION_NONE_TEXT}") {
|
select_state = sl_button_1_action->state;
|
||||||
ESP_LOGV("core_hw_relays", "Toggle relay 1: (%s)", sl_button_1_action->state.c_str());
|
toggle_relay = (select_state == "${BUTTON_1_ACTION_TEXT}" or
|
||||||
|
(api_disconnected and select_state == "${BUTTON_1_ACTION_FAILSAFE_TEXT}"));
|
||||||
|
if (toggle_relay)
|
||||||
sw_relay_1->toggle();
|
sw_relay_1->toggle();
|
||||||
} else {
|
|
||||||
ESP_LOGV("core_hw_relays", "Ignoring toggle for relay 1: action is '%s'",
|
|
||||||
sl_button_1_action->state.c_str());
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case ${BUTTON_2_ID}:
|
case ${BUTTON_2_ID}:
|
||||||
if (sl_button_2_action->state != "${BUTTON_ACTION_NONE_TEXT}") {
|
select_state = sl_button_2_action->state;
|
||||||
ESP_LOGV("core_hw_relays", "Toggle relay 2: (%s)", sl_button_2_action->state.c_str());
|
toggle_relay = (select_state == "${BUTTON_2_ACTION_TEXT}" or
|
||||||
|
(api_disconnected and select_state == "${BUTTON_2_ACTION_FAILSAFE_TEXT}"));
|
||||||
|
if (toggle_relay)
|
||||||
sw_relay_2->toggle();
|
sw_relay_2->toggle();
|
||||||
} else {
|
|
||||||
ESP_LOGV("core_hw_relays", "Ignoring toggle for relay 2: action is '%s'",
|
|
||||||
sl_button_2_action->state.c_str());
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case ${BUTTON_3_ID}:
|
case ${BUTTON_3_ID}:
|
||||||
if (sl_button_3_action->state != "${BUTTON_ACTION_NONE_TEXT}") {
|
select_state = sl_button_3_action->state;
|
||||||
ESP_LOGV("core_hw_relays", "Toggle relay 3: (%s)", sl_button_3_action->state.c_str());
|
toggle_relay = (select_state == "${BUTTON_3_ACTION_TEXT}" or
|
||||||
|
(api_disconnected and select_state == "${BUTTON_3_ACTION_FAILSAFE_TEXT}"));
|
||||||
|
if (toggle_relay)
|
||||||
sw_relay_3->toggle();
|
sw_relay_3->toggle();
|
||||||
} else {
|
|
||||||
ESP_LOGV("core_hw_relays", "Ignoring toggle for relay 3: action is '%s'",
|
|
||||||
sl_button_3_action->state.c_str());
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case ${BUTTON_4_ID}:
|
case ${BUTTON_4_ID}:
|
||||||
if (sl_button_4_action->state != "${BUTTON_ACTION_NONE_TEXT}") {
|
select_state = sl_button_4_action->state;
|
||||||
ESP_LOGV("core_hw_relays", "Toggle relay 4: (%s)", sl_button_4_action->state.c_str());
|
toggle_relay = (select_state == "${BUTTON_4_ACTION_TEXT}" or
|
||||||
|
(api_disconnected and select_state == "${BUTTON_4_ACTION_FAILSAFE_TEXT}"));
|
||||||
|
if (toggle_relay)
|
||||||
sw_relay_4->toggle();
|
sw_relay_4->toggle();
|
||||||
} else {
|
|
||||||
ESP_LOGV("core_hw_relays", "Ignoring toggle for relay 4: action is '%s'",
|
|
||||||
sl_button_4_action->state.c_str());
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if (toggle_relay) {
|
||||||
|
ESP_LOGI("core_hw_relays", "Toggle relay %" PRIu8 ": (%s)", button, select_state.c_str());
|
||||||
|
} else if (not select_state.empty()) {
|
||||||
|
ESP_LOGV("core_hw_relays", "Ignoring toggle for relay %" PRIu8 ": action is '%s'",
|
||||||
|
button, select_state.c_str());
|
||||||
|
} else {
|
||||||
|
ESP_LOGE("core_hw_relays", "No button action selected for button %" PRIu8, button);
|
||||||
|
}
|
||||||
|
|
||||||
- id: show_relay_status
|
- id: show_relay_status
|
||||||
mode: restart
|
mode: restart
|
||||||
|
|||||||
Reference in New Issue
Block a user