mirror of
https://github.com/esphome/esphome.git
synced 2024-11-23 15:38:11 +01:00
Merge branch 'dev' into platform
This commit is contained in:
commit
6fbcfc798b
17 changed files with 237 additions and 70 deletions
|
@ -32,9 +32,9 @@ RUN \
|
|||
python3-setuptools=66.1.1-1 \
|
||||
python3-venv=3.11.2-1+b1 \
|
||||
python3-wheel=0.38.4-2 \
|
||||
iputils-ping=3:20221126-1 \
|
||||
iputils-ping=3:20221126-1+deb12u1 \
|
||||
git=1:2.39.5-0+deb12u1 \
|
||||
curl=7.88.1-10+deb12u7 \
|
||||
curl=7.88.1-10+deb12u8 \
|
||||
openssh-client=1:9.2p1-2+deb12u3 \
|
||||
python3-cffi=1.15.1-5 \
|
||||
libcairo2=1.16.0-7 \
|
||||
|
@ -97,7 +97,7 @@ BUILD_DEPS="
|
|||
zlib1g-dev=1:1.2.13.dfsg-1
|
||||
libjpeg-dev=1:2.1.5-2
|
||||
libfreetype-dev=2.12.1+dfsg-5+deb12u3
|
||||
libssl-dev=3.0.14-1~deb12u2
|
||||
libssl-dev=3.0.15-1~deb12u1
|
||||
libffi-dev=3.4.4-1
|
||||
libopenjp2-7=2.5.0-2
|
||||
libtiff6=4.5.0-6+deb12u1
|
||||
|
|
|
@ -20,6 +20,8 @@ from esphome.const import (
|
|||
CONF_DEASSERT_RTS_DTR,
|
||||
CONF_DISABLED,
|
||||
CONF_ESPHOME,
|
||||
CONF_LEVEL,
|
||||
CONF_LOG_TOPIC,
|
||||
CONF_LOGGER,
|
||||
CONF_MDNS,
|
||||
CONF_MQTT,
|
||||
|
@ -30,6 +32,7 @@ from esphome.const import (
|
|||
CONF_PLATFORMIO_OPTIONS,
|
||||
CONF_PORT,
|
||||
CONF_SUBSTITUTIONS,
|
||||
CONF_TOPIC,
|
||||
PLATFORM_BK72XX,
|
||||
PLATFORM_ESP32,
|
||||
PLATFORM_ESP8266,
|
||||
|
@ -95,8 +98,12 @@ def choose_upload_log_host(
|
|||
options.append((f"Over The Air ({CORE.address})", CORE.address))
|
||||
if default == "OTA":
|
||||
return CORE.address
|
||||
if show_mqtt and CONF_MQTT in CORE.config:
|
||||
options.append((f"MQTT ({CORE.config['mqtt'][CONF_BROKER]})", "MQTT"))
|
||||
if (
|
||||
show_mqtt
|
||||
and (mqtt_config := CORE.config.get(CONF_MQTT))
|
||||
and mqtt_logging_enabled(mqtt_config)
|
||||
):
|
||||
options.append((f"MQTT ({mqtt_config[CONF_BROKER]})", "MQTT"))
|
||||
if default == "OTA":
|
||||
return "MQTT"
|
||||
if default is not None:
|
||||
|
@ -106,6 +113,17 @@ def choose_upload_log_host(
|
|||
return choose_prompt(options, purpose=purpose)
|
||||
|
||||
|
||||
def mqtt_logging_enabled(mqtt_config):
|
||||
log_topic = mqtt_config[CONF_LOG_TOPIC]
|
||||
if log_topic is None:
|
||||
return False
|
||||
if CONF_TOPIC not in log_topic:
|
||||
return False
|
||||
if log_topic.get(CONF_LEVEL, None) == "NONE":
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def get_port_type(port):
|
||||
if port.startswith("/") or port.startswith("COM"):
|
||||
return "SERIAL"
|
||||
|
|
|
@ -7,6 +7,7 @@ import esphome.config_validation as cv
|
|||
from esphome.const import (
|
||||
CONF_AUTO_CLEAR_ENABLED,
|
||||
CONF_BUFFER_SIZE,
|
||||
CONF_GROUP,
|
||||
CONF_ID,
|
||||
CONF_LAMBDA,
|
||||
CONF_ON_IDLE,
|
||||
|
@ -23,9 +24,15 @@ from esphome.helpers import write_file_if_changed
|
|||
from . import defines as df, helpers, lv_validation as lvalid
|
||||
from .automation import disp_update, focused_widgets, update_to_code
|
||||
from .defines import add_define
|
||||
from .encoders import ENCODERS_CONFIG, encoders_to_code, initial_focus_to_code
|
||||
from .encoders import (
|
||||
ENCODERS_CONFIG,
|
||||
encoders_to_code,
|
||||
get_default_group,
|
||||
initial_focus_to_code,
|
||||
)
|
||||
from .gradient import GRADIENT_SCHEMA, gradients_to_code
|
||||
from .hello_world import get_hello_world
|
||||
from .keypads import KEYPADS_CONFIG, keypads_to_code
|
||||
from .lv_validation import lv_bool, lv_images_used
|
||||
from .lvcode import LvContext, LvglComponent, lvgl_static
|
||||
from .schemas import (
|
||||
|
@ -158,6 +165,13 @@ def multi_conf_validate(configs: list[dict]):
|
|||
display_list = [disp for disps in displays for disp in disps]
|
||||
if len(display_list) != len(set(display_list)):
|
||||
raise cv.Invalid("A display ID may be used in only one LVGL instance")
|
||||
for config in configs:
|
||||
for item in (df.CONF_ENCODERS, df.CONF_KEYPADS):
|
||||
for enc in config.get(item, ()):
|
||||
if CONF_GROUP not in enc:
|
||||
raise cv.Invalid(
|
||||
f"'{item}' must have an explicit group set when using multiple LVGL instances"
|
||||
)
|
||||
base_config = configs[0]
|
||||
for config in configs[1:]:
|
||||
for item in (
|
||||
|
@ -173,6 +187,7 @@ def multi_conf_validate(configs: list[dict]):
|
|||
|
||||
|
||||
def final_validation(configs):
|
||||
if len(configs) != 1:
|
||||
multi_conf_validate(configs)
|
||||
global_config = full_config.get()
|
||||
for config in configs:
|
||||
|
@ -275,6 +290,7 @@ async def to_code(configs):
|
|||
else:
|
||||
add_define("LV_FONT_DEFAULT", await lvalid.lv_font.process(default_font))
|
||||
cg.add(lvgl_static.esphome_lvgl_init())
|
||||
default_group = get_default_group(config_0)
|
||||
|
||||
for config in configs:
|
||||
frac = config[CONF_BUFFER_SIZE]
|
||||
|
@ -303,7 +319,8 @@ async def to_code(configs):
|
|||
lv_scr_act = get_scr_act(lv_component)
|
||||
async with LvContext():
|
||||
await touchscreens_to_code(lv_component, config)
|
||||
await encoders_to_code(lv_component, config)
|
||||
await encoders_to_code(lv_component, config, default_group)
|
||||
await keypads_to_code(lv_component, config, default_group)
|
||||
await theme_to_code(config)
|
||||
await styles_to_code(config)
|
||||
await gradients_to_code(config)
|
||||
|
@ -430,6 +447,7 @@ LVGL_SCHEMA = (
|
|||
cv.Optional(df.CONF_GRADIENTS): GRADIENT_SCHEMA,
|
||||
cv.Optional(df.CONF_TOUCHSCREENS, default=None): touchscreen_schema,
|
||||
cv.Optional(df.CONF_ENCODERS, default=None): ENCODERS_CONFIG,
|
||||
cv.Optional(df.CONF_KEYPADS, default=None): KEYPADS_CONFIG,
|
||||
cv.GenerateID(df.CONF_DEFAULT_GROUP): cv.declare_id(lv_group_t),
|
||||
cv.Optional(df.CONF_RESUME_ON_INPUT, default=True): cv.boolean,
|
||||
}
|
||||
|
|
|
@ -438,6 +438,7 @@ CONF_HEADER_MODE = "header_mode"
|
|||
CONF_HOME = "home"
|
||||
CONF_INITIAL_FOCUS = "initial_focus"
|
||||
CONF_KEY_CODE = "key_code"
|
||||
CONF_KEYPADS = "keypads"
|
||||
CONF_LAYOUT = "layout"
|
||||
CONF_LEFT_BUTTON = "left_button"
|
||||
CONF_LINE_WIDTH = "line_width"
|
||||
|
|
|
@ -17,7 +17,7 @@ from .defines import (
|
|||
from .helpers import lvgl_components_required, requires_component
|
||||
from .lvcode import lv, lv_add, lv_assign, lv_expr, lv_Pvariable
|
||||
from .schemas import ENCODER_SCHEMA
|
||||
from .types import lv_group_t, lv_indev_type_t
|
||||
from .types import lv_group_t, lv_indev_type_t, lv_key_t
|
||||
|
||||
ENCODERS_CONFIG = cv.ensure_list(
|
||||
ENCODER_SCHEMA.extend(
|
||||
|
@ -39,10 +39,13 @@ ENCODERS_CONFIG = cv.ensure_list(
|
|||
)
|
||||
|
||||
|
||||
async def encoders_to_code(var, config):
|
||||
default_group = lv_Pvariable(lv_group_t, config[CONF_DEFAULT_GROUP])
|
||||
lv_assign(default_group, lv_expr.group_create())
|
||||
lv.group_set_default(default_group)
|
||||
def get_default_group(config):
|
||||
default_group = cg.Pvariable(config[CONF_DEFAULT_GROUP], lv_expr.group_create())
|
||||
cg.add(lv.group_set_default(default_group))
|
||||
return default_group
|
||||
|
||||
|
||||
async def encoders_to_code(var, config, default_group):
|
||||
for enc_conf in config[CONF_ENCODERS]:
|
||||
lvgl_components_required.add("KEY_LISTENER")
|
||||
lpt = enc_conf[CONF_LONG_PRESS_TIME].total_milliseconds
|
||||
|
@ -54,14 +57,14 @@ async def encoders_to_code(var, config):
|
|||
if sensor_config := enc_conf.get(CONF_SENSOR):
|
||||
if isinstance(sensor_config, dict):
|
||||
b_sensor = await cg.get_variable(sensor_config[CONF_LEFT_BUTTON])
|
||||
cg.add(listener.set_left_button(b_sensor))
|
||||
cg.add(listener.add_button(b_sensor, lv_key_t.LV_KEY_LEFT))
|
||||
b_sensor = await cg.get_variable(sensor_config[CONF_RIGHT_BUTTON])
|
||||
cg.add(listener.set_right_button(b_sensor))
|
||||
cg.add(listener.add_button(b_sensor, lv_key_t.LV_KEY_RIGHT))
|
||||
else:
|
||||
sensor_config = await cg.get_variable(sensor_config)
|
||||
lv_add(listener.set_sensor(sensor_config))
|
||||
b_sensor = await cg.get_variable(enc_conf[CONF_ENTER_BUTTON])
|
||||
cg.add(listener.set_enter_button(b_sensor))
|
||||
cg.add(listener.add_button(b_sensor, lv_key_t.LV_KEY_ENTER))
|
||||
if group := enc_conf.get(CONF_GROUP):
|
||||
group = lv_Pvariable(lv_group_t, group)
|
||||
lv_assign(group, lv_expr.group_create())
|
||||
|
|
77
esphome/components/lvgl/keypads.py
Normal file
77
esphome/components/lvgl/keypads.py
Normal file
|
@ -0,0 +1,77 @@
|
|||
import esphome.codegen as cg
|
||||
from esphome.components.binary_sensor import BinarySensor
|
||||
import esphome.config_validation as cv
|
||||
from esphome.const import CONF_GROUP, CONF_ID
|
||||
|
||||
from .defines import (
|
||||
CONF_ENCODERS,
|
||||
CONF_INITIAL_FOCUS,
|
||||
CONF_KEYPADS,
|
||||
CONF_LONG_PRESS_REPEAT_TIME,
|
||||
CONF_LONG_PRESS_TIME,
|
||||
literal,
|
||||
)
|
||||
from .helpers import lvgl_components_required
|
||||
from .lvcode import lv, lv_assign, lv_expr, lv_Pvariable
|
||||
from .schemas import ENCODER_SCHEMA
|
||||
from .types import lv_group_t, lv_indev_type_t
|
||||
|
||||
KEYPAD_KEYS = (
|
||||
"up",
|
||||
"down",
|
||||
"right",
|
||||
"left",
|
||||
"esc",
|
||||
"del",
|
||||
"backspace",
|
||||
"enter",
|
||||
"next",
|
||||
"prev",
|
||||
"home",
|
||||
"end",
|
||||
"0",
|
||||
"1",
|
||||
"2",
|
||||
"3",
|
||||
"4",
|
||||
"5",
|
||||
"6",
|
||||
"7",
|
||||
"8",
|
||||
"9",
|
||||
"#",
|
||||
"*",
|
||||
)
|
||||
|
||||
KEYPADS_CONFIG = cv.ensure_list(
|
||||
ENCODER_SCHEMA.extend(
|
||||
{cv.Optional(key): cv.use_id(BinarySensor) for key in KEYPAD_KEYS}
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
async def keypads_to_code(var, config, default_group):
|
||||
for enc_conf in config[CONF_KEYPADS]:
|
||||
lvgl_components_required.add("KEY_LISTENER")
|
||||
lpt = enc_conf[CONF_LONG_PRESS_TIME].total_milliseconds
|
||||
lprt = enc_conf[CONF_LONG_PRESS_REPEAT_TIME].total_milliseconds
|
||||
listener = cg.new_Pvariable(
|
||||
enc_conf[CONF_ID], lv_indev_type_t.LV_INDEV_TYPE_KEYPAD, lpt, lprt
|
||||
)
|
||||
await cg.register_parented(listener, var)
|
||||
for key in [x for x in enc_conf if x in KEYPAD_KEYS]:
|
||||
b_sensor = await cg.get_variable(enc_conf[key])
|
||||
cg.add(listener.add_button(b_sensor, literal(f"LV_KEY_{key.upper()}")))
|
||||
if group := enc_conf.get(CONF_GROUP):
|
||||
group = lv_Pvariable(lv_group_t, group)
|
||||
lv_assign(group, lv_expr.group_create())
|
||||
else:
|
||||
group = default_group
|
||||
lv.indev_set_group(lv_expr.indev_drv_register(listener.get_drv()), group)
|
||||
|
||||
|
||||
async def initial_focus_to_code(config):
|
||||
for enc_conf in config[CONF_ENCODERS]:
|
||||
if default_focus := enc_conf.get(CONF_INITIAL_FOCUS):
|
||||
obj = await cg.get_variable(default_focus)
|
||||
lv.group_focus_obj(obj)
|
|
@ -256,15 +256,8 @@ class LVEncoderListener : public Parented<LvglComponent> {
|
|||
LVEncoderListener(lv_indev_type_t type, uint16_t lpt, uint16_t lprt);
|
||||
|
||||
#ifdef USE_BINARY_SENSOR
|
||||
void set_left_button(binary_sensor::BinarySensor *left_button) {
|
||||
left_button->add_on_state_callback([this](bool state) { this->event(LV_KEY_LEFT, state); });
|
||||
}
|
||||
void set_right_button(binary_sensor::BinarySensor *right_button) {
|
||||
right_button->add_on_state_callback([this](bool state) { this->event(LV_KEY_RIGHT, state); });
|
||||
}
|
||||
|
||||
void set_enter_button(binary_sensor::BinarySensor *enter_button) {
|
||||
enter_button->add_on_state_callback([this](bool state) { this->event(LV_KEY_ENTER, state); });
|
||||
void add_button(binary_sensor::BinarySensor *button, lv_key_t key) {
|
||||
button->add_on_state_callback([this, key](bool state) { this->event(key, state); });
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -40,6 +40,7 @@ void_ptr = cg.void.operator("ptr")
|
|||
lv_coord_t = cg.global_ns.namespace("lv_coord_t")
|
||||
lv_event_code_t = cg.global_ns.enum("lv_event_code_t")
|
||||
lv_indev_type_t = cg.global_ns.enum("lv_indev_type_t")
|
||||
lv_key_t = cg.global_ns.enum("lv_key_t")
|
||||
FontEngine = lvgl_ns.class_("FontEngine")
|
||||
IdleTrigger = lvgl_ns.class_("IdleTrigger", automation.Trigger.template())
|
||||
PauseTrigger = lvgl_ns.class_("PauseTrigger", automation.Trigger.template())
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
#include "esphome/core/log.h"
|
||||
#include "air_conditioner.h"
|
||||
#include "ac_adapter.h"
|
||||
#include <cmath>
|
||||
#include <cstdint>
|
||||
|
||||
namespace esphome {
|
||||
namespace midea {
|
||||
|
@ -121,7 +123,21 @@ void AirConditioner::dump_config() {
|
|||
|
||||
void AirConditioner::do_follow_me(float temperature, bool beeper) {
|
||||
#ifdef USE_REMOTE_TRANSMITTER
|
||||
IrFollowMeData data(static_cast<uint8_t>(lroundf(temperature)), beeper);
|
||||
// Check if temperature is finite (not NaN or infinite)
|
||||
if (!std::isfinite(temperature)) {
|
||||
ESP_LOGW(Constants::TAG, "Follow me action requires a finite temperature, got: %f", temperature);
|
||||
return;
|
||||
}
|
||||
|
||||
// Round and convert temperature to long, then clamp and convert it to uint8_t
|
||||
uint8_t temp_uint8 =
|
||||
static_cast<uint8_t>(std::max(0L, std::min(static_cast<long>(UINT8_MAX), std::lroundf(temperature))));
|
||||
|
||||
ESP_LOGD(Constants::TAG, "Follow me action called with temperature: %f °C, rounded to: %u °C", temperature,
|
||||
temp_uint8);
|
||||
|
||||
// Create and transmit the data
|
||||
IrFollowMeData data(temp_uint8, beeper);
|
||||
this->transmitter_.transmit(data);
|
||||
#else
|
||||
ESP_LOGW(Constants::TAG, "Action needs remote_transmitter component");
|
||||
|
|
|
@ -335,19 +335,28 @@ def sensor_schema(
|
|||
return SENSOR_SCHEMA.extend(schema)
|
||||
|
||||
|
||||
@FILTER_REGISTRY.register("offset", OffsetFilter, cv.float_)
|
||||
@FILTER_REGISTRY.register("offset", OffsetFilter, cv.templatable(cv.float_))
|
||||
async def offset_filter_to_code(config, filter_id):
|
||||
return cg.new_Pvariable(filter_id, config)
|
||||
template_ = await cg.templatable(config, [], float)
|
||||
return cg.new_Pvariable(filter_id, template_)
|
||||
|
||||
|
||||
@FILTER_REGISTRY.register("multiply", MultiplyFilter, cv.float_)
|
||||
@FILTER_REGISTRY.register("multiply", MultiplyFilter, cv.templatable(cv.float_))
|
||||
async def multiply_filter_to_code(config, filter_id):
|
||||
return cg.new_Pvariable(filter_id, config)
|
||||
template_ = await cg.templatable(config, [], float)
|
||||
return cg.new_Pvariable(filter_id, template_)
|
||||
|
||||
|
||||
@FILTER_REGISTRY.register("filter_out", FilterOutValueFilter, cv.float_)
|
||||
@FILTER_REGISTRY.register(
|
||||
"filter_out",
|
||||
FilterOutValueFilter,
|
||||
cv.Any(cv.templatable(cv.float_), [cv.templatable(cv.float_)]),
|
||||
)
|
||||
async def filter_out_filter_to_code(config, filter_id):
|
||||
return cg.new_Pvariable(filter_id, config)
|
||||
if not isinstance(config, list):
|
||||
config = [config]
|
||||
template_ = [await cg.templatable(x, [], float) for x in config]
|
||||
return cg.new_Pvariable(filter_id, template_)
|
||||
|
||||
|
||||
QUANTILE_SCHEMA = cv.All(
|
||||
|
@ -573,7 +582,7 @@ async def heartbeat_filter_to_code(config, filter_id):
|
|||
TIMEOUT_SCHEMA = cv.maybe_simple_value(
|
||||
{
|
||||
cv.Required(CONF_TIMEOUT): cv.positive_time_period_milliseconds,
|
||||
cv.Optional(CONF_VALUE, default="nan"): cv.float_,
|
||||
cv.Optional(CONF_VALUE, default="nan"): cv.templatable(cv.float_),
|
||||
},
|
||||
key=CONF_TIMEOUT,
|
||||
)
|
||||
|
@ -581,7 +590,8 @@ TIMEOUT_SCHEMA = cv.maybe_simple_value(
|
|||
|
||||
@FILTER_REGISTRY.register("timeout", TimeoutFilter, TIMEOUT_SCHEMA)
|
||||
async def timeout_filter_to_code(config, filter_id):
|
||||
var = cg.new_Pvariable(filter_id, config[CONF_TIMEOUT], config[CONF_VALUE])
|
||||
template_ = await cg.templatable(config[CONF_VALUE], [], float)
|
||||
var = cg.new_Pvariable(filter_id, config[CONF_TIMEOUT], template_)
|
||||
await cg.register_component(var, {})
|
||||
return var
|
||||
|
||||
|
|
|
@ -288,37 +288,37 @@ optional<float> LambdaFilter::new_value(float value) {
|
|||
}
|
||||
|
||||
// OffsetFilter
|
||||
OffsetFilter::OffsetFilter(float offset) : offset_(offset) {}
|
||||
OffsetFilter::OffsetFilter(TemplatableValue<float> offset) : offset_(std::move(offset)) {}
|
||||
|
||||
optional<float> OffsetFilter::new_value(float value) { return value + this->offset_; }
|
||||
optional<float> OffsetFilter::new_value(float value) { return value + this->offset_.value(); }
|
||||
|
||||
// MultiplyFilter
|
||||
MultiplyFilter::MultiplyFilter(float multiplier) : multiplier_(multiplier) {}
|
||||
MultiplyFilter::MultiplyFilter(TemplatableValue<float> multiplier) : multiplier_(std::move(multiplier)) {}
|
||||
|
||||
optional<float> MultiplyFilter::new_value(float value) { return value * this->multiplier_; }
|
||||
optional<float> MultiplyFilter::new_value(float value) { return value * this->multiplier_.value(); }
|
||||
|
||||
// FilterOutValueFilter
|
||||
FilterOutValueFilter::FilterOutValueFilter(float value_to_filter_out) : value_to_filter_out_(value_to_filter_out) {}
|
||||
FilterOutValueFilter::FilterOutValueFilter(std::vector<TemplatableValue<float>> values_to_filter_out)
|
||||
: values_to_filter_out_(std::move(values_to_filter_out)) {}
|
||||
|
||||
optional<float> FilterOutValueFilter::new_value(float value) {
|
||||
if (std::isnan(this->value_to_filter_out_)) {
|
||||
if (std::isnan(value)) {
|
||||
return {};
|
||||
} else {
|
||||
return value;
|
||||
}
|
||||
} else {
|
||||
int8_t accuracy = this->parent_->get_accuracy_decimals();
|
||||
float accuracy_mult = powf(10.0f, accuracy);
|
||||
float rounded_filter_out = roundf(accuracy_mult * this->value_to_filter_out_);
|
||||
for (auto filter_value : this->values_to_filter_out_) {
|
||||
if (std::isnan(filter_value.value())) {
|
||||
if (std::isnan(value)) {
|
||||
return {};
|
||||
}
|
||||
continue;
|
||||
}
|
||||
float rounded_filter_out = roundf(accuracy_mult * filter_value.value());
|
||||
float rounded_value = roundf(accuracy_mult * value);
|
||||
if (rounded_filter_out == rounded_value) {
|
||||
return {};
|
||||
} else {
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ThrottleFilter
|
||||
ThrottleFilter::ThrottleFilter(uint32_t min_time_between_inputs) : min_time_between_inputs_(min_time_between_inputs) {}
|
||||
|
@ -383,11 +383,12 @@ void OrFilter::initialize(Sensor *parent, Filter *next) {
|
|||
|
||||
// TimeoutFilter
|
||||
optional<float> TimeoutFilter::new_value(float value) {
|
||||
this->set_timeout("timeout", this->time_period_, [this]() { this->output(this->value_); });
|
||||
this->set_timeout("timeout", this->time_period_, [this]() { this->output(this->value_.value()); });
|
||||
return value;
|
||||
}
|
||||
|
||||
TimeoutFilter::TimeoutFilter(uint32_t time_period, float new_value) : time_period_(time_period), value_(new_value) {}
|
||||
TimeoutFilter::TimeoutFilter(uint32_t time_period, TemplatableValue<float> new_value)
|
||||
: time_period_(time_period), value_(std::move(new_value)) {}
|
||||
float TimeoutFilter::get_setup_priority() const { return setup_priority::HARDWARE; }
|
||||
|
||||
// DebounceFilter
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include <vector>
|
||||
#include "esphome/core/component.h"
|
||||
#include "esphome/core/helpers.h"
|
||||
#include "esphome/core/automation.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace sensor {
|
||||
|
@ -273,34 +274,33 @@ class LambdaFilter : public Filter {
|
|||
/// A simple filter that adds `offset` to each value it receives.
|
||||
class OffsetFilter : public Filter {
|
||||
public:
|
||||
explicit OffsetFilter(float offset);
|
||||
explicit OffsetFilter(TemplatableValue<float> offset);
|
||||
|
||||
optional<float> new_value(float value) override;
|
||||
|
||||
protected:
|
||||
float offset_;
|
||||
TemplatableValue<float> offset_;
|
||||
};
|
||||
|
||||
/// A simple filter that multiplies to each value it receives by `multiplier`.
|
||||
class MultiplyFilter : public Filter {
|
||||
public:
|
||||
explicit MultiplyFilter(float multiplier);
|
||||
|
||||
explicit MultiplyFilter(TemplatableValue<float> multiplier);
|
||||
optional<float> new_value(float value) override;
|
||||
|
||||
protected:
|
||||
float multiplier_;
|
||||
TemplatableValue<float> multiplier_;
|
||||
};
|
||||
|
||||
/// A simple filter that only forwards the filter chain if it doesn't receive `value_to_filter_out`.
|
||||
class FilterOutValueFilter : public Filter {
|
||||
public:
|
||||
explicit FilterOutValueFilter(float value_to_filter_out);
|
||||
explicit FilterOutValueFilter(std::vector<TemplatableValue<float>> values_to_filter_out);
|
||||
|
||||
optional<float> new_value(float value) override;
|
||||
|
||||
protected:
|
||||
float value_to_filter_out_;
|
||||
std::vector<TemplatableValue<float>> values_to_filter_out_;
|
||||
};
|
||||
|
||||
class ThrottleFilter : public Filter {
|
||||
|
@ -316,8 +316,7 @@ class ThrottleFilter : public Filter {
|
|||
|
||||
class TimeoutFilter : public Filter, public Component {
|
||||
public:
|
||||
explicit TimeoutFilter(uint32_t time_period, float new_value);
|
||||
void set_value(float new_value) { this->value_ = new_value; }
|
||||
explicit TimeoutFilter(uint32_t time_period, TemplatableValue<float> new_value);
|
||||
|
||||
optional<float> new_value(float value) override;
|
||||
|
||||
|
@ -325,7 +324,7 @@ class TimeoutFilter : public Filter, public Component {
|
|||
|
||||
protected:
|
||||
uint32_t time_period_;
|
||||
float value_;
|
||||
TemplatableValue<float> value_;
|
||||
};
|
||||
|
||||
class DebounceFilter : public Filter, public Component {
|
||||
|
|
|
@ -26,7 +26,7 @@ class MDNSStatus:
|
|||
self.host_mdns_state: dict[str, bool | None] = {}
|
||||
self._loop = asyncio.get_running_loop()
|
||||
|
||||
async def async_resolve_host(self, host_name: str) -> str | None:
|
||||
async def async_resolve_host(self, host_name: str) -> list[str] | None:
|
||||
"""Resolve a host name to an address in a thread-safe manner."""
|
||||
if aiozc := self.aiozc:
|
||||
return await aiozc.async_resolve_host(host_name)
|
||||
|
@ -50,13 +50,12 @@ class MDNSStatus:
|
|||
poll_names.setdefault(entry.name, set()).add(entry)
|
||||
elif (online := host_mdns_state.get(entry.name, SENTINEL)) != SENTINEL:
|
||||
entries.async_set_state(entry, bool_to_entry_state(online))
|
||||
|
||||
if poll_names and self.aiozc:
|
||||
results = await asyncio.gather(
|
||||
*(self.aiozc.async_resolve_host(name) for name in poll_names)
|
||||
)
|
||||
for name, address in zip(poll_names, results):
|
||||
result = bool(address)
|
||||
for name, address_list in zip(poll_names, results):
|
||||
result = bool(address_list)
|
||||
host_mdns_state[name] = result
|
||||
for entry in poll_names[name]:
|
||||
entries.async_set_state(entry, bool_to_entry_state(result))
|
||||
|
|
|
@ -320,12 +320,12 @@ class EsphomePortCommandWebSocket(EsphomeCommandWebSocket):
|
|||
and "api" in entry.loaded_integrations
|
||||
):
|
||||
if (mdns := dashboard.mdns_status) and (
|
||||
address := await mdns.async_resolve_host(entry.name)
|
||||
address_list := await mdns.async_resolve_host(entry.name)
|
||||
):
|
||||
# Use the IP address if available but only
|
||||
# if the API is loaded and the device is online
|
||||
# since MQTT logging will not work otherwise
|
||||
port = address
|
||||
port = address_list[0]
|
||||
elif (
|
||||
entry.address
|
||||
and (
|
||||
|
|
|
@ -176,7 +176,7 @@ def _make_host_resolver(host: str) -> HostResolver:
|
|||
|
||||
|
||||
class EsphomeZeroconf(Zeroconf):
|
||||
def resolve_host(self, host: str, timeout: float = 3.0) -> str | None:
|
||||
def resolve_host(self, host: str, timeout: float = 3.0) -> list[str] | None:
|
||||
"""Resolve a host name to an IP address."""
|
||||
info = _make_host_resolver(host)
|
||||
if (
|
||||
|
@ -188,7 +188,9 @@ class EsphomeZeroconf(Zeroconf):
|
|||
|
||||
|
||||
class AsyncEsphomeZeroconf(AsyncZeroconf):
|
||||
async def async_resolve_host(self, host: str, timeout: float = 3.0) -> str | None:
|
||||
async def async_resolve_host(
|
||||
self, host: str, timeout: float = 3.0
|
||||
) -> list[str] | None:
|
||||
"""Resolve a host name to an IP address."""
|
||||
info = _make_host_resolver(host)
|
||||
if (
|
||||
|
|
|
@ -11,6 +11,12 @@ substitutions:
|
|||
check: "\U000F012C"
|
||||
arrow_down: "\U000F004B"
|
||||
|
||||
binary_sensor:
|
||||
- id: enter_sensor
|
||||
platform: template
|
||||
- id: left_sensor
|
||||
platform: template
|
||||
|
||||
lvgl:
|
||||
log_level: debug
|
||||
resume_on_input: true
|
||||
|
@ -93,6 +99,10 @@ lvgl:
|
|||
- touchscreen_id: tft_touch
|
||||
long_press_repeat_time: 200ms
|
||||
long_press_time: 500ms
|
||||
keypads:
|
||||
- initial_focus: button_button
|
||||
enter: enter_sensor
|
||||
next: left_sensor
|
||||
|
||||
msgboxes:
|
||||
- id: message_box
|
||||
|
|
|
@ -9,6 +9,25 @@ sensor:
|
|||
return 0.0;
|
||||
}
|
||||
update_interval: 60s
|
||||
filters:
|
||||
- offset: 10
|
||||
- multiply: 1
|
||||
- offset: !lambda return 10;
|
||||
- multiply: !lambda return 2;
|
||||
- filter_out:
|
||||
- 10
|
||||
- 20
|
||||
- !lambda return 10;
|
||||
- filter_out: 10
|
||||
- filter_out: !lambda return NAN;
|
||||
- timeout:
|
||||
timeout: 10s
|
||||
value: !lambda return 10;
|
||||
- timeout:
|
||||
timeout: 1h
|
||||
value: 20.0
|
||||
- timeout:
|
||||
timeout: 1d
|
||||
|
||||
esphome:
|
||||
on_boot:
|
||||
|
|
Loading…
Reference in a new issue