Fix usage of CONF_TYPE

This commit is contained in:
Michael Davidson 2023-12-20 22:53:40 +11:00
parent 64ff886806
commit 64d34b2879
No known key found for this signature in database
GPG Key ID: B8D1A99712B8B0EB
5 changed files with 17 additions and 21 deletions

View File

@ -28,26 +28,26 @@ def item_type_schema(value):
ITEM_TYPE_SCHEMA = cv.typed_schema(
{
text_panel.CONF_TYPE: text_panel.get_config_schema(
text_panel.CONF_TEXT_PANEL: text_panel.get_config_schema(
BASE_ITEM_SCHEMA, item_type_schema
),
horizontal_stack.CONF_TYPE: horizontal_stack.get_config_schema(
horizontal_stack.CONF_HORIZONTAL_STACK: horizontal_stack.get_config_schema(
BASE_ITEM_SCHEMA, item_type_schema
),
vertical_stack.CONF_TYPE: vertical_stack.get_config_schema(
vertical_stack.CONF_VERTICAL_STACK: vertical_stack.get_config_schema(
BASE_ITEM_SCHEMA, item_type_schema
),
display_rendering_panel.CONF_TYPE: display_rendering_panel.get_config_schema(
display_rendering_panel.CONF_DISPLAY_RENDERING_PANEL: display_rendering_panel.get_config_schema(
BASE_ITEM_SCHEMA, item_type_schema
),
}
)
CODE_GENERATORS = {
text_panel.CONF_TYPE: text_panel.config_to_layout_item,
horizontal_stack.CONF_TYPE: horizontal_stack.config_to_layout_item,
vertical_stack.CONF_TYPE: vertical_stack.config_to_layout_item,
display_rendering_panel.CONF_TYPE: display_rendering_panel.config_to_layout_item,
text_panel.CONF_TEXT_PANEL: text_panel.config_to_layout_item,
horizontal_stack.CONF_HORIZONTAL_STACK: horizontal_stack.config_to_layout_item,
vertical_stack.CONF_VERTICAL_STACK: vertical_stack.config_to_layout_item,
display_rendering_panel.CONF_DISPLAY_RENDERING_PANEL: display_rendering_panel.config_to_layout_item,
}
CONFIG_SCHEMA = cv.Schema(

View File

@ -6,7 +6,7 @@ from esphome.components.display import DisplayRef
graphical_layout_ns = cg.esphome_ns.namespace("graphical_layout")
DisplayRenderingPanel = graphical_layout_ns.class_("DisplayRenderingPanel")
CONF_TYPE = "display_rendering_panel"
CONF_DISPLAY_RENDERING_PANEL = "display_rendering_panel"
def get_config_schema(base_item_schema, item_type_schema):

View File

@ -1,14 +1,13 @@
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.const import CONF_ID
from esphome.const import CONF_ID, CONF_TYPE
graphical_layout_ns = cg.esphome_ns.namespace("graphical_layout")
HorizontalStack = graphical_layout_ns.class_("HorizontalStack")
CONF_ITEM_PADDING = "item_padding"
CONF_TYPE = "horizontal_stack"
CONF_HORIZONTAL_STACK = "horizontal_stack"
CONF_ITEMS = "items"
CONF_TYPE_KEY = "type"
def get_config_schema(base_item_schema, item_type_schema):
@ -30,7 +29,7 @@ async def config_to_layout_item(item_config, child_item_builder):
cg.add(var.set_item_padding(item_padding_config))
for child_item_config in item_config[CONF_ITEMS]:
child_item_type = child_item_config[CONF_TYPE_KEY]
child_item_type = child_item_config[CONF_TYPE]
if child_item_type in child_item_builder:
child_item_var = await child_item_builder[child_item_type](
child_item_config, child_item_builder

View File

@ -7,7 +7,7 @@ graphical_layout_ns = cg.esphome_ns.namespace("graphical_layout")
TextPanel = graphical_layout_ns.class_("TextPanel")
CONF_ITEM_PADDING = "item_padding"
CONF_TYPE = "text_panel"
CONF_TEXT_PANEL = "text_panel"
CONF_FONT = "font"
CONF_FOREGROUND_COLOR = "foreground_color"
CONF_BACKGROUND_COLOR = "background_color"
@ -18,9 +18,7 @@ def get_config_schema(base_item_schema, item_type_schema):
return base_item_schema.extend(
{
cv.GenerateID(): cv.declare_id(TextPanel),
cv.Optional(CONF_ITEM_PADDING, default=0): cv.templatable(
cv.int_
),
cv.Optional(CONF_ITEM_PADDING, default=0): cv.templatable(cv.int_),
cv.Required(CONF_FONT): cv.use_id(font.Font),
cv.Optional(CONF_FOREGROUND_COLOR): cv.use_id(color.ColorStruct),
cv.Optional(CONF_BACKGROUND_COLOR): cv.use_id(color.ColorStruct),

View File

@ -1,14 +1,13 @@
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.const import CONF_ID
from esphome.const import CONF_ID, CONF_TYPE
graphical_layout_ns = cg.esphome_ns.namespace("graphical_layout")
VerticalStack = graphical_layout_ns.class_("VerticalStack")
CONF_ITEM_PADDING = "item_padding"
CONF_TYPE = "vertical_stack"
CONF_VERTICAL_STACK = "vertical_stack"
CONF_ITEMS = "items"
CONF_TYPE_KEY = "type"
def get_config_schema(base_item_schema, item_type_schema):
@ -30,7 +29,7 @@ async def config_to_layout_item(item_config, child_item_builder):
cg.add(var.set_item_padding(item_padding_config))
for child_item_config in item_config[CONF_ITEMS]:
child_item_type = child_item_config[CONF_TYPE_KEY]
child_item_type = child_item_config[CONF_TYPE]
if child_item_type in child_item_builder:
child_item_var = await child_item_builder[child_item_type](
child_item_config, child_item_builder