diff --git a/esphome/components/micronova/__init__.py b/esphome/components/micronova/__init__.py index 11213e82c5..637d0eb168 100644 --- a/esphome/components/micronova/__init__.py +++ b/esphome/components/micronova/__init__.py @@ -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: diff --git a/esphome/components/micronova/button/__init__.py b/esphome/components/micronova/button/__init__.py index dd57c9ec4f..38fee2f561 100644 --- a/esphome/components/micronova/button/__init__.py +++ b/esphome/components/micronova/button/__init__.py @@ -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, ) diff --git a/esphome/components/micronova/micronova.cpp b/esphome/components/micronova/micronova.cpp index 7343bc90ba..22daef4fe6 100644 --- a/esphome/components/micronova/micronova.cpp +++ b/esphome/components/micronova/micronova.cpp @@ -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; diff --git a/esphome/components/micronova/micronova.h b/esphome/components/micronova/micronova.h index c5a5ba4f4e..a2eee81be8 100644 --- a/esphome/components/micronova/micronova.h +++ b/esphome/components/micronova/micronova.h @@ -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, diff --git a/esphome/components/micronova/number/__init__.py b/esphome/components/micronova/number/__init__.py index ec994a5aa5..07023e618c 100644 --- a/esphome/components/micronova/number/__init__.py +++ b/esphome/components/micronova/number/__init__.py @@ -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) - ) - ) diff --git a/esphome/components/micronova/number/micronova_number.cpp b/esphome/components/micronova/number/micronova_number.cpp index 66e81e98b7..c71d819ad6 100644 --- a/esphome/components/micronova/number/micronova_number.cpp +++ b/esphome/components/micronova/number/micronova_number.cpp @@ -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(); } diff --git a/esphome/components/micronova/number/micronova_number.h b/esphome/components/micronova/number/micronova_number.h index e1545bb35a..391765b730 100644 --- a/esphome/components/micronova/number/micronova_number.h +++ b/esphome/components/micronova/number/micronova_number.h @@ -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 diff --git a/esphome/components/micronova/switch/__init__.py b/esphome/components/micronova/switch/__init__.py index 006ada92aa..c6897d8e5c 100644 --- a/esphome/components/micronova/switch/__init__.py +++ b/esphome/components/micronova/switch/__init__.py @@ -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, ) diff --git a/tests/components/micronova/common.yaml b/tests/components/micronova/common.yaml index 73456aa199..660970350a 100644 --- a/tests/components/micronova/common.yaml +++ b/tests/components/micronova/common.yaml @@ -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