[micronova] Require memory location and address for custom entities (#12371)
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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]))
|
||||
|
||||
@@ -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,
|
||||
)
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user