mirror of
https://github.com/esphome/esphome.git
synced 2026-01-09 19:50:49 -07:00
[micronova] Remove MicroNovaFunctions (#12363)
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>
This commit is contained in:
@@ -17,22 +17,6 @@ DEFAULT_POLLING_INTERVAL = "60s"
|
||||
|
||||
micronova_ns = cg.esphome_ns.namespace(DOMAIN)
|
||||
|
||||
MicroNovaFunctions = micronova_ns.enum("MicroNovaFunctions", is_class=True)
|
||||
MICRONOVA_FUNCTIONS_ENUM = {
|
||||
"STOVE_FUNCTION_SWITCH": MicroNovaFunctions.STOVE_FUNCTION_SWITCH,
|
||||
"STOVE_FUNCTION_ROOM_TEMPERATURE": MicroNovaFunctions.STOVE_FUNCTION_ROOM_TEMPERATURE,
|
||||
"STOVE_FUNCTION_THERMOSTAT_TEMPERATURE": MicroNovaFunctions.STOVE_FUNCTION_THERMOSTAT_TEMPERATURE,
|
||||
"STOVE_FUNCTION_FUMES_TEMPERATURE": MicroNovaFunctions.STOVE_FUNCTION_FUMES_TEMPERATURE,
|
||||
"STOVE_FUNCTION_STOVE_POWER": MicroNovaFunctions.STOVE_FUNCTION_STOVE_POWER,
|
||||
"STOVE_FUNCTION_FAN_SPEED": MicroNovaFunctions.STOVE_FUNCTION_FAN_SPEED,
|
||||
"STOVE_FUNCTION_STOVE_STATE": MicroNovaFunctions.STOVE_FUNCTION_STOVE_STATE,
|
||||
"STOVE_FUNCTION_MEMORY_ADDRESS_SENSOR": MicroNovaFunctions.STOVE_FUNCTION_MEMORY_ADDRESS_SENSOR,
|
||||
"STOVE_FUNCTION_WATER_TEMPERATURE": MicroNovaFunctions.STOVE_FUNCTION_WATER_TEMPERATURE,
|
||||
"STOVE_FUNCTION_WATER_PRESSURE": MicroNovaFunctions.STOVE_FUNCTION_WATER_PRESSURE,
|
||||
"STOVE_FUNCTION_POWER_LEVEL": MicroNovaFunctions.STOVE_FUNCTION_POWER_LEVEL,
|
||||
"STOVE_FUNCTION_CUSTOM": MicroNovaFunctions.STOVE_FUNCTION_CUSTOM,
|
||||
}
|
||||
|
||||
MicroNova = micronova_ns.class_("MicroNova", cg.Component, uart.UARTDevice)
|
||||
MicroNovaListener = micronova_ns.class_("MicroNovaListener", cg.PollingComponent)
|
||||
|
||||
@@ -78,12 +62,11 @@ def MICRONOVA_ADDRESS_SCHEMA(
|
||||
return schema
|
||||
|
||||
|
||||
async def to_code_micronova_listener(mv, var, config, micronova_function):
|
||||
async def to_code_micronova_listener(mv, var, config):
|
||||
await cg.register_component(var, config)
|
||||
cg.add(mv.register_micronova_listener(var))
|
||||
cg.add(var.set_memory_location(config[CONF_MEMORY_LOCATION]))
|
||||
cg.add(var.set_memory_address(config[CONF_MEMORY_ADDRESS]))
|
||||
cg.add(var.set_function(micronova_function))
|
||||
|
||||
|
||||
async def to_code(config):
|
||||
|
||||
@@ -8,7 +8,6 @@ from .. import (
|
||||
CONF_MICRONOVA_ID,
|
||||
MICRONOVA_ADDRESS_SCHEMA,
|
||||
MicroNova,
|
||||
MicroNovaFunctions,
|
||||
micronova_ns,
|
||||
)
|
||||
|
||||
@@ -43,4 +42,3 @@ async def to_code(config):
|
||||
cg.add(bt.set_memory_location(custom_button_config.get(CONF_MEMORY_LOCATION)))
|
||||
cg.add(bt.set_memory_address(custom_button_config.get(CONF_MEMORY_ADDRESS)))
|
||||
cg.add(bt.set_memory_data(custom_button_config[CONF_MEMORY_DATA]))
|
||||
cg.add(bt.set_function(MicroNovaFunctions.STOVE_FUNCTION_CUSTOM))
|
||||
|
||||
@@ -3,13 +3,7 @@
|
||||
namespace esphome::micronova {
|
||||
|
||||
void MicroNovaButton::press_action() {
|
||||
switch (this->get_function()) {
|
||||
case MicroNovaFunctions::STOVE_FUNCTION_CUSTOM:
|
||||
this->micronova_->write_address(this->memory_location_, this->memory_address_, this->memory_data_);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
this->micronova_->write_address(this->memory_location_, this->memory_address_, this->memory_data_);
|
||||
this->micronova_->request_update_listeners();
|
||||
}
|
||||
|
||||
|
||||
@@ -12,22 +12,6 @@ namespace esphome::micronova {
|
||||
|
||||
static const char *const TAG = "micronova";
|
||||
|
||||
enum class MicroNovaFunctions {
|
||||
STOVE_FUNCTION_VOID = 0,
|
||||
STOVE_FUNCTION_SWITCH = 1,
|
||||
STOVE_FUNCTION_ROOM_TEMPERATURE = 2,
|
||||
STOVE_FUNCTION_THERMOSTAT_TEMPERATURE = 3,
|
||||
STOVE_FUNCTION_FUMES_TEMPERATURE = 4,
|
||||
STOVE_FUNCTION_STOVE_POWER = 5,
|
||||
STOVE_FUNCTION_FAN_SPEED = 6,
|
||||
STOVE_FUNCTION_STOVE_STATE = 7,
|
||||
STOVE_FUNCTION_MEMORY_ADDRESS_SENSOR = 8,
|
||||
STOVE_FUNCTION_WATER_TEMPERATURE = 9,
|
||||
STOVE_FUNCTION_WATER_PRESSURE = 10,
|
||||
STOVE_FUNCTION_POWER_LEVEL = 11,
|
||||
STOVE_FUNCTION_CUSTOM = 12
|
||||
};
|
||||
|
||||
class MicroNova;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
@@ -39,9 +23,6 @@ class MicroNovaBaseListener {
|
||||
|
||||
void set_micronova_object(MicroNova *m) { this->micronova_ = m; }
|
||||
|
||||
void set_function(MicroNovaFunctions f) { this->function_ = f; }
|
||||
MicroNovaFunctions get_function() { return this->function_; }
|
||||
|
||||
void set_memory_location(uint8_t l) { this->memory_location_ = l; }
|
||||
uint8_t get_memory_location() { return this->memory_location_; }
|
||||
|
||||
@@ -52,7 +33,6 @@ class MicroNovaBaseListener {
|
||||
|
||||
protected:
|
||||
MicroNova *micronova_{nullptr};
|
||||
MicroNovaFunctions function_ = MicroNovaFunctions::STOVE_FUNCTION_VOID;
|
||||
uint8_t memory_location_ = 0;
|
||||
uint8_t memory_address_ = 0;
|
||||
};
|
||||
|
||||
@@ -7,7 +7,6 @@ from .. import (
|
||||
CONF_MICRONOVA_ID,
|
||||
MICRONOVA_ADDRESS_SCHEMA,
|
||||
MicroNova,
|
||||
MicroNovaFunctions,
|
||||
MicroNovaListener,
|
||||
micronova_ns,
|
||||
to_code_micronova_listener,
|
||||
@@ -66,13 +65,9 @@ async def to_code(config):
|
||||
max_value=40,
|
||||
step=thermostat_temperature_config.get(CONF_STEP),
|
||||
)
|
||||
await to_code_micronova_listener(
|
||||
mv,
|
||||
numb,
|
||||
thermostat_temperature_config,
|
||||
MicroNovaFunctions.STOVE_FUNCTION_THERMOSTAT_TEMPERATURE,
|
||||
)
|
||||
await to_code_micronova_listener(mv, numb, thermostat_temperature_config)
|
||||
cg.add(numb.set_micronova_object(mv))
|
||||
cg.add(numb.set_use_step_scaling(True))
|
||||
|
||||
if power_level_config := config.get(CONF_POWER_LEVEL):
|
||||
numb = await number.new_number(
|
||||
@@ -81,7 +76,5 @@ async def to_code(config):
|
||||
max_value=5,
|
||||
step=1,
|
||||
)
|
||||
await to_code_micronova_listener(
|
||||
mv, numb, power_level_config, MicroNovaFunctions.STOVE_FUNCTION_POWER_LEVEL
|
||||
)
|
||||
await to_code_micronova_listener(mv, numb, power_level_config)
|
||||
cg.add(numb.set_micronova_object(mv))
|
||||
|
||||
@@ -3,38 +3,24 @@
|
||||
namespace esphome::micronova {
|
||||
|
||||
void MicroNovaNumber::process_value_from_stove(int value_from_stove) {
|
||||
float new_sensor_value = 0;
|
||||
|
||||
if (value_from_stove == -1) {
|
||||
this->publish_state(NAN);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (this->get_function()) {
|
||||
case MicroNovaFunctions::STOVE_FUNCTION_THERMOSTAT_TEMPERATURE:
|
||||
new_sensor_value = ((float) value_from_stove) * this->traits.get_step();
|
||||
break;
|
||||
case MicroNovaFunctions::STOVE_FUNCTION_POWER_LEVEL:
|
||||
new_sensor_value = (float) value_from_stove;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
float new_value = static_cast<float>(value_from_stove);
|
||||
if (this->use_step_scaling_) {
|
||||
new_value *= this->traits.get_step();
|
||||
}
|
||||
this->publish_state(new_sensor_value);
|
||||
this->publish_state(new_value);
|
||||
}
|
||||
|
||||
void MicroNovaNumber::control(float value) {
|
||||
uint8_t new_number = 0;
|
||||
|
||||
switch (this->get_function()) {
|
||||
case MicroNovaFunctions::STOVE_FUNCTION_THERMOSTAT_TEMPERATURE:
|
||||
new_number = (uint8_t) (value / this->traits.get_step());
|
||||
break;
|
||||
case MicroNovaFunctions::STOVE_FUNCTION_POWER_LEVEL:
|
||||
new_number = (uint8_t) value;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
uint8_t new_number;
|
||||
if (this->use_step_scaling_) {
|
||||
new_number = static_cast<uint8_t>(value / this->traits.get_step());
|
||||
} else {
|
||||
new_number = static_cast<uint8_t>(value);
|
||||
}
|
||||
this->micronova_->write_address(this->memory_location_, this->memory_address_, new_number);
|
||||
this->micronova_->request_update_listeners();
|
||||
|
||||
@@ -18,6 +18,11 @@ class MicroNovaNumber : public number::Number, public MicroNovaListener {
|
||||
this->micronova_->request_address(this->memory_location_, this->memory_address_, this);
|
||||
}
|
||||
void process_value_from_stove(int value_from_stove) override;
|
||||
|
||||
void set_use_step_scaling(bool v) { this->use_step_scaling_ = v; }
|
||||
|
||||
protected:
|
||||
bool use_step_scaling_ = false;
|
||||
};
|
||||
|
||||
} // namespace esphome::micronova
|
||||
|
||||
@@ -13,7 +13,6 @@ from .. import (
|
||||
CONF_MICRONOVA_ID,
|
||||
MICRONOVA_ADDRESS_SCHEMA,
|
||||
MicroNova,
|
||||
MicroNovaFunctions,
|
||||
MicroNovaListener,
|
||||
micronova_ns,
|
||||
to_code_micronova_listener,
|
||||
@@ -131,21 +130,21 @@ CONFIG_SCHEMA = cv.Schema(
|
||||
async def to_code(config):
|
||||
mv = await cg.get_variable(config[CONF_MICRONOVA_ID])
|
||||
|
||||
for key, fn in {
|
||||
CONF_ROOM_TEMPERATURE: MicroNovaFunctions.STOVE_FUNCTION_ROOM_TEMPERATURE,
|
||||
CONF_FUMES_TEMPERATURE: MicroNovaFunctions.STOVE_FUNCTION_FUMES_TEMPERATURE,
|
||||
CONF_STOVE_POWER: MicroNovaFunctions.STOVE_FUNCTION_STOVE_POWER,
|
||||
CONF_MEMORY_ADDRESS_SENSOR: MicroNovaFunctions.STOVE_FUNCTION_MEMORY_ADDRESS_SENSOR,
|
||||
CONF_WATER_TEMPERATURE: MicroNovaFunctions.STOVE_FUNCTION_WATER_TEMPERATURE,
|
||||
CONF_WATER_PRESSURE: MicroNovaFunctions.STOVE_FUNCTION_WATER_PRESSURE,
|
||||
for key, divisor in {
|
||||
CONF_ROOM_TEMPERATURE: 2,
|
||||
CONF_FUMES_TEMPERATURE: None,
|
||||
CONF_STOVE_POWER: None,
|
||||
CONF_MEMORY_ADDRESS_SENSOR: None,
|
||||
CONF_WATER_TEMPERATURE: 2,
|
||||
CONF_WATER_PRESSURE: 10,
|
||||
}.items():
|
||||
if sensor_config := config.get(key):
|
||||
sens = await sensor.new_sensor(sensor_config, mv)
|
||||
await to_code_micronova_listener(mv, sens, sensor_config, fn)
|
||||
await to_code_micronova_listener(mv, sens, sensor_config)
|
||||
if divisor:
|
||||
cg.add(sens.set_divisor(divisor))
|
||||
|
||||
if fan_speed_config := config.get(CONF_FAN_SPEED):
|
||||
sens = await sensor.new_sensor(fan_speed_config, mv)
|
||||
await to_code_micronova_listener(
|
||||
mv, sens, fan_speed_config, MicroNovaFunctions.STOVE_FUNCTION_FAN_SPEED
|
||||
)
|
||||
await to_code_micronova_listener(mv, sens, fan_speed_config)
|
||||
cg.add(sens.set_fan_speed_offset(fan_speed_config[CONF_FAN_RPM_OFFSET]))
|
||||
|
||||
@@ -8,25 +8,15 @@ void MicroNovaSensor::process_value_from_stove(int value_from_stove) {
|
||||
return;
|
||||
}
|
||||
|
||||
float new_sensor_value = (float) value_from_stove;
|
||||
switch (this->get_function()) {
|
||||
case MicroNovaFunctions::STOVE_FUNCTION_ROOM_TEMPERATURE:
|
||||
new_sensor_value = new_sensor_value / 2;
|
||||
break;
|
||||
case MicroNovaFunctions::STOVE_FUNCTION_THERMOSTAT_TEMPERATURE:
|
||||
break;
|
||||
case MicroNovaFunctions::STOVE_FUNCTION_FAN_SPEED:
|
||||
new_sensor_value = new_sensor_value == 0 ? 0 : (new_sensor_value * 10) + this->fan_speed_offset_;
|
||||
break;
|
||||
case MicroNovaFunctions::STOVE_FUNCTION_WATER_TEMPERATURE:
|
||||
new_sensor_value = new_sensor_value / 2;
|
||||
break;
|
||||
case MicroNovaFunctions::STOVE_FUNCTION_WATER_PRESSURE:
|
||||
new_sensor_value = new_sensor_value / 10;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
float new_sensor_value = static_cast<float>(value_from_stove);
|
||||
|
||||
// Fan speed has special calculation: value * 10 + offset (when non-zero)
|
||||
if (this->is_fan_speed_) {
|
||||
new_sensor_value = value_from_stove == 0 ? 0.0f : (new_sensor_value * 10) + this->fan_speed_offset_;
|
||||
} else if (this->divisor_ > 1) {
|
||||
new_sensor_value = new_sensor_value / this->divisor_;
|
||||
}
|
||||
|
||||
this->publish_state(new_sensor_value);
|
||||
}
|
||||
|
||||
|
||||
@@ -18,11 +18,16 @@ class MicroNovaSensor : public sensor::Sensor, public MicroNovaListener {
|
||||
}
|
||||
void process_value_from_stove(int value_from_stove) override;
|
||||
|
||||
void set_fan_speed_offset(uint8_t f) { this->fan_speed_offset_ = f; }
|
||||
uint8_t get_set_fan_speed_offset() { return this->fan_speed_offset_; }
|
||||
void set_divisor(uint8_t d) { this->divisor_ = d; }
|
||||
void set_fan_speed_offset(uint8_t offset) {
|
||||
this->is_fan_speed_ = true;
|
||||
this->fan_speed_offset_ = offset;
|
||||
}
|
||||
|
||||
protected:
|
||||
int fan_speed_offset_ = 0;
|
||||
uint8_t divisor_ = 1;
|
||||
uint8_t fan_speed_offset_ = 0;
|
||||
bool is_fan_speed_ = false;
|
||||
};
|
||||
|
||||
} // namespace esphome::micronova
|
||||
|
||||
@@ -7,7 +7,6 @@ from .. import (
|
||||
CONF_MICRONOVA_ID,
|
||||
MICRONOVA_ADDRESS_SCHEMA,
|
||||
MicroNova,
|
||||
MicroNovaFunctions,
|
||||
MicroNovaListener,
|
||||
micronova_ns,
|
||||
to_code_micronova_listener,
|
||||
@@ -50,8 +49,6 @@ async def to_code(config):
|
||||
|
||||
if stove_config := config.get(CONF_STOVE):
|
||||
sw = await switch.new_switch(stove_config, mv)
|
||||
await to_code_micronova_listener(
|
||||
mv, sw, stove_config, MicroNovaFunctions.STOVE_FUNCTION_SWITCH
|
||||
)
|
||||
await to_code_micronova_listener(mv, sw, stove_config)
|
||||
cg.add(sw.set_memory_data_on(stove_config[CONF_MEMORY_DATA_ON]))
|
||||
cg.add(sw.set_memory_data_off(stove_config[CONF_MEMORY_DATA_OFF]))
|
||||
|
||||
@@ -3,31 +3,24 @@
|
||||
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;
|
||||
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_);
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
this->set_needs_update(true);
|
||||
}
|
||||
|
||||
void MicroNovaSwitch::process_value_from_stove(int value_from_stove) {
|
||||
@@ -37,16 +30,9 @@ void MicroNovaSwitch::process_value_from_stove(int value_from_stove) {
|
||||
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;
|
||||
}
|
||||
// set the stove switch to on for any value but 0
|
||||
bool state = value_from_stove != 0;
|
||||
this->publish_state(state);
|
||||
}
|
||||
|
||||
} // namespace esphome::micronova
|
||||
|
||||
@@ -6,7 +6,6 @@ from .. import (
|
||||
CONF_MICRONOVA_ID,
|
||||
MICRONOVA_ADDRESS_SCHEMA,
|
||||
MicroNova,
|
||||
MicroNovaFunctions,
|
||||
MicroNovaListener,
|
||||
micronova_ns,
|
||||
to_code_micronova_listener,
|
||||
@@ -39,6 +38,4 @@ async def to_code(config):
|
||||
|
||||
if stove_state_config := config.get(CONF_STOVE_STATE):
|
||||
sens = await text_sensor.new_text_sensor(stove_state_config, mv)
|
||||
await to_code_micronova_listener(
|
||||
mv, sens, stove_state_config, MicroNovaFunctions.STOVE_FUNCTION_STOVE_STATE
|
||||
)
|
||||
await to_code_micronova_listener(mv, sens, stove_state_config)
|
||||
|
||||
@@ -8,13 +8,7 @@ void MicroNovaTextSensor::process_value_from_stove(int value_from_stove) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (this->get_function()) {
|
||||
case MicroNovaFunctions::STOVE_FUNCTION_STOVE_STATE:
|
||||
this->publish_state(STOVE_STATES[value_from_stove]);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
this->publish_state(STOVE_STATES[value_from_stove]);
|
||||
}
|
||||
|
||||
} // namespace esphome::micronova
|
||||
|
||||
Reference in New Issue
Block a user