From 329b38fa296b88c1dca4cd25ced351048a0ea85e Mon Sep 17 00:00:00 2001 From: Robert Resch Date: Tue, 9 Dec 2025 20:30:55 +0100 Subject: [PATCH] [micronova] Require memory location and address for custom entities (#12371) --- esphome/components/micronova/__init__.py | 24 +++++++++++-------- .../components/micronova/button/__init__.py | 6 ++--- .../components/micronova/sensor/__init__.py | 2 -- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/esphome/components/micronova/__init__.py b/esphome/components/micronova/__init__.py index 52fbae2da2..d6ef93cf30 100644 --- a/esphome/components/micronova/__init__.py +++ b/esphome/components/micronova/__init__.py @@ -40,21 +40,25 @@ FINAL_VALIDATE_SCHEMA = uart.final_validate_device_schema( def MICRONOVA_ADDRESS_SCHEMA( *, - default_memory_location: int, - default_memory_address: int, + default_memory_location: int | None = None, + default_memory_address: int | None = None, is_polling_component: bool, ): + location_key = ( + cv.Optional(CONF_MEMORY_LOCATION, default=default_memory_location) + if default_memory_location is not None + else cv.Required(CONF_MEMORY_LOCATION) + ) + address_key = ( + cv.Optional(CONF_MEMORY_ADDRESS, default=default_memory_address) + if default_memory_address is not None + else cv.Required(CONF_MEMORY_ADDRESS) + ) 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(min=0x00, max=0x79), - cv.Optional( - CONF_MEMORY_ADDRESS, default=default_memory_address - ): cv.hex_int_range(min=0x00, max=0xFF), + location_key: cv.hex_int_range(min=0x00, max=0x79), + address_key: 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 2eda887443..6adf8d96fe 100644 --- a/esphome/components/micronova/button/__init__.py +++ b/esphome/components/micronova/button/__init__.py @@ -24,8 +24,6 @@ CONFIG_SCHEMA = cv.Schema( ) .extend( MICRONOVA_ADDRESS_SCHEMA( - default_memory_location=0x20, - default_memory_address=0x7D, is_polling_component=False, ) ) @@ -39,6 +37,6 @@ async def to_code(config): if custom_button_config := config.get(CONF_CUSTOM_BUTTON): bt = await button.new_button(custom_button_config, mv) - 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_location(custom_button_config[CONF_MEMORY_LOCATION])) + cg.add(bt.set_memory_address(custom_button_config[CONF_MEMORY_ADDRESS])) cg.add(bt.set_memory_data(custom_button_config[CONF_MEMORY_DATA])) diff --git a/esphome/components/micronova/sensor/__init__.py b/esphome/components/micronova/sensor/__init__.py index 55318a7fff..e53c49aca5 100644 --- a/esphome/components/micronova/sensor/__init__.py +++ b/esphome/components/micronova/sensor/__init__.py @@ -118,8 +118,6 @@ CONFIG_SCHEMA = cv.Schema( MicroNovaSensor, ).extend( MICRONOVA_ADDRESS_SCHEMA( - default_memory_location=0x00, - default_memory_address=0x00, is_polling_component=True, ) ),