[micronova] Set the write bit automatically (#12318)
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> Co-authored-by: Jonathan Swoboda <154711427+swoboda1337@users.noreply.github.com>
This commit is contained in:
@@ -63,12 +63,14 @@ def MICRONOVA_ADDRESS_SCHEMA(
|
||||
schema = cv.Schema(
|
||||
{
|
||||
cv.GenerateID(CONF_MICRONOVA_ID): cv.use_id(MicroNova),
|
||||
# On write requests the write bit (0x80) is added automatically to the location
|
||||
# Therefore no locations >= 0x80 are allowed
|
||||
cv.Optional(
|
||||
CONF_MEMORY_LOCATION, default=default_memory_location
|
||||
): cv.hex_int_range(),
|
||||
): cv.hex_int_range(min=0x00, max=0x79),
|
||||
cv.Optional(
|
||||
CONF_MEMORY_ADDRESS, default=default_memory_address
|
||||
): cv.hex_int_range(),
|
||||
): cv.hex_int_range(min=0x00, max=0xFF),
|
||||
}
|
||||
)
|
||||
if is_polling_component:
|
||||
|
||||
@@ -25,7 +25,7 @@ CONFIG_SCHEMA = cv.Schema(
|
||||
)
|
||||
.extend(
|
||||
MICRONOVA_ADDRESS_SCHEMA(
|
||||
default_memory_location=0xA0,
|
||||
default_memory_location=0x20,
|
||||
default_memory_address=0x7D,
|
||||
is_polling_component=False,
|
||||
)
|
||||
|
||||
@@ -3,6 +3,9 @@
|
||||
|
||||
namespace esphome::micronova {
|
||||
|
||||
static const int STOVE_REPLY_DELAY = 60;
|
||||
static const uint8_t WRITE_BIT = 1 << 7; // 0x80
|
||||
|
||||
void MicroNovaBaseListener::dump_base_config() {
|
||||
ESP_LOGCONFIG(TAG,
|
||||
" Memory Location: %02X\n"
|
||||
@@ -125,7 +128,8 @@ void MicroNova::write_address(uint8_t location, uint8_t address, uint8_t data) {
|
||||
uint16_t checksum = 0;
|
||||
|
||||
if (this->reply_pending_mutex_.try_lock()) {
|
||||
write_data[0] = location;
|
||||
uint8_t write_location = location | WRITE_BIT;
|
||||
write_data[0] = write_location;
|
||||
write_data[1] = address;
|
||||
write_data[2] = data;
|
||||
|
||||
@@ -140,7 +144,7 @@ void MicroNova::write_address(uint8_t location, uint8_t address, uint8_t data) {
|
||||
this->enable_rx_pin_->digital_write(false);
|
||||
|
||||
this->current_transmission_.request_transmission_time = millis();
|
||||
this->current_transmission_.memory_location = location;
|
||||
this->current_transmission_.memory_location = write_location;
|
||||
this->current_transmission_.memory_address = address;
|
||||
this->current_transmission_.reply_pending = true;
|
||||
this->current_transmission_.initiating_listener = nullptr;
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
namespace esphome::micronova {
|
||||
|
||||
static const char *const TAG = "micronova";
|
||||
static const int STOVE_REPLY_DELAY = 60;
|
||||
|
||||
enum class MicroNovaFunctions {
|
||||
STOVE_FUNCTION_VOID = 0,
|
||||
|
||||
@@ -17,7 +17,6 @@ ICON_FLASH = "mdi:flash"
|
||||
|
||||
CONF_THERMOSTAT_TEMPERATURE = "thermostat_temperature"
|
||||
CONF_POWER_LEVEL = "power_level"
|
||||
CONF_MEMORY_WRITE_LOCATION = "memory_write_location"
|
||||
|
||||
MicroNovaNumber = micronova_ns.class_(
|
||||
"MicroNovaNumber", number.Number, MicroNovaListener
|
||||
@@ -40,25 +39,18 @@ CONFIG_SCHEMA = cv.Schema(
|
||||
)
|
||||
.extend(
|
||||
{
|
||||
cv.Optional(
|
||||
CONF_MEMORY_WRITE_LOCATION, default=0xA0
|
||||
): cv.hex_int_range(),
|
||||
cv.Optional(CONF_STEP, default=1.0): cv.float_range(min=0.1, max=10.0),
|
||||
}
|
||||
),
|
||||
cv.Optional(CONF_POWER_LEVEL): number.number_schema(
|
||||
MicroNovaNumber,
|
||||
icon=ICON_FLASH,
|
||||
)
|
||||
.extend(
|
||||
).extend(
|
||||
MICRONOVA_ADDRESS_SCHEMA(
|
||||
default_memory_location=0x20,
|
||||
default_memory_address=0x7F,
|
||||
is_polling_component=True,
|
||||
)
|
||||
)
|
||||
.extend(
|
||||
{cv.Optional(CONF_MEMORY_WRITE_LOCATION, default=0xA0): cv.hex_int_range()}
|
||||
),
|
||||
}
|
||||
)
|
||||
@@ -81,11 +73,6 @@ async def to_code(config):
|
||||
MicroNovaFunctions.STOVE_FUNCTION_THERMOSTAT_TEMPERATURE,
|
||||
)
|
||||
cg.add(numb.set_micronova_object(mv))
|
||||
cg.add(
|
||||
numb.set_memory_write_location(
|
||||
thermostat_temperature_config.get(CONF_MEMORY_WRITE_LOCATION)
|
||||
)
|
||||
)
|
||||
|
||||
if power_level_config := config.get(CONF_POWER_LEVEL):
|
||||
numb = await number.new_number(
|
||||
@@ -98,8 +85,3 @@ async def to_code(config):
|
||||
mv, numb, power_level_config, MicroNovaFunctions.STOVE_FUNCTION_POWER_LEVEL
|
||||
)
|
||||
cg.add(numb.set_micronova_object(mv))
|
||||
cg.add(
|
||||
numb.set_memory_write_location(
|
||||
power_level_config.get(CONF_MEMORY_WRITE_LOCATION)
|
||||
)
|
||||
)
|
||||
|
||||
@@ -36,7 +36,7 @@ void MicroNovaNumber::control(float value) {
|
||||
default:
|
||||
break;
|
||||
}
|
||||
this->micronova_->write_address(this->memory_write_location_, this->memory_address_, new_number);
|
||||
this->micronova_->write_address(this->memory_location_, this->memory_address_, new_number);
|
||||
this->micronova_->request_update_listeners();
|
||||
}
|
||||
|
||||
|
||||
@@ -18,12 +18,6 @@ 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_memory_write_location(uint8_t l) { this->memory_write_location_ = l; }
|
||||
uint8_t get_memory_write_location() { return this->memory_write_location_; }
|
||||
|
||||
protected:
|
||||
uint8_t memory_write_location_ = 0;
|
||||
};
|
||||
|
||||
} // namespace esphome::micronova
|
||||
|
||||
@@ -28,7 +28,7 @@ CONFIG_SCHEMA = cv.Schema(
|
||||
)
|
||||
.extend(
|
||||
MICRONOVA_ADDRESS_SCHEMA(
|
||||
default_memory_location=0x80,
|
||||
default_memory_location=0x00,
|
||||
default_memory_address=0x21,
|
||||
is_polling_component=False,
|
||||
)
|
||||
|
||||
@@ -5,7 +5,7 @@ button:
|
||||
- platform: micronova
|
||||
custom_button:
|
||||
name: Custom Micronova Button
|
||||
memory_location: 0xA0
|
||||
memory_location: 0x20
|
||||
memory_address: 0x7D
|
||||
memory_data: 0x0F
|
||||
|
||||
|
||||
Reference in New Issue
Block a user