mirror of
https://github.com/esphome/esphome.git
synced 2024-11-28 12:46:22 +01:00
Lint/clang fixes
This commit is contained in:
parent
25b2897268
commit
8cb27b5b78
@ -1,10 +1,10 @@
|
||||
import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
import esphome.components.graphical_layout.horizontal_stack as horizontal_stack
|
||||
import esphome.components.graphical_layout.vertical_stack as vertical_stack
|
||||
import esphome.components.graphical_layout.text_panel as text_panel
|
||||
from esphome.components import font, color
|
||||
from esphome.const import CONF_ID
|
||||
from esphome.components.graphical_layout import horizontal_stack
|
||||
from esphome.components.graphical_layout import vertical_stack
|
||||
from esphome.components.graphical_layout import text_panel
|
||||
|
||||
graphical_layout_ns = cg.esphome_ns.namespace("graphical_layout")
|
||||
RootLayoutComponent = graphical_layout_ns.class_("RootLayoutComponent", cg.Component)
|
||||
@ -21,42 +21,48 @@ CONF_ITEMS = "items"
|
||||
CONF_LAYOUT = "layout"
|
||||
CONF_ITEM_TYPE = "type"
|
||||
|
||||
BASE_ITEM_SCHEMA = cv.Schema(
|
||||
{
|
||||
}
|
||||
)
|
||||
BASE_ITEM_SCHEMA = cv.Schema({})
|
||||
|
||||
def item_type_schema(value):
|
||||
return ITEM_TYPE_SCHEMA(value)
|
||||
|
||||
|
||||
ITEM_TYPE_SCHEMA = cv.typed_schema(
|
||||
{
|
||||
text_panel.CONF_TYPE: cv.Schema(
|
||||
text_panel.CONF_TYPE: BASE_ITEM_SCHEMA.extend(
|
||||
{
|
||||
cv.GenerateID(): cv.declare_id(text_panel.TextPanel),
|
||||
cv.Optional(text_panel.CONF_ITEM_PADDING, default=0): cv.templatable(cv.int_),
|
||||
cv.Required(text_panel.CONF_FONT): cv.use_id(font.Font),
|
||||
cv.Optional(text_panel.CONF_FOREGROUND_COLOR): cv.use_id(color.ColorStruct),
|
||||
cv.Optional(text_panel.CONF_BACKGROUND_COLOR): cv.use_id(color.ColorStruct),
|
||||
cv.Optional(text_panel.CONF_FOREGROUND_COLOR): cv.use_id(
|
||||
color.ColorStruct
|
||||
),
|
||||
cv.Optional(text_panel.CONF_BACKGROUND_COLOR): cv.use_id(
|
||||
color.ColorStruct
|
||||
),
|
||||
cv.Required(text_panel.CONF_TEXT): cv.templatable(cv.string),
|
||||
}
|
||||
),
|
||||
horizontal_stack.CONF_TYPE: BASE_ITEM_SCHEMA.extend(
|
||||
{
|
||||
cv.GenerateID(): cv.declare_id(horizontal_stack.HorizontalStack),
|
||||
cv.Optional(horizontal_stack.CONF_ITEM_PADDING, default=0): cv.templatable(cv.int_),
|
||||
cv.Optional(
|
||||
horizontal_stack.CONF_ITEM_PADDING, default=0
|
||||
): cv.templatable(cv.int_),
|
||||
cv.Required(CONF_ITEMS): cv.All(
|
||||
cv.ensure_list(item_type_schema), cv.Length(min=1)
|
||||
)
|
||||
),
|
||||
}
|
||||
),
|
||||
vertical_stack.CONF_TYPE: BASE_ITEM_SCHEMA.extend(
|
||||
{
|
||||
cv.GenerateID(): cv.declare_id(vertical_stack.VerticalStack),
|
||||
cv.Optional(vertical_stack.CONF_ITEM_PADDING, default=0): cv.templatable(cv.int_),
|
||||
cv.Optional(
|
||||
vertical_stack.CONF_ITEM_PADDING, default=0
|
||||
): cv.templatable(cv.int_),
|
||||
cv.Required(CONF_ITEMS): cv.All(
|
||||
cv.ensure_list(item_type_schema), cv.Length(min=1)
|
||||
)
|
||||
),
|
||||
}
|
||||
)
|
||||
}
|
||||
@ -65,13 +71,13 @@ ITEM_TYPE_SCHEMA = cv.typed_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
|
||||
vertical_stack.CONF_TYPE: vertical_stack.config_to_layout_item,
|
||||
}
|
||||
|
||||
CONFIG_SCHEMA = cv.Schema(
|
||||
{
|
||||
cv.GenerateID(): cv.declare_id(RootLayoutComponent),
|
||||
cv.Required(CONF_LAYOUT): ITEM_TYPE_SCHEMA
|
||||
cv.Required(CONF_LAYOUT): ITEM_TYPE_SCHEMA,
|
||||
}
|
||||
).extend(cv.COMPONENT_SCHEMA)
|
||||
|
||||
|
@ -26,4 +26,4 @@ class ContainerLayoutItem : public LayoutItem {
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -48,4 +48,4 @@ void HorizontalStack::render(display::Display *display, display::Rect bounds) {
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -22,4 +22,4 @@ class HorizontalStack : public ContainerLayoutItem {
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
from esphome.const import CONF_ID
|
||||
|
||||
graphical_layout_ns = cg.esphome_ns.namespace("graphical_layout")
|
||||
@ -10,6 +9,7 @@ CONF_TYPE = "horizontal_stack"
|
||||
CONF_ITEMS = "items"
|
||||
CONF_ITEM_TYPE = "type"
|
||||
|
||||
|
||||
async def config_to_layout_item(item_config, child_item_builder):
|
||||
var = cg.new_Pvariable(item_config[CONF_ID])
|
||||
|
||||
@ -19,7 +19,9 @@ async def config_to_layout_item(item_config, child_item_builder):
|
||||
for child_item_config in item_config[CONF_ITEMS]:
|
||||
child_item_type = child_item_config[CONF_ITEM_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)
|
||||
child_item_var = await child_item_builder[child_item_type](
|
||||
child_item_config, child_item_builder
|
||||
)
|
||||
cg.add(var.add_item(child_item_var))
|
||||
else:
|
||||
raise f"Do not know how to build type {child_item_type}"
|
||||
|
@ -34,4 +34,4 @@ class LayoutItem {
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +0,0 @@
|
||||
import esphome.config_validation as cv
|
||||
from typing import Awaitable, Any, Callable, Optional
|
||||
|
||||
class LayoutImport:
|
||||
def __init__(self, name : str, schema_builder_func: Callable[[cv.Schema, cv.Schema, cv.Schema], cv.Schema], builder_func : Awaitable[Any], parent_schema_builder_func : Optional[Callable[[], cv.Schema]] = None):
|
||||
self.name = name
|
||||
self.schema_builder_func = schema_builder_func
|
||||
self.builder_func = builder_func
|
||||
self.parent_schema_builder_func = parent_schema_builder_func
|
@ -29,4 +29,4 @@ void TextPanel::render(display::Display *display, display::Rect bounds) {
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -33,4 +33,4 @@ class TextPanel : public LayoutItem {
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
from esphome.components import font, color
|
||||
from esphome.const import CONF_ID
|
||||
|
||||
@ -13,17 +12,6 @@ CONF_FOREGROUND_COLOR = "foreground_color"
|
||||
CONF_BACKGROUND_COLOR = "background_color"
|
||||
CONF_TEXT = "text"
|
||||
|
||||
LAYOUT_ITEM_SCHEMA = cv.Schema(
|
||||
{
|
||||
cv.GenerateID(): cv.declare_id(TextPanel),
|
||||
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),
|
||||
cv.Required(CONF_TEXT): cv.templatable(cv.string),
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
async def config_to_layout_item(item_config, child_item_builder):
|
||||
var = cg.new_Pvariable(item_config[CONF_ID])
|
||||
@ -31,8 +19,8 @@ async def config_to_layout_item(item_config, child_item_builder):
|
||||
if item_padding_config := item_config[CONF_ITEM_PADDING]:
|
||||
cg.add(var.set_item_padding(item_padding_config))
|
||||
|
||||
font = await cg.get_variable(item_config[CONF_FONT])
|
||||
cg.add(var.set_font(font))
|
||||
panel_font = await cg.get_variable(item_config[CONF_FONT])
|
||||
cg.add(var.set_font(panel_font))
|
||||
|
||||
if foreground_color_config := item_config.get(CONF_FOREGROUND_COLOR):
|
||||
foreground_color = await cg.get_variable(foreground_color_config)
|
||||
@ -42,7 +30,7 @@ async def config_to_layout_item(item_config, child_item_builder):
|
||||
background_color = await cg.get_variable(background_color_config)
|
||||
cg.add(var.set_background_color(background_color))
|
||||
|
||||
text = await cg.templatable(item_config[CONF_TEXT], args = [], output_type = str)
|
||||
text = await cg.templatable(item_config[CONF_TEXT], args=[], output_type=str)
|
||||
cg.add(var.set_text(text))
|
||||
|
||||
return var
|
||||
return var
|
||||
|
@ -47,4 +47,4 @@ void VerticalStack::render(display::Display *display, display::Rect bounds) {
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -22,4 +22,4 @@ class VerticalStack : public ContainerLayoutItem {
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
from esphome.const import CONF_ID
|
||||
|
||||
graphical_layout_ns = cg.esphome_ns.namespace("graphical_layout")
|
||||
@ -20,9 +19,11 @@ async def config_to_layout_item(item_config, child_item_builder):
|
||||
for child_item_config in item_config[CONF_ITEMS]:
|
||||
child_item_type = child_item_config[CONF_ITEM_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)
|
||||
child_item_var = await child_item_builder[child_item_type](
|
||||
child_item_config, child_item_builder
|
||||
)
|
||||
cg.add(var.add_item(child_item_var))
|
||||
else:
|
||||
raise f"Do not know how to build type {child_item_type}"
|
||||
|
||||
return var
|
||||
return var
|
||||
|
Loading…
Reference in New Issue
Block a user