Files
esphome-lsm6ds/esphome/components/micronova/switch/micronova_switch.cpp
T
9f60aed9b0 [micronova] Make stove switch entity independent (#12355)
Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-12-08 11:18:44 -05:00

53 lines
1.6 KiB
C++

#include "micronova_switch.h"
namespace esphome::micronova {
void MicroNovaSwitch::write_state(bool state) {
switch (this->get_function()) {
case MicroNovaFunctions::STOVE_FUNCTION_SWITCH: {
if (state) {
// Only send power-on when current state is Off
if (this->raw_state_ == 0) {
this->micronova_->write_address(this->memory_location_, this->memory_address_, this->memory_data_on_);
this->publish_state(true);
} else {
ESP_LOGW(TAG, "Unable to turn stove on, invalid state: %d", this->raw_state_);
}
} else {
// don't send power-off when status is Off or Final cleaning
if (this->raw_state_ != 0 && this->raw_state_ != 6) {
this->micronova_->write_address(this->memory_location_, this->memory_address_, this->memory_data_off_);
this->publish_state(false);
} else {
ESP_LOGW(TAG, "Unable to turn stove off, invalid state: %d", this->raw_state_);
}
}
this->set_needs_update(true);
break;
}
default:
break;
}
}
void MicroNovaSwitch::process_value_from_stove(int value_from_stove) {
this->raw_state_ = value_from_stove;
if (value_from_stove == -1) {
ESP_LOGE(TAG, "Error reading stove state");
return;
}
switch (this->get_function()) {
case MicroNovaFunctions::STOVE_FUNCTION_SWITCH: {
// set the stove switch to on for any value but 0
bool state = value_from_stove != 0;
this->publish_state(state);
break;
}
default:
break;
}
}
} // namespace esphome::micronova