modbus_switch: honor switch:restore_mode (#4122)

This commit is contained in:
Javier Peletier 2022-11-29 22:44:31 +01:00 committed by GitHub
parent 027284c29c
commit d706f40ce1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -6,7 +6,17 @@ namespace modbus_controller {
static const char *const TAG = "modbus_controller.switch"; static const char *const TAG = "modbus_controller.switch";
void ModbusSwitch::setup() {} void ModbusSwitch::setup() {
optional<bool> initial_state = Switch::get_initial_state_with_restore_mode();
if (initial_state.has_value()) {
// if it has a value, restore_mode is not "DISABLED", therefore act on the switch:
if (initial_state.value()) {
this->turn_on();
} else {
this->turn_off();
}
}
}
void ModbusSwitch::dump_config() { LOG_SWITCH(TAG, "Modbus Controller Switch", this); } void ModbusSwitch::dump_config() { LOG_SWITCH(TAG, "Modbus Controller Switch", this); }
void ModbusSwitch::parse_and_publish(const std::vector<uint8_t> &data) { void ModbusSwitch::parse_and_publish(const std::vector<uint8_t> &data) {