diff --git a/esphome/components/graphical_layout/text_panel.cpp b/esphome/components/graphical_layout/text_panel.cpp index 09aeaa5d08..9e1b7c4d2b 100644 --- a/esphome/components/graphical_layout/text_panel.cpp +++ b/esphome/components/graphical_layout/text_panel.cpp @@ -31,9 +31,7 @@ void TextPanel::dump_config(int indent_depth, int additional_level_depth) { void TextPanel::setup_complete() { if (!this->text_formatter_.has_value()) { - this->text_formatter_ = [this](const std::string string) { - return string; - }; + this->text_formatter_ = [this](const std::string string) { return string; }; } if (this->sensor_ != nullptr) { @@ -47,15 +45,11 @@ void TextPanel::setup_complete() { if (this->text_sensor_ != nullptr) { // Need to setup the text callback to the TextSensor - this->text_ = [this]() { - return this->text_formatter_.value(this->text_sensor_->get_state()); - }; + this->text_ = [this]() { return this->text_formatter_.value(this->text_sensor_->get_state()); }; } if (this->text_input_.has_value()) { - this->text_ = [this]() { - return this->text_formatter_.value(this->text_input_.value()); - }; + this->text_ = [this]() { return this->text_formatter_.value(this->text_input_.value()); }; } } diff --git a/esphome/components/graphical_layout/text_panel.py b/esphome/components/graphical_layout/text_panel.py index 4cdc8695bf..bc149aad92 100644 --- a/esphome/components/graphical_layout/text_panel.py +++ b/esphome/components/graphical_layout/text_panel.py @@ -2,7 +2,7 @@ import esphome.codegen as cg import esphome.config_validation as cv from esphome.components import font, color, sensor, text_sensor from esphome.components.display import display_ns -from esphome.const import CONF_FOREGROUND_COLOR, CONF_BACKGROUND_COLOR, CONST_SENSOR +from esphome.const import CONF_FOREGROUND_COLOR, CONF_BACKGROUND_COLOR, CONF_SENSOR graphical_layout_ns = cg.esphome_ns.namespace("graphical_layout") TextPanel = graphical_layout_ns.class_("TextPanel") diff --git a/esphome/components/graphical_layout/text_run_panel.h b/esphome/components/graphical_layout/text_run_panel.h index 2ef4e45751..99bdc068b1 100644 --- a/esphome/components/graphical_layout/text_run_panel.h +++ b/esphome/components/graphical_layout/text_run_panel.h @@ -31,15 +31,13 @@ struct CanWrapAtCharacterArguments { class TextRunBase { public: - TextRunBase(display::BaseFont *font) { - this->font_ = font; - } + TextRunBase(display::BaseFont *font) { this->font_ = font; } + void set_foreground_color(Color foreground_color) { this->foreground_color_ = foreground_color; } void set_background_color(Color background_color) { this->background_color_ = background_color; } virtual std::string get_text() = 0; - display::BaseFont *font_{nullptr}; Color foreground_color_{COLOR_ON}; Color background_color_{COLOR_OFF}; @@ -67,19 +65,15 @@ class TextRun : public TextRunBase, public FormattableTextRun { this->text_ = std::move(text); } - std::string get_text() override { - return this->format_text(text_.value()); - } + std::string get_text() override { return this->format_text(text_.value()); } protected: TemplatableValue text_{}; }; class SensorTextRun : public TextRunBase, public FormattableTextRun { - public: - SensorTextRun(sensor::Sensor *sensor, display::BaseFont *font) : TextRunBase(font) { - this->sensor_ = sensor; - } + public: + SensorTextRun(sensor::Sensor *sensor, display::BaseFont *font) : TextRunBase(font) { this->sensor_ = sensor; } std::string get_text() override { std::stringstream stream; @@ -97,9 +91,8 @@ class TextSensorTextRun : public TextRunBase, public FormattableTextRun { this->text_sensor_ = text_sensor; } - std::string get_text() override { - return this->format_text(this->text_sensor_->get_state()); - } + std::string get_text() override { return this->format_text(this->text_sensor_->get_state()); } + protected: text_sensor::TextSensor *text_sensor_{nullptr}; diff --git a/esphome/components/graphical_layout/text_run_panel.py b/esphome/components/graphical_layout/text_run_panel.py index f09c304bdd..2d97cd5e8d 100644 --- a/esphome/components/graphical_layout/text_run_panel.py +++ b/esphome/components/graphical_layout/text_run_panel.py @@ -2,7 +2,12 @@ import esphome.codegen as cg import esphome.config_validation as cv from esphome.components import font, color, sensor, text_sensor from esphome.components.display import display_ns -from esphome.const import CONF_ID, CONF_FOREGROUND_COLOR, CONF_BACKGROUND_COLOR, CONF_SENSOR +from esphome.const import ( + CONF_ID, + CONF_FOREGROUND_COLOR, + CONF_BACKGROUND_COLOR, + CONF_SENSOR, +) graphical_layout_ns = cg.esphome_ns.namespace("graphical_layout") TextRunPanel = graphical_layout_ns.class_("TextRunPanel")