mirror of
https://github.com/esphome/esphome.git
synced 2024-11-24 12:06:26 +01:00
Apply build fixes, black, flake8, pylint, and ci-custom recommendation
This commit is contained in:
parent
0403562e3a
commit
130ce44c51
@ -31,9 +31,7 @@ void TextPanel::dump_config(int indent_depth, int additional_level_depth) {
|
|||||||
|
|
||||||
void TextPanel::setup_complete() {
|
void TextPanel::setup_complete() {
|
||||||
if (!this->text_formatter_.has_value()) {
|
if (!this->text_formatter_.has_value()) {
|
||||||
this->text_formatter_ = [this](const std::string string) {
|
this->text_formatter_ = [this](const std::string string) { return string; };
|
||||||
return string;
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this->sensor_ != nullptr) {
|
if (this->sensor_ != nullptr) {
|
||||||
@ -47,15 +45,11 @@ void TextPanel::setup_complete() {
|
|||||||
|
|
||||||
if (this->text_sensor_ != nullptr) {
|
if (this->text_sensor_ != nullptr) {
|
||||||
// Need to setup the text callback to the TextSensor
|
// Need to setup the text callback to the TextSensor
|
||||||
this->text_ = [this]() {
|
this->text_ = [this]() { return this->text_formatter_.value(this->text_sensor_->get_state()); };
|
||||||
return this->text_formatter_.value(this->text_sensor_->get_state());
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this->text_input_.has_value()) {
|
if (this->text_input_.has_value()) {
|
||||||
this->text_ = [this]() {
|
this->text_ = [this]() { return this->text_formatter_.value(this->text_input_.value()); };
|
||||||
return this->text_formatter_.value(this->text_input_.value());
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@ import esphome.codegen as cg
|
|||||||
import esphome.config_validation as cv
|
import esphome.config_validation as cv
|
||||||
from esphome.components import font, color, sensor, text_sensor
|
from esphome.components import font, color, sensor, text_sensor
|
||||||
from esphome.components.display import display_ns
|
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")
|
graphical_layout_ns = cg.esphome_ns.namespace("graphical_layout")
|
||||||
TextPanel = graphical_layout_ns.class_("TextPanel")
|
TextPanel = graphical_layout_ns.class_("TextPanel")
|
||||||
|
@ -31,15 +31,13 @@ struct CanWrapAtCharacterArguments {
|
|||||||
|
|
||||||
class TextRunBase {
|
class TextRunBase {
|
||||||
public:
|
public:
|
||||||
TextRunBase(display::BaseFont *font) {
|
TextRunBase(display::BaseFont *font) { this->font_ = font; }
|
||||||
this->font_ = font;
|
|
||||||
}
|
|
||||||
|
|
||||||
void set_foreground_color(Color foreground_color) { this->foreground_color_ = foreground_color; }
|
void set_foreground_color(Color foreground_color) { this->foreground_color_ = foreground_color; }
|
||||||
void set_background_color(Color background_color) { this->background_color_ = background_color; }
|
void set_background_color(Color background_color) { this->background_color_ = background_color; }
|
||||||
virtual std::string get_text() = 0;
|
virtual std::string get_text() = 0;
|
||||||
|
|
||||||
|
|
||||||
display::BaseFont *font_{nullptr};
|
display::BaseFont *font_{nullptr};
|
||||||
Color foreground_color_{COLOR_ON};
|
Color foreground_color_{COLOR_ON};
|
||||||
Color background_color_{COLOR_OFF};
|
Color background_color_{COLOR_OFF};
|
||||||
@ -67,19 +65,15 @@ class TextRun : public TextRunBase, public FormattableTextRun {
|
|||||||
this->text_ = std::move(text);
|
this->text_ = std::move(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string get_text() override {
|
std::string get_text() override { return this->format_text(text_.value()); }
|
||||||
return this->format_text(text_.value());
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
TemplatableValue<std::string> text_{};
|
TemplatableValue<std::string> text_{};
|
||||||
};
|
};
|
||||||
|
|
||||||
class SensorTextRun : public TextRunBase, public FormattableTextRun {
|
class SensorTextRun : public TextRunBase, public FormattableTextRun {
|
||||||
public:
|
public:
|
||||||
SensorTextRun(sensor::Sensor *sensor, display::BaseFont *font) : TextRunBase(font) {
|
SensorTextRun(sensor::Sensor *sensor, display::BaseFont *font) : TextRunBase(font) { this->sensor_ = sensor; }
|
||||||
this->sensor_ = sensor;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string get_text() override {
|
std::string get_text() override {
|
||||||
std::stringstream stream;
|
std::stringstream stream;
|
||||||
@ -97,9 +91,8 @@ class TextSensorTextRun : public TextRunBase, public FormattableTextRun {
|
|||||||
this->text_sensor_ = text_sensor;
|
this->text_sensor_ = text_sensor;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string get_text() override {
|
std::string get_text() override { return this->format_text(this->text_sensor_->get_state()); }
|
||||||
return this->format_text(this->text_sensor_->get_state());
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
text_sensor::TextSensor *text_sensor_{nullptr};
|
text_sensor::TextSensor *text_sensor_{nullptr};
|
||||||
|
@ -2,7 +2,12 @@ import esphome.codegen as cg
|
|||||||
import esphome.config_validation as cv
|
import esphome.config_validation as cv
|
||||||
from esphome.components import font, color, sensor, text_sensor
|
from esphome.components import font, color, sensor, text_sensor
|
||||||
from esphome.components.display import display_ns
|
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")
|
graphical_layout_ns = cg.esphome_ns.namespace("graphical_layout")
|
||||||
TextRunPanel = graphical_layout_ns.class_("TextRunPanel")
|
TextRunPanel = graphical_layout_ns.class_("TextRunPanel")
|
||||||
|
Loading…
Reference in New Issue
Block a user