From 8cb27b5b789f7a0d10e2a9c89c9dca9028a52fb3 Mon Sep 17 00:00:00 2001 From: Michael Davidson Date: Sun, 17 Dec 2023 21:34:09 +1100 Subject: [PATCH] Lint/clang fixes --- .../components/graphical_layout/__init__.py | 38 +++++++++++-------- .../graphical_layout/container_layout_item.h | 2 +- .../graphical_layout/horizontal_stack.cpp | 2 +- .../graphical_layout/horizontal_stack.h | 2 +- .../graphical_layout/horizontal_stack.py | 6 ++- .../components/graphical_layout/layout_item.h | 2 +- .../graphical_layout/layoutexport.py | 9 ----- .../graphical_layout/text_panel.cpp | 2 +- .../components/graphical_layout/text_panel.h | 2 +- .../components/graphical_layout/text_panel.py | 20 ++-------- .../graphical_layout/vertical_stack.cpp | 2 +- .../graphical_layout/vertical_stack.h | 2 +- .../graphical_layout/vertical_stack.py | 7 ++-- 13 files changed, 42 insertions(+), 54 deletions(-) delete mode 100644 esphome/components/graphical_layout/layoutexport.py diff --git a/esphome/components/graphical_layout/__init__.py b/esphome/components/graphical_layout/__init__.py index d8ae49329d..1770dac0d8 100644 --- a/esphome/components/graphical_layout/__init__.py +++ b/esphome/components/graphical_layout/__init__.py @@ -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) diff --git a/esphome/components/graphical_layout/container_layout_item.h b/esphome/components/graphical_layout/container_layout_item.h index 1832810c31..870fd126bc 100644 --- a/esphome/components/graphical_layout/container_layout_item.h +++ b/esphome/components/graphical_layout/container_layout_item.h @@ -26,4 +26,4 @@ class ContainerLayoutItem : public LayoutItem { }; } -} \ No newline at end of file +} diff --git a/esphome/components/graphical_layout/horizontal_stack.cpp b/esphome/components/graphical_layout/horizontal_stack.cpp index 3f1911dd34..013c33db2b 100644 --- a/esphome/components/graphical_layout/horizontal_stack.cpp +++ b/esphome/components/graphical_layout/horizontal_stack.cpp @@ -48,4 +48,4 @@ void HorizontalStack::render(display::Display *display, display::Rect bounds) { } } -} \ No newline at end of file +} diff --git a/esphome/components/graphical_layout/horizontal_stack.h b/esphome/components/graphical_layout/horizontal_stack.h index c2192ff68f..d79b90cd5d 100644 --- a/esphome/components/graphical_layout/horizontal_stack.h +++ b/esphome/components/graphical_layout/horizontal_stack.h @@ -22,4 +22,4 @@ class HorizontalStack : public ContainerLayoutItem { }; } -} \ No newline at end of file +} diff --git a/esphome/components/graphical_layout/horizontal_stack.py b/esphome/components/graphical_layout/horizontal_stack.py index 98f218f3a7..aa97b2531f 100644 --- a/esphome/components/graphical_layout/horizontal_stack.py +++ b/esphome/components/graphical_layout/horizontal_stack.py @@ -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}" diff --git a/esphome/components/graphical_layout/layout_item.h b/esphome/components/graphical_layout/layout_item.h index 117b26fba7..d0e2334057 100644 --- a/esphome/components/graphical_layout/layout_item.h +++ b/esphome/components/graphical_layout/layout_item.h @@ -34,4 +34,4 @@ class LayoutItem { }; } -} \ No newline at end of file +} diff --git a/esphome/components/graphical_layout/layoutexport.py b/esphome/components/graphical_layout/layoutexport.py deleted file mode 100644 index 3c69c56277..0000000000 --- a/esphome/components/graphical_layout/layoutexport.py +++ /dev/null @@ -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 \ No newline at end of file diff --git a/esphome/components/graphical_layout/text_panel.cpp b/esphome/components/graphical_layout/text_panel.cpp index b70b94dd7d..3c4ae131e6 100644 --- a/esphome/components/graphical_layout/text_panel.cpp +++ b/esphome/components/graphical_layout/text_panel.cpp @@ -29,4 +29,4 @@ void TextPanel::render(display::Display *display, display::Rect bounds) { } } -} \ No newline at end of file +} diff --git a/esphome/components/graphical_layout/text_panel.h b/esphome/components/graphical_layout/text_panel.h index e840b8e9d1..c88d31c35f 100644 --- a/esphome/components/graphical_layout/text_panel.h +++ b/esphome/components/graphical_layout/text_panel.h @@ -33,4 +33,4 @@ class TextPanel : public LayoutItem { }; } -} \ No newline at end of file +} diff --git a/esphome/components/graphical_layout/text_panel.py b/esphome/components/graphical_layout/text_panel.py index 377f3c8375..a50c9ab124 100644 --- a/esphome/components/graphical_layout/text_panel.py +++ b/esphome/components/graphical_layout/text_panel.py @@ -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 \ No newline at end of file + return var diff --git a/esphome/components/graphical_layout/vertical_stack.cpp b/esphome/components/graphical_layout/vertical_stack.cpp index eda18f53c1..66cf8d1533 100644 --- a/esphome/components/graphical_layout/vertical_stack.cpp +++ b/esphome/components/graphical_layout/vertical_stack.cpp @@ -47,4 +47,4 @@ void VerticalStack::render(display::Display *display, display::Rect bounds) { } } -} \ No newline at end of file +} diff --git a/esphome/components/graphical_layout/vertical_stack.h b/esphome/components/graphical_layout/vertical_stack.h index 412ae230b3..995a350739 100644 --- a/esphome/components/graphical_layout/vertical_stack.h +++ b/esphome/components/graphical_layout/vertical_stack.h @@ -22,4 +22,4 @@ class VerticalStack : public ContainerLayoutItem { }; } -} \ No newline at end of file +} diff --git a/esphome/components/graphical_layout/vertical_stack.py b/esphome/components/graphical_layout/vertical_stack.py index 5b5be39f7f..980cf99658 100644 --- a/esphome/components/graphical_layout/vertical_stack.py +++ b/esphome/components/graphical_layout/vertical_stack.py @@ -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 \ No newline at end of file + return var