mirror of
https://github.com/esphome/esphome.git
synced 2026-10-22 13:56:10 +00:00
Compare commits
26
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9bc9fc1b9b | ||
|
|
90cf7abbde | ||
|
|
b8a0de91db | ||
|
|
fb54defeda | ||
|
|
e2d37f0d7e | ||
|
|
2937d81216 | ||
|
|
9d59415766 | ||
|
|
29ef01a207 | ||
|
|
05a4b256db | ||
|
|
e8e98ee3db | ||
|
|
6aa647638c | ||
|
|
d0427c36eb | ||
|
|
e2c2fdfb3d | ||
|
|
7425b8d3b1 | ||
|
|
5f697bb0d6 | ||
|
|
8f79467d5f | ||
|
|
5ca927da8e | ||
|
|
776a7f68d8 | ||
|
|
87de7d679e | ||
|
|
e75a10ec7d | ||
|
|
f0ea8edfad | ||
|
|
5df5d44516 | ||
|
|
dd59a827ff | ||
|
|
ed9b566091 | ||
|
|
5fd7c33916 | ||
|
|
a990231342 |
+11
-3
@@ -426,12 +426,20 @@ def _apply_function(
|
||||
) -> MockObj:
|
||||
"""Emit the generated function and declare ``id_`` as the ``ApplyAction`` or
|
||||
``ApplyCondition`` templated on it, so ``play()`` calls it directly."""
|
||||
fn = cg.static_function(
|
||||
f"esphome__{id_.id}__fn", return_type, lambda_args, statements
|
||||
)
|
||||
fn = apply_static_function(id_, return_type, lambda_args, statements)
|
||||
return cg.new_Pvariable(id_, cg.TemplateArguments(fn, *template_arg))
|
||||
|
||||
|
||||
def apply_static_function(
|
||||
id_: ID,
|
||||
return_type: SafeExpType,
|
||||
params: TemplateArgsType,
|
||||
statements: list[str],
|
||||
) -> MockObj:
|
||||
"""Emit the static function generated for ``id_`` and return an expression naming it."""
|
||||
return cg.static_function(f"esphome__{id_.id}__fn", return_type, params, statements)
|
||||
|
||||
|
||||
async def _render_values(
|
||||
name: str,
|
||||
target: str,
|
||||
|
||||
@@ -4,14 +4,13 @@ import esphome.config_validation as cv
|
||||
from esphome.const import DEVICE_CLASS_SWITCH, ICON_WIFI
|
||||
from esphome.types import ConfigType
|
||||
|
||||
from .. import CONF_AT581X_ID, AT581XComponent, at581x_ns
|
||||
from .. import CONF_AT581X_ID, AT581XComponent
|
||||
|
||||
DEPENDENCIES = ["at581x"]
|
||||
|
||||
RFSwitch = at581x_ns.class_("RFSwitch", switch.Switch)
|
||||
|
||||
CONFIG_SCHEMA = switch.switch_schema(
|
||||
RFSwitch,
|
||||
switch.ApplySwitch,
|
||||
device_class=DEVICE_CLASS_SWITCH,
|
||||
icon=ICON_WIFI,
|
||||
).extend(
|
||||
@@ -24,7 +23,7 @@ CONFIG_SCHEMA = switch.switch_schema(
|
||||
|
||||
|
||||
async def to_code(config: ConfigType) -> None:
|
||||
at581x_component = await cg.get_variable(config[CONF_AT581X_ID])
|
||||
s = await switch.new_switch(config)
|
||||
await cg.register_parented(s, config[CONF_AT581X_ID])
|
||||
cg.add(at581x_component.set_rf_power_switch(s))
|
||||
hub = await cg.get_variable(config[CONF_AT581X_ID])
|
||||
await switch.sub_switches(config, parent=hub).create(
|
||||
config, hub.set_rf_power_switch, apply="set_rf_mode(state)", publish="before"
|
||||
)
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
#include "rf_switch.h"
|
||||
|
||||
namespace esphome::at581x {
|
||||
|
||||
void RFSwitch::write_state(bool state) {
|
||||
this->publish_state(state);
|
||||
this->parent_->set_rf_mode(state);
|
||||
}
|
||||
|
||||
} // namespace esphome::at581x
|
||||
@@ -1,13 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/components/switch/switch.h"
|
||||
#include "../at581x.h"
|
||||
|
||||
namespace esphome::at581x {
|
||||
|
||||
class RFSwitch final : public switch_::Switch, public Parented<AT581XComponent> {
|
||||
protected:
|
||||
void write_state(bool state) override;
|
||||
};
|
||||
|
||||
} // namespace esphome::at581x
|
||||
@@ -1,25 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/core/defines.h"
|
||||
#ifdef USE_BUTTON
|
||||
|
||||
#include "bq25186.h"
|
||||
#include "esphome/components/button/button.h"
|
||||
|
||||
namespace esphome::bq25186 {
|
||||
|
||||
/// Writes one SHIP_RST field when pressed
|
||||
class BQ25186Button final : public button::Button, public Parented<BQ25186Component> {
|
||||
public:
|
||||
BQ25186Button(uint8_t mask, uint8_t value) : mask_(mask), value_(value) {}
|
||||
|
||||
protected:
|
||||
void press_action() override { this->parent_->write_ship_rst(this->mask_, this->value_); }
|
||||
|
||||
const uint8_t mask_;
|
||||
const uint8_t value_;
|
||||
};
|
||||
|
||||
} // namespace esphome::bq25186
|
||||
|
||||
#endif // USE_BUTTON
|
||||
@@ -1,4 +1,3 @@
|
||||
import esphome.codegen as cg
|
||||
from esphome.components import button
|
||||
import esphome.config_validation as cv
|
||||
from esphome.const import (
|
||||
@@ -10,11 +9,10 @@ from esphome.const import (
|
||||
)
|
||||
from esphome.types import ConfigType
|
||||
|
||||
from . import BQ25186_CHILD_SCHEMA, CONF_BQ25186_ID, bq25186_ns
|
||||
from . import BQ25186_CHILD_SCHEMA, CONF_BQ25186_ID
|
||||
|
||||
DEPENDENCIES = ["bq25186"]
|
||||
|
||||
BQ25186Button = bq25186_ns.class_("BQ25186Button", button.Button)
|
||||
|
||||
# SHIP_RST: bit 7 is the software reset, bits 6:5 the shutdown, ship and hardware reset codes
|
||||
SOFTWARE_RESET_MASK = 0x80
|
||||
@@ -33,7 +31,7 @@ CONFIG_SCHEMA = cv.All(
|
||||
BQ25186_CHILD_SCHEMA.extend(
|
||||
{
|
||||
cv.Optional(key): button.button_schema(
|
||||
BQ25186Button,
|
||||
button.ApplyButton,
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
icon=icon,
|
||||
device_class=device_class,
|
||||
@@ -46,7 +44,6 @@ CONFIG_SCHEMA = cv.All(
|
||||
|
||||
|
||||
async def to_code(config: ConfigType) -> None:
|
||||
buttons = button.sub_buttons(config, parent=config[CONF_BQ25186_ID])
|
||||
for key, mask, value, _, _ in _BUTTONS:
|
||||
if (conf := config.get(key)) is not None:
|
||||
var = await button.new_button(conf, mask, value)
|
||||
await cg.register_parented(var, config[CONF_BQ25186_ID])
|
||||
await buttons(key, None, apply=f"write_ship_rst({mask:#04x}, {value:#04x})")
|
||||
|
||||
@@ -18,6 +18,7 @@ from esphome.const import (
|
||||
)
|
||||
from esphome.core import CORE, ID, CoroPriority, coroutine_with_priority
|
||||
from esphome.core.entity_helpers import (
|
||||
ApplyEntity,
|
||||
SubEntities,
|
||||
entity_duplicate_validator,
|
||||
queue_entity_register,
|
||||
@@ -41,6 +42,7 @@ DEVICE_CLASSES = [
|
||||
button_ns = cg.esphome_ns.namespace("button")
|
||||
Button = button_ns.class_("Button", cg.EntityBase)
|
||||
ButtonPtr = Button.operator("ptr")
|
||||
ApplyButton = button_ns.class_("ApplyButton", Button)
|
||||
|
||||
validate_device_class = cv.one_of(*DEVICE_CLASSES, lower=True, space="_")
|
||||
|
||||
@@ -116,11 +118,14 @@ async def new_button(config: ConfigType, *args: SafeExpType) -> MockObj:
|
||||
return var
|
||||
|
||||
|
||||
APPLY_ENTITY = ApplyEntity(ApplyButton, ((ButtonPtr, "entity"),))
|
||||
|
||||
|
||||
def sub_buttons(
|
||||
config: ConfigType, *, parent: MockObj | ID | None = None
|
||||
) -> SubEntities:
|
||||
"""Return a SubEntities bound to new_button."""
|
||||
return SubEntities(new_button, config, parent)
|
||||
"""Return a SubEntities bound to new_button; ``apply`` statements can use ``entity``."""
|
||||
return SubEntities(new_button, config, parent, APPLY_ENTITY)
|
||||
|
||||
|
||||
BUTTON_PRESS_SCHEMA = maybe_simple_id(
|
||||
|
||||
@@ -46,4 +46,14 @@ class Button : public EntityBase {
|
||||
LazyCallbackManager<void()> press_callback_{};
|
||||
};
|
||||
|
||||
/// Calls the codegen-generated Fn(this) on a press; the hub and any publish are baked into Fn.
|
||||
template<auto Fn> class ApplyButton final : public Button {
|
||||
public:
|
||||
// Not "= default": placement new would zero-fill .bss that is already zero.
|
||||
ApplyButton() {}
|
||||
|
||||
protected:
|
||||
void press_action() override { Fn(this); }
|
||||
};
|
||||
|
||||
} // namespace esphome::button
|
||||
|
||||
@@ -28,14 +28,12 @@ ADC_INPUT_MIC_OPTIONS = {
|
||||
}
|
||||
ADC_INPUT_MIC_OPTION_NAMES = list(ADC_INPUT_MIC_OPTIONS)
|
||||
|
||||
DacOutputSelect = es8388_ns.class_("DacOutputSelect", select.Select)
|
||||
ADCInputMicSelect = es8388_ns.class_("ADCInputMicSelect", select.Select)
|
||||
|
||||
CONFIG_SCHEMA = cv.All(
|
||||
{
|
||||
cv.GenerateID(CONF_ES8388_ID): cv.use_id(ES8388),
|
||||
cv.Optional(CONF_DAC_OUTPUT): select.select_schema(
|
||||
DacOutputSelect,
|
||||
select.ApplySelect,
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
icon=ICON_CHIP,
|
||||
).extend(
|
||||
@@ -46,7 +44,7 @@ CONFIG_SCHEMA = cv.All(
|
||||
}
|
||||
),
|
||||
cv.Optional(CONF_ADC_INPUT_MIC): select.select_schema(
|
||||
ADCInputMicSelect,
|
||||
select.ApplySelect,
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
icon=ICON_CHIP,
|
||||
).extend(
|
||||
@@ -65,12 +63,18 @@ async def to_code(config: ConfigType) -> None:
|
||||
hub = await cg.get_variable(config[CONF_ES8388_ID])
|
||||
selects = select.sub_selects(config, parent=hub)
|
||||
await selects(
|
||||
CONF_DAC_OUTPUT, hub.set_dac_output_select, options=DAC_OUTPUT_OPTION_NAMES
|
||||
CONF_DAC_OUTPUT,
|
||||
hub.set_dac_output_select,
|
||||
options=DAC_OUTPUT_OPTION_NAMES,
|
||||
apply="set_dac_output(static_cast<es8388::DacOutputLine>(index))",
|
||||
publish="before",
|
||||
)
|
||||
await selects(
|
||||
CONF_ADC_INPUT_MIC,
|
||||
hub.set_adc_input_mic_select,
|
||||
options=ADC_INPUT_MIC_OPTION_NAMES,
|
||||
apply="set_adc_input_mic(static_cast<es8388::AdcInputMicLine>(index))",
|
||||
publish="before",
|
||||
)
|
||||
if (
|
||||
initial := config.get(CONF_DAC_OUTPUT, {}).get(CONF_INITIAL_OPTION)
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
#include "adc_input_mic_select.h"
|
||||
|
||||
namespace esphome::es8388 {
|
||||
|
||||
void ADCInputMicSelect::control(size_t index) {
|
||||
this->publish_state(index);
|
||||
this->parent_->set_adc_input_mic(static_cast<AdcInputMicLine>(index));
|
||||
}
|
||||
|
||||
} // namespace esphome::es8388
|
||||
@@ -1,13 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/components/es8388/es8388.h"
|
||||
#include "esphome/components/select/select.h"
|
||||
|
||||
namespace esphome::es8388 {
|
||||
|
||||
class ADCInputMicSelect final : public select::Select, public Parented<ES8388> {
|
||||
protected:
|
||||
void control(size_t index) override;
|
||||
};
|
||||
|
||||
} // namespace esphome::es8388
|
||||
@@ -1,10 +0,0 @@
|
||||
#include "dac_output_select.h"
|
||||
|
||||
namespace esphome::es8388 {
|
||||
|
||||
void DacOutputSelect::control(size_t index) {
|
||||
this->publish_state(index);
|
||||
this->parent_->set_dac_output(static_cast<DacOutputLine>(index));
|
||||
}
|
||||
|
||||
} // namespace esphome::es8388
|
||||
@@ -1,13 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/components/es8388/es8388.h"
|
||||
#include "esphome/components/select/select.h"
|
||||
|
||||
namespace esphome::es8388 {
|
||||
|
||||
class DacOutputSelect final : public select::Select, public Parented<ES8388> {
|
||||
protected:
|
||||
void control(size_t index) override;
|
||||
};
|
||||
|
||||
} // namespace esphome::es8388
|
||||
@@ -1,20 +1,18 @@
|
||||
import esphome.codegen as cg
|
||||
from esphome.components import button
|
||||
import esphome.config_validation as cv
|
||||
from esphome.const import ENTITY_CATEGORY_CONFIG
|
||||
from esphome.types import ConfigType
|
||||
|
||||
from .. import CONF_ESPECTRE_ID, ESPectreComponent, espectre_ns
|
||||
from .. import CONF_ESPECTRE_ID, ESPectreComponent
|
||||
|
||||
DEPENDENCIES = ["espectre"]
|
||||
|
||||
RecalibrateButton = espectre_ns.class_("RecalibrateButton", button.Button)
|
||||
|
||||
CONFIG_SCHEMA = button.button_schema(
|
||||
RecalibrateButton, entity_category=ENTITY_CATEGORY_CONFIG
|
||||
button.ApplyButton, entity_category=ENTITY_CATEGORY_CONFIG
|
||||
).extend({cv.GenerateID(CONF_ESPECTRE_ID): cv.use_id(ESPectreComponent)})
|
||||
|
||||
|
||||
async def to_code(config: ConfigType) -> None:
|
||||
var = await button.new_button(config)
|
||||
await cg.register_parented(var, config[CONF_ESPECTRE_ID])
|
||||
buttons = button.sub_buttons(config, parent=config[CONF_ESPECTRE_ID])
|
||||
await buttons.create(config, None, apply="recalibrate()")
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/core/defines.h"
|
||||
|
||||
#ifdef USE_ESPECTRE
|
||||
|
||||
#include "esphome/components/button/button.h"
|
||||
#include "../espectre.h"
|
||||
|
||||
namespace esphome::espectre {
|
||||
|
||||
class RecalibrateButton final : public button::Button, public Parented<ESPectreComponent> {
|
||||
protected:
|
||||
void press_action() override { this->parent_->recalibrate(); }
|
||||
};
|
||||
|
||||
} // namespace esphome::espectre
|
||||
|
||||
#endif // USE_ESPECTRE
|
||||
@@ -9,24 +9,23 @@ from .. import (
|
||||
CONF_ESPECTRE_ID,
|
||||
DOMAIN,
|
||||
ESPectreComponent,
|
||||
espectre_ns,
|
||||
supported_traffic_generator_modes,
|
||||
)
|
||||
|
||||
DEPENDENCIES = ["espectre"]
|
||||
|
||||
TrafficModeSelect = espectre_ns.class_(
|
||||
"TrafficModeSelect", select.Select, cg.Parented.template(ESPectreComponent)
|
||||
)
|
||||
|
||||
CONFIG_SCHEMA = select.select_schema(
|
||||
TrafficModeSelect, entity_category=ENTITY_CATEGORY_CONFIG
|
||||
select.ApplySelect, entity_category=ENTITY_CATEGORY_CONFIG
|
||||
).extend({cv.GenerateID(CONF_ESPECTRE_ID): cv.use_id(ESPectreComponent)})
|
||||
|
||||
|
||||
async def to_code(config: ConfigType) -> None:
|
||||
options = supported_traffic_generator_modes(CORE.config[DOMAIN])
|
||||
var = await select.new_select(config, options=options)
|
||||
await cg.register_parented(var, config[CONF_ESPECTRE_ID])
|
||||
parent = await cg.get_variable(config[CONF_ESPECTRE_ID])
|
||||
cg.add(parent.set_traffic_mode_select(var))
|
||||
hub = await cg.get_variable(config[CONF_ESPECTRE_ID])
|
||||
await select.sub_selects(config, parent=hub).create(
|
||||
config,
|
||||
hub.set_traffic_mode_select,
|
||||
options=options,
|
||||
apply="request_traffic_generator_mode(entity->option_at(index))",
|
||||
)
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
#include "espectre_select.h"
|
||||
|
||||
#ifdef USE_ESPECTRE
|
||||
|
||||
namespace esphome::espectre {
|
||||
|
||||
void TrafficModeSelect::control(size_t index) { this->parent_->request_traffic_generator_mode(this->option_at(index)); }
|
||||
|
||||
} // namespace esphome::espectre
|
||||
|
||||
#endif // USE_ESPECTRE
|
||||
@@ -1,19 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/core/defines.h"
|
||||
|
||||
#ifdef USE_ESPECTRE
|
||||
|
||||
#include "esphome/components/select/select.h"
|
||||
#include "../espectre.h"
|
||||
|
||||
namespace esphome::espectre {
|
||||
|
||||
class TrafficModeSelect final : public select::Select, public Parented<ESPectreComponent> {
|
||||
protected:
|
||||
void control(size_t index) override;
|
||||
};
|
||||
|
||||
} // namespace esphome::espectre
|
||||
|
||||
#endif // USE_ESPECTRE
|
||||
@@ -1,12 +1,10 @@
|
||||
import esphome.codegen as cg
|
||||
from esphome.components import button
|
||||
import esphome.config_validation as cv
|
||||
from esphome.types import ConfigType
|
||||
|
||||
from ..climate import CONF_HAIER_ID, HonClimate, haier_ns
|
||||
from ..climate import CONF_HAIER_ID, HonClimate
|
||||
|
||||
CODEOWNERS = ["@paveldn"]
|
||||
SelfCleaningButton = haier_ns.class_("SelfCleaningButton", button.Button)
|
||||
SteriCleaningButton = haier_ns.class_("SteriCleaningButton", button.Button)
|
||||
|
||||
|
||||
# Haier buttons
|
||||
@@ -20,19 +18,18 @@ CONFIG_SCHEMA = cv.Schema(
|
||||
{
|
||||
cv.GenerateID(CONF_HAIER_ID): cv.use_id(HonClimate),
|
||||
cv.Optional(CONF_SELF_CLEANING): button.button_schema(
|
||||
SelfCleaningButton,
|
||||
button.ApplyButton,
|
||||
icon=ICON_SPRAY_BOTTLE,
|
||||
),
|
||||
cv.Optional(CONF_STERI_CLEANING): button.button_schema(
|
||||
SteriCleaningButton,
|
||||
button.ApplyButton,
|
||||
icon=ICON_SPRAY_BOTTLE,
|
||||
),
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
async def to_code(config):
|
||||
for button_type in [CONF_SELF_CLEANING, CONF_STERI_CLEANING]:
|
||||
if conf := config.get(button_type):
|
||||
btn = await button.new_button(conf)
|
||||
await cg.register_parented(btn, config[CONF_HAIER_ID])
|
||||
async def to_code(config: ConfigType) -> None:
|
||||
buttons = button.sub_buttons(config, parent=config[CONF_HAIER_ID])
|
||||
await buttons(CONF_SELF_CLEANING, None, apply="start_self_cleaning()")
|
||||
await buttons(CONF_STERI_CLEANING, None, apply="start_steri_cleaning()")
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
#include "self_cleaning.h"
|
||||
|
||||
namespace esphome::haier {
|
||||
|
||||
void SelfCleaningButton::press_action() { this->parent_->start_self_cleaning(); }
|
||||
|
||||
} // namespace esphome::haier
|
||||
@@ -1,16 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/components/button/button.h"
|
||||
#include "../hon_climate.h"
|
||||
|
||||
namespace esphome::haier {
|
||||
|
||||
class SelfCleaningButton final : public button::Button, public Parented<HonClimate> {
|
||||
public:
|
||||
SelfCleaningButton() = default;
|
||||
|
||||
protected:
|
||||
void press_action() override;
|
||||
};
|
||||
|
||||
} // namespace esphome::haier
|
||||
@@ -1,7 +0,0 @@
|
||||
#include "steri_cleaning.h"
|
||||
|
||||
namespace esphome::haier {
|
||||
|
||||
void SteriCleaningButton::press_action() { this->parent_->start_steri_cleaning(); }
|
||||
|
||||
} // namespace esphome::haier
|
||||
@@ -1,16 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/components/button/button.h"
|
||||
#include "../hon_climate.h"
|
||||
|
||||
namespace esphome::haier {
|
||||
|
||||
class SteriCleaningButton final : public button::Button, public Parented<HonClimate> {
|
||||
public:
|
||||
SteriCleaningButton() = default;
|
||||
|
||||
protected:
|
||||
void press_action() override;
|
||||
};
|
||||
|
||||
} // namespace esphome::haier
|
||||
@@ -9,12 +9,9 @@ from ..climate import (
|
||||
CONF_HORIZONTAL_AIRFLOW,
|
||||
CONF_VERTICAL_AIRFLOW,
|
||||
HonClimate,
|
||||
haier_ns,
|
||||
)
|
||||
|
||||
CODEOWNERS = ["@paveldn"]
|
||||
VerticalAirflowSelect = haier_ns.class_("VerticalAirflowSelect", select.Select)
|
||||
HorizontalAirflowSelect = haier_ns.class_("HorizontalAirflowSelect", select.Select)
|
||||
|
||||
# Same order as VERTICAL_SWING_MODES_ORDER and HORIZONTAL_SWING_MODES_ORDER in hon_climate.h
|
||||
AIRFLOW_VERTICAL_DIRECTION_OPTIONS = [
|
||||
@@ -39,12 +36,12 @@ CONFIG_SCHEMA = cv.Schema(
|
||||
{
|
||||
cv.GenerateID(CONF_HAIER_ID): cv.use_id(HonClimate),
|
||||
cv.Optional(CONF_VERTICAL_AIRFLOW): select.select_schema(
|
||||
VerticalAirflowSelect,
|
||||
select.ApplySelect,
|
||||
icon="mdi:arrow-expand-vertical",
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
),
|
||||
cv.Optional(CONF_HORIZONTAL_AIRFLOW): select.select_schema(
|
||||
HorizontalAirflowSelect,
|
||||
select.ApplySelect,
|
||||
icon="mdi:arrow-expand-horizontal",
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
),
|
||||
@@ -59,9 +56,13 @@ async def to_code(config: ConfigType) -> None:
|
||||
CONF_VERTICAL_AIRFLOW,
|
||||
hub.set_vertical_airflow_select,
|
||||
options=AIRFLOW_VERTICAL_DIRECTION_OPTIONS,
|
||||
apply="set_vertical_airflow("
|
||||
"haier::airflow_order_at(haier::VERTICAL_SWING_MODES_ORDER, index))",
|
||||
)
|
||||
await selects(
|
||||
CONF_HORIZONTAL_AIRFLOW,
|
||||
hub.set_horizontal_airflow_select,
|
||||
options=AIRFLOW_HORIZONTAL_DIRECTION_OPTIONS,
|
||||
apply="set_horizontal_airflow("
|
||||
"haier::airflow_order_at(haier::HORIZONTAL_SWING_MODES_ORDER, index))",
|
||||
)
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/components/select/select.h"
|
||||
#include "../hon_climate.h"
|
||||
|
||||
namespace esphome::haier {
|
||||
|
||||
class HorizontalAirflowSelect : public select::Select, public Parented<HonClimate> {
|
||||
protected:
|
||||
void control(size_t index) override {
|
||||
this->parent_->set_horizontal_airflow(airflow_order_at(HORIZONTAL_SWING_MODES_ORDER, index));
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace esphome::haier
|
||||
@@ -1,15 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/components/select/select.h"
|
||||
#include "../hon_climate.h"
|
||||
|
||||
namespace esphome::haier {
|
||||
|
||||
class VerticalAirflowSelect : public select::Select, public Parented<HonClimate> {
|
||||
protected:
|
||||
void control(size_t index) override {
|
||||
this->parent_->set_vertical_airflow(airflow_order_at(VERTICAL_SWING_MODES_ORDER, index));
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace esphome::haier
|
||||
@@ -1,10 +1,9 @@
|
||||
import esphome.codegen as cg
|
||||
from esphome.components import button
|
||||
import esphome.config_validation as cv
|
||||
from esphome.const import ICON_AIR_FILTER
|
||||
from esphome.types import ConfigType
|
||||
|
||||
from .. import CONF_HOERMANN_HCP_ID, HoermannHcp, hoermann_hcp_ns
|
||||
from .. import CONF_HOERMANN_HCP_ID, HoermannHcp
|
||||
|
||||
DEPENDENCIES = ["hoermann_hcp"]
|
||||
|
||||
@@ -13,10 +12,6 @@ CONF_VENT = "vent"
|
||||
|
||||
ICON_GARAGE_OPEN_VARIANT = "mdi:garage-open-variant"
|
||||
|
||||
HoermannHcpVentButton = hoermann_hcp_ns.class_("HoermannHcpVentButton", button.Button)
|
||||
HoermannHcpHalfOpenButton = hoermann_hcp_ns.class_(
|
||||
"HoermannHcpHalfOpenButton", button.Button
|
||||
)
|
||||
|
||||
BUTTON_KEYS = (CONF_VENT, CONF_HALF_OPEN)
|
||||
|
||||
@@ -25,10 +20,10 @@ CONFIG_SCHEMA = cv.All(
|
||||
{
|
||||
cv.GenerateID(CONF_HOERMANN_HCP_ID): cv.use_id(HoermannHcp),
|
||||
cv.Optional(CONF_VENT): button.button_schema(
|
||||
HoermannHcpVentButton, icon=ICON_AIR_FILTER
|
||||
button.ApplyButton, icon=ICON_AIR_FILTER
|
||||
),
|
||||
cv.Optional(CONF_HALF_OPEN): button.button_schema(
|
||||
HoermannHcpHalfOpenButton, icon=ICON_GARAGE_OPEN_VARIANT
|
||||
button.ApplyButton, icon=ICON_GARAGE_OPEN_VARIANT
|
||||
),
|
||||
}
|
||||
),
|
||||
@@ -37,7 +32,6 @@ CONFIG_SCHEMA = cv.All(
|
||||
|
||||
|
||||
async def to_code(config: ConfigType) -> None:
|
||||
parent = await cg.get_variable(config[CONF_HOERMANN_HCP_ID])
|
||||
for key in BUTTON_KEYS:
|
||||
if (conf := config.get(key)) is not None:
|
||||
await button.new_button(conf, parent)
|
||||
buttons = button.sub_buttons(config, parent=config[CONF_HOERMANN_HCP_ID])
|
||||
await buttons(CONF_VENT, None, apply="vent_door()")
|
||||
await buttons(CONF_HALF_OPEN, None, apply="half_open_door()")
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/components/button/button.h"
|
||||
#include "../hoermann_hcp.h"
|
||||
|
||||
namespace esphome::hoermann_hcp {
|
||||
|
||||
// The door commands the cover has no equivalent for. A refused command is already reported by the hub and
|
||||
// leaves nothing to correct here, because a button carries no state of its own.
|
||||
class HoermannHcpButton : public button::Button {
|
||||
public:
|
||||
explicit HoermannHcpButton(HoermannHcp *parent) : parent_(parent) {}
|
||||
|
||||
protected:
|
||||
HoermannHcp *const parent_;
|
||||
};
|
||||
|
||||
class HoermannHcpVentButton final : public HoermannHcpButton {
|
||||
public:
|
||||
using HoermannHcpButton::HoermannHcpButton;
|
||||
|
||||
protected:
|
||||
void press_action() override { this->parent_->vent_door(); }
|
||||
};
|
||||
|
||||
class HoermannHcpHalfOpenButton final : public HoermannHcpButton {
|
||||
public:
|
||||
using HoermannHcpButton::HoermannHcpButton;
|
||||
|
||||
protected:
|
||||
void press_action() override { this->parent_->half_open_door(); }
|
||||
};
|
||||
|
||||
} // namespace esphome::hoermann_hcp
|
||||
@@ -15,29 +15,25 @@ from esphome.const import (
|
||||
)
|
||||
from esphome.types import ConfigType
|
||||
|
||||
from .. import CONF_LD2410_ID, LD2410Component, ld2410_ns
|
||||
|
||||
FactoryResetButton = ld2410_ns.class_("FactoryResetButton", button.Button)
|
||||
QueryButton = ld2410_ns.class_("QueryButton", button.Button)
|
||||
RestartButton = ld2410_ns.class_("RestartButton", button.Button)
|
||||
from .. import CONF_LD2410_ID, LD2410Component
|
||||
|
||||
CONFIG_SCHEMA = {
|
||||
cv.GenerateID(CONF_ID): cv.declare_id(cg.EntityBase),
|
||||
cv.GenerateID(CONF_LD2410_ID): cv.use_id(LD2410Component),
|
||||
cv.Optional(CONF_FACTORY_RESET): button.button_schema(
|
||||
FactoryResetButton,
|
||||
button.ApplyButton,
|
||||
device_class=DEVICE_CLASS_RESTART,
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
icon=ICON_RESTART_ALERT,
|
||||
),
|
||||
cv.Optional(CONF_RESTART): button.button_schema(
|
||||
RestartButton,
|
||||
button.ApplyButton,
|
||||
device_class=DEVICE_CLASS_RESTART,
|
||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
icon=ICON_RESTART,
|
||||
),
|
||||
cv.Optional(CONF_QUERY_PARAMS): button.button_schema(
|
||||
QueryButton,
|
||||
button.ApplyButton,
|
||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
icon=ICON_DATABASE,
|
||||
),
|
||||
@@ -47,6 +43,10 @@ CONFIG_SCHEMA = {
|
||||
async def to_code(config: ConfigType) -> None:
|
||||
hub = await cg.get_variable(config[CONF_LD2410_ID])
|
||||
buttons = button.sub_buttons(config, parent=hub)
|
||||
await buttons(CONF_FACTORY_RESET, hub.set_factory_reset_button)
|
||||
await buttons(CONF_RESTART, hub.set_restart_button)
|
||||
await buttons(CONF_QUERY_PARAMS, hub.set_query_button)
|
||||
await buttons(
|
||||
CONF_FACTORY_RESET, hub.set_factory_reset_button, apply="factory_reset()"
|
||||
)
|
||||
await buttons(
|
||||
CONF_RESTART, hub.set_restart_button, apply="restart_and_read_all_info()"
|
||||
)
|
||||
await buttons(CONF_QUERY_PARAMS, hub.set_query_button, apply="read_all_info()")
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
#include "factory_reset_button.h"
|
||||
|
||||
namespace esphome::ld2410 {
|
||||
|
||||
void FactoryResetButton::press_action() { this->parent_->factory_reset(); }
|
||||
|
||||
} // namespace esphome::ld2410
|
||||
@@ -1,16 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/components/button/button.h"
|
||||
#include "../ld2410.h"
|
||||
|
||||
namespace esphome::ld2410 {
|
||||
|
||||
class FactoryResetButton final : public button::Button, public Parented<LD2410Component> {
|
||||
public:
|
||||
FactoryResetButton() = default;
|
||||
|
||||
protected:
|
||||
void press_action() override;
|
||||
};
|
||||
|
||||
} // namespace esphome::ld2410
|
||||
@@ -1,7 +0,0 @@
|
||||
#include "query_button.h"
|
||||
|
||||
namespace esphome::ld2410 {
|
||||
|
||||
void QueryButton::press_action() { this->parent_->read_all_info(); }
|
||||
|
||||
} // namespace esphome::ld2410
|
||||
@@ -1,16 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/components/button/button.h"
|
||||
#include "../ld2410.h"
|
||||
|
||||
namespace esphome::ld2410 {
|
||||
|
||||
class QueryButton final : public button::Button, public Parented<LD2410Component> {
|
||||
public:
|
||||
QueryButton() = default;
|
||||
|
||||
protected:
|
||||
void press_action() override;
|
||||
};
|
||||
|
||||
} // namespace esphome::ld2410
|
||||
@@ -1,7 +0,0 @@
|
||||
#include "restart_button.h"
|
||||
|
||||
namespace esphome::ld2410 {
|
||||
|
||||
void RestartButton::press_action() { this->parent_->restart_and_read_all_info(); }
|
||||
|
||||
} // namespace esphome::ld2410
|
||||
@@ -1,16 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/components/button/button.h"
|
||||
#include "../ld2410.h"
|
||||
|
||||
namespace esphome::ld2410 {
|
||||
|
||||
class RestartButton final : public button::Button, public Parented<LD2410Component> {
|
||||
public:
|
||||
RestartButton() = default;
|
||||
|
||||
protected:
|
||||
void press_action() override;
|
||||
};
|
||||
|
||||
} // namespace esphome::ld2410
|
||||
@@ -727,7 +727,16 @@ void LD2410Component::set_max_distances_timeout() {
|
||||
this->set_config_mode_(false);
|
||||
}
|
||||
|
||||
void LD2410Component::set_gate_threshold(uint8_t gate) {
|
||||
void LD2410Component::set_gate_threshold(number::Number *n) {
|
||||
// Found by pointer: up to 18 compares per write beat storing the gate in each number
|
||||
uint8_t gate = 0;
|
||||
while (gate < TOTAL_GATES && this->gate_move_threshold_numbers_[gate] != n &&
|
||||
this->gate_still_threshold_numbers_[gate] != n)
|
||||
gate++;
|
||||
if (gate == TOTAL_GATES) {
|
||||
ESP_LOGW(TAG, "Threshold number is not a known gate");
|
||||
return;
|
||||
}
|
||||
number::Number *motionsens = this->gate_move_threshold_numbers_[gate];
|
||||
number::Number *stillsens = this->gate_still_threshold_numbers_[gate];
|
||||
|
||||
|
||||
@@ -87,7 +87,7 @@ class LD2410Component final : public Component, public uart::UARTDevice {
|
||||
void set_gate_still_threshold_number(uint8_t gate, number::Number *n);
|
||||
void set_gate_move_threshold_number(uint8_t gate, number::Number *n);
|
||||
void set_max_distances_timeout();
|
||||
void set_gate_threshold(uint8_t gate);
|
||||
void set_gate_threshold(number::Number *n);
|
||||
#endif
|
||||
#ifdef USE_SENSOR
|
||||
void set_gate_move_sensor(uint8_t gate, sensor::Sensor *s);
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
from functools import partial
|
||||
|
||||
import esphome.codegen as cg
|
||||
from esphome.components import number
|
||||
import esphome.config_validation as cv
|
||||
@@ -18,11 +20,7 @@ from esphome.const import (
|
||||
)
|
||||
from esphome.types import ConfigType
|
||||
|
||||
from .. import CONF_LD2410_ID, LD2410Component, ld2410_ns
|
||||
|
||||
GateThresholdNumber = ld2410_ns.class_("GateThresholdNumber", number.Number)
|
||||
LightThresholdNumber = ld2410_ns.class_("LightThresholdNumber", number.Number)
|
||||
MaxDistanceTimeoutNumber = ld2410_ns.class_("MaxDistanceTimeoutNumber", number.Number)
|
||||
from .. import CONF_LD2410_ID, LD2410Component
|
||||
|
||||
CONF_MAX_MOVE_DISTANCE_GATE = "max_move_distance_gate"
|
||||
CONF_MAX_STILL_DISTANCE_GATE = "max_still_distance_gate"
|
||||
@@ -35,25 +33,25 @@ CONFIG_SCHEMA = cv.Schema(
|
||||
cv.GenerateID(CONF_ID): cv.declare_id(cg.EntityBase),
|
||||
cv.GenerateID(CONF_LD2410_ID): cv.use_id(LD2410Component),
|
||||
cv.Inclusive(CONF_TIMEOUT, TIMEOUT_GROUP): number.number_schema(
|
||||
MaxDistanceTimeoutNumber,
|
||||
number.ApplyNumber,
|
||||
unit_of_measurement=UNIT_SECOND,
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
icon=ICON_TIMELAPSE,
|
||||
),
|
||||
cv.Inclusive(CONF_MAX_MOVE_DISTANCE_GATE, TIMEOUT_GROUP): number.number_schema(
|
||||
MaxDistanceTimeoutNumber,
|
||||
number.ApplyNumber,
|
||||
device_class=DEVICE_CLASS_DISTANCE,
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
icon=ICON_MOTION_SENSOR,
|
||||
),
|
||||
cv.Inclusive(CONF_MAX_STILL_DISTANCE_GATE, TIMEOUT_GROUP): number.number_schema(
|
||||
MaxDistanceTimeoutNumber,
|
||||
number.ApplyNumber,
|
||||
device_class=DEVICE_CLASS_DISTANCE,
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
icon=ICON_MOTION_SENSOR,
|
||||
),
|
||||
cv.Optional(CONF_LIGHT_THRESHOLD): number.number_schema(
|
||||
LightThresholdNumber,
|
||||
number.ApplyNumber,
|
||||
device_class=DEVICE_CLASS_ILLUMINANCE,
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
icon=ICON_LIGHTBULB,
|
||||
@@ -66,14 +64,14 @@ CONFIG_SCHEMA = CONFIG_SCHEMA.extend(
|
||||
cv.Optional(f"g{x}"): cv.Schema(
|
||||
{
|
||||
cv.Required(CONF_MOVE_THRESHOLD): number.number_schema(
|
||||
GateThresholdNumber,
|
||||
number.ApplyNumber,
|
||||
device_class=DEVICE_CLASS_SIGNAL_STRENGTH,
|
||||
unit_of_measurement=UNIT_PERCENT,
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
icon=ICON_MOTION_SENSOR,
|
||||
),
|
||||
cv.Required(CONF_STILL_THRESHOLD): number.number_schema(
|
||||
GateThresholdNumber,
|
||||
number.ApplyNumber,
|
||||
device_class=DEVICE_CLASS_SIGNAL_STRENGTH,
|
||||
unit_of_measurement=UNIT_PERCENT,
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
@@ -89,8 +87,14 @@ CONFIG_SCHEMA = CONFIG_SCHEMA.extend(
|
||||
async def to_code(config: ConfigType) -> None:
|
||||
hub = await cg.get_variable(config[CONF_LD2410_ID])
|
||||
numbers = number.sub_numbers(config, parent=hub)
|
||||
timeouts = {"apply": "set_max_distances_timeout()", "publish": "before"}
|
||||
await numbers(
|
||||
CONF_TIMEOUT, hub.set_timeout_number, min_value=0, max_value=65535, step=1
|
||||
CONF_TIMEOUT,
|
||||
hub.set_timeout_number,
|
||||
min_value=0,
|
||||
max_value=65535,
|
||||
step=1,
|
||||
**timeouts,
|
||||
)
|
||||
await numbers(
|
||||
CONF_MAX_MOVE_DISTANCE_GATE,
|
||||
@@ -98,6 +102,7 @@ async def to_code(config: ConfigType) -> None:
|
||||
min_value=2,
|
||||
max_value=8,
|
||||
step=1,
|
||||
**timeouts,
|
||||
)
|
||||
await numbers(
|
||||
CONF_MAX_STILL_DISTANCE_GATE,
|
||||
@@ -105,6 +110,7 @@ async def to_code(config: ConfigType) -> None:
|
||||
min_value=2,
|
||||
max_value=8,
|
||||
step=1,
|
||||
**timeouts,
|
||||
)
|
||||
await numbers(
|
||||
CONF_LIGHT_THRESHOLD,
|
||||
@@ -112,21 +118,25 @@ async def to_code(config: ConfigType) -> None:
|
||||
min_value=0,
|
||||
max_value=255,
|
||||
step=1,
|
||||
apply="set_light_out_control()",
|
||||
publish="before",
|
||||
)
|
||||
threshold = {
|
||||
"min_value": 0,
|
||||
"max_value": 100,
|
||||
"step": 1,
|
||||
"apply": "set_gate_threshold(entity)",
|
||||
"publish": "before",
|
||||
}
|
||||
for x in range(9):
|
||||
if gate_conf := config.get(f"g{x}"):
|
||||
move_config = gate_conf[CONF_MOVE_THRESHOLD]
|
||||
n = cg.new_Pvariable(move_config[CONF_ID], x)
|
||||
await number.register_number(
|
||||
n, move_config, min_value=0, max_value=100, step=1
|
||||
await numbers.create(
|
||||
gate_conf[CONF_MOVE_THRESHOLD],
|
||||
partial(hub.set_gate_move_threshold_number, x),
|
||||
**threshold,
|
||||
)
|
||||
await cg.register_parented(n, hub)
|
||||
cg.add(hub.set_gate_move_threshold_number(x, n))
|
||||
|
||||
still_config = gate_conf[CONF_STILL_THRESHOLD]
|
||||
n = cg.new_Pvariable(still_config[CONF_ID], x)
|
||||
await number.register_number(
|
||||
n, still_config, min_value=0, max_value=100, step=1
|
||||
await numbers.create(
|
||||
gate_conf[CONF_STILL_THRESHOLD],
|
||||
partial(hub.set_gate_still_threshold_number, x),
|
||||
**threshold,
|
||||
)
|
||||
await cg.register_parented(n, hub)
|
||||
cg.add(hub.set_gate_still_threshold_number(x, n))
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
#include "gate_threshold_number.h"
|
||||
|
||||
namespace esphome::ld2410 {
|
||||
|
||||
GateThresholdNumber::GateThresholdNumber(uint8_t gate) : gate_(gate) {}
|
||||
|
||||
void GateThresholdNumber::control(float value) {
|
||||
this->publish_state(value);
|
||||
this->parent_->set_gate_threshold(this->gate_);
|
||||
}
|
||||
|
||||
} // namespace esphome::ld2410
|
||||
@@ -1,17 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/components/number/number.h"
|
||||
#include "../ld2410.h"
|
||||
|
||||
namespace esphome::ld2410 {
|
||||
|
||||
class GateThresholdNumber final : public number::Number, public Parented<LD2410Component> {
|
||||
public:
|
||||
GateThresholdNumber(uint8_t gate);
|
||||
|
||||
protected:
|
||||
uint8_t gate_;
|
||||
void control(float value) override;
|
||||
};
|
||||
|
||||
} // namespace esphome::ld2410
|
||||
@@ -1,10 +0,0 @@
|
||||
#include "light_threshold_number.h"
|
||||
|
||||
namespace esphome::ld2410 {
|
||||
|
||||
void LightThresholdNumber::control(float value) {
|
||||
this->publish_state(value);
|
||||
this->parent_->set_light_out_control();
|
||||
}
|
||||
|
||||
} // namespace esphome::ld2410
|
||||
@@ -1,16 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/components/number/number.h"
|
||||
#include "../ld2410.h"
|
||||
|
||||
namespace esphome::ld2410 {
|
||||
|
||||
class LightThresholdNumber final : public number::Number, public Parented<LD2410Component> {
|
||||
public:
|
||||
LightThresholdNumber() = default;
|
||||
|
||||
protected:
|
||||
void control(float value) override;
|
||||
};
|
||||
|
||||
} // namespace esphome::ld2410
|
||||
@@ -1,10 +0,0 @@
|
||||
#include "max_distance_timeout_number.h"
|
||||
|
||||
namespace esphome::ld2410 {
|
||||
|
||||
void MaxDistanceTimeoutNumber::control(float value) {
|
||||
this->publish_state(value);
|
||||
this->parent_->set_max_distances_timeout();
|
||||
}
|
||||
|
||||
} // namespace esphome::ld2410
|
||||
@@ -1,16 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/components/number/number.h"
|
||||
#include "../ld2410.h"
|
||||
|
||||
namespace esphome::ld2410 {
|
||||
|
||||
class MaxDistanceTimeoutNumber final : public number::Number, public Parented<LD2410Component> {
|
||||
public:
|
||||
MaxDistanceTimeoutNumber() = default;
|
||||
|
||||
protected:
|
||||
void control(float value) override;
|
||||
};
|
||||
|
||||
} // namespace esphome::ld2410
|
||||
@@ -13,11 +13,7 @@ from esphome.const import (
|
||||
)
|
||||
from esphome.types import ConfigType
|
||||
|
||||
from .. import CONF_LD2410_ID, LD2410Component, ld2410_ns
|
||||
|
||||
BaudRateSelect = ld2410_ns.class_("BaudRateSelect", select.Select)
|
||||
DistanceResolutionSelect = ld2410_ns.class_("DistanceResolutionSelect", select.Select)
|
||||
LightOutControlSelect = ld2410_ns.class_("LightOutControlSelect", select.Select)
|
||||
from .. import CONF_LD2410_ID, LD2410Component
|
||||
|
||||
CONF_DISTANCE_RESOLUTION = "distance_resolution"
|
||||
CONF_LIGHT_FUNCTION = "light_function"
|
||||
@@ -27,22 +23,22 @@ CONFIG_SCHEMA = {
|
||||
cv.GenerateID(CONF_ID): cv.declare_id(cg.EntityBase),
|
||||
cv.GenerateID(CONF_LD2410_ID): cv.use_id(LD2410Component),
|
||||
cv.Optional(CONF_DISTANCE_RESOLUTION): select.select_schema(
|
||||
DistanceResolutionSelect,
|
||||
select.ApplySelect,
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
icon=ICON_RULER,
|
||||
),
|
||||
cv.Optional(CONF_LIGHT_FUNCTION): select.select_schema(
|
||||
LightOutControlSelect,
|
||||
select.ApplySelect,
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
icon=ICON_LIGHTBULB,
|
||||
),
|
||||
cv.Optional(CONF_OUT_PIN_LEVEL): select.select_schema(
|
||||
LightOutControlSelect,
|
||||
select.ApplySelect,
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
icon=ICON_SCALE,
|
||||
),
|
||||
cv.Optional(CONF_BAUD_RATE): select.select_schema(
|
||||
BaudRateSelect,
|
||||
select.ApplySelect,
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
icon=ICON_THERMOMETER,
|
||||
),
|
||||
@@ -56,18 +52,27 @@ async def to_code(config: ConfigType) -> None:
|
||||
CONF_DISTANCE_RESOLUTION,
|
||||
hub.set_distance_resolution_select,
|
||||
options=["0.2m", "0.75m"],
|
||||
apply="set_distance_resolution(entity->option_at(index))",
|
||||
publish="before",
|
||||
)
|
||||
light = {"apply": "set_light_out_control()", "publish": "before"}
|
||||
await selects(
|
||||
CONF_OUT_PIN_LEVEL, hub.set_out_pin_level_select, options=["low", "high"]
|
||||
CONF_OUT_PIN_LEVEL,
|
||||
hub.set_out_pin_level_select,
|
||||
options=["low", "high"],
|
||||
**light,
|
||||
)
|
||||
await selects(
|
||||
CONF_LIGHT_FUNCTION,
|
||||
hub.set_light_function_select,
|
||||
options=["off", "below", "above"],
|
||||
**light,
|
||||
)
|
||||
await selects(
|
||||
CONF_BAUD_RATE,
|
||||
hub.set_baud_rate_select,
|
||||
apply="set_baud_rate(entity->option_at(index))",
|
||||
publish="before",
|
||||
options=[
|
||||
"9600",
|
||||
"19200",
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
#include "baud_rate_select.h"
|
||||
|
||||
namespace esphome::ld2410 {
|
||||
|
||||
void BaudRateSelect::control(size_t index) {
|
||||
this->publish_state(index);
|
||||
this->parent_->set_baud_rate(this->option_at(index));
|
||||
}
|
||||
|
||||
} // namespace esphome::ld2410
|
||||
@@ -1,16 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/components/select/select.h"
|
||||
#include "../ld2410.h"
|
||||
|
||||
namespace esphome::ld2410 {
|
||||
|
||||
class BaudRateSelect final : public select::Select, public Parented<LD2410Component> {
|
||||
public:
|
||||
BaudRateSelect() = default;
|
||||
|
||||
protected:
|
||||
void control(size_t index) override;
|
||||
};
|
||||
|
||||
} // namespace esphome::ld2410
|
||||
@@ -1,10 +0,0 @@
|
||||
#include "distance_resolution_select.h"
|
||||
|
||||
namespace esphome::ld2410 {
|
||||
|
||||
void DistanceResolutionSelect::control(size_t index) {
|
||||
this->publish_state(index);
|
||||
this->parent_->set_distance_resolution(this->option_at(index));
|
||||
}
|
||||
|
||||
} // namespace esphome::ld2410
|
||||
@@ -1,16 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/components/select/select.h"
|
||||
#include "../ld2410.h"
|
||||
|
||||
namespace esphome::ld2410 {
|
||||
|
||||
class DistanceResolutionSelect final : public select::Select, public Parented<LD2410Component> {
|
||||
public:
|
||||
DistanceResolutionSelect() = default;
|
||||
|
||||
protected:
|
||||
void control(size_t index) override;
|
||||
};
|
||||
|
||||
} // namespace esphome::ld2410
|
||||
@@ -1,10 +0,0 @@
|
||||
#include "light_out_control_select.h"
|
||||
|
||||
namespace esphome::ld2410 {
|
||||
|
||||
void LightOutControlSelect::control(size_t index) {
|
||||
this->publish_state(index);
|
||||
this->parent_->set_light_out_control();
|
||||
}
|
||||
|
||||
} // namespace esphome::ld2410
|
||||
@@ -1,16 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/components/select/select.h"
|
||||
#include "../ld2410.h"
|
||||
|
||||
namespace esphome::ld2410 {
|
||||
|
||||
class LightOutControlSelect final : public select::Select, public Parented<LD2410Component> {
|
||||
public:
|
||||
LightOutControlSelect() = default;
|
||||
|
||||
protected:
|
||||
void control(size_t index) override;
|
||||
};
|
||||
|
||||
} // namespace esphome::ld2410
|
||||
@@ -11,10 +11,7 @@ from esphome.const import (
|
||||
)
|
||||
from esphome.types import ConfigType
|
||||
|
||||
from .. import CONF_LD2410_ID, LD2410Component, ld2410_ns
|
||||
|
||||
BluetoothSwitch = ld2410_ns.class_("BluetoothSwitch", switch.Switch)
|
||||
EngineeringModeSwitch = ld2410_ns.class_("EngineeringModeSwitch", switch.Switch)
|
||||
from .. import CONF_LD2410_ID, LD2410Component
|
||||
|
||||
CONF_ENGINEERING_MODE = "engineering_mode"
|
||||
|
||||
@@ -22,13 +19,13 @@ CONFIG_SCHEMA = {
|
||||
cv.GenerateID(CONF_ID): cv.declare_id(cg.EntityBase),
|
||||
cv.GenerateID(CONF_LD2410_ID): cv.use_id(LD2410Component),
|
||||
cv.Optional(CONF_ENGINEERING_MODE): switch.switch_schema(
|
||||
EngineeringModeSwitch,
|
||||
switch.ApplySwitch,
|
||||
device_class=DEVICE_CLASS_SWITCH,
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
icon=ICON_PULSE,
|
||||
),
|
||||
cv.Optional(CONF_BLUETOOTH): switch.switch_schema(
|
||||
BluetoothSwitch,
|
||||
switch.ApplySwitch,
|
||||
device_class=DEVICE_CLASS_SWITCH,
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
icon=ICON_BLUETOOTH,
|
||||
@@ -39,5 +36,15 @@ CONFIG_SCHEMA = {
|
||||
async def to_code(config: ConfigType) -> None:
|
||||
hub = await cg.get_variable(config[CONF_LD2410_ID])
|
||||
switches = switch.sub_switches(config, parent=hub)
|
||||
await switches(CONF_ENGINEERING_MODE, hub.set_engineering_mode_switch)
|
||||
await switches(CONF_BLUETOOTH, hub.set_bluetooth_switch)
|
||||
await switches(
|
||||
CONF_ENGINEERING_MODE,
|
||||
hub.set_engineering_mode_switch,
|
||||
apply="set_engineering_mode(state)",
|
||||
publish="before",
|
||||
)
|
||||
await switches(
|
||||
CONF_BLUETOOTH,
|
||||
hub.set_bluetooth_switch,
|
||||
apply="set_bluetooth(state)",
|
||||
publish="before",
|
||||
)
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
#include "bluetooth_switch.h"
|
||||
|
||||
namespace esphome::ld2410 {
|
||||
|
||||
void BluetoothSwitch::write_state(bool state) {
|
||||
this->publish_state(state);
|
||||
this->parent_->set_bluetooth(state);
|
||||
}
|
||||
|
||||
} // namespace esphome::ld2410
|
||||
@@ -1,16 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/components/switch/switch.h"
|
||||
#include "../ld2410.h"
|
||||
|
||||
namespace esphome::ld2410 {
|
||||
|
||||
class BluetoothSwitch final : public switch_::Switch, public Parented<LD2410Component> {
|
||||
public:
|
||||
BluetoothSwitch() = default;
|
||||
|
||||
protected:
|
||||
void write_state(bool state) override;
|
||||
};
|
||||
|
||||
} // namespace esphome::ld2410
|
||||
@@ -1,10 +0,0 @@
|
||||
#include "engineering_mode_switch.h"
|
||||
|
||||
namespace esphome::ld2410 {
|
||||
|
||||
void EngineeringModeSwitch::write_state(bool state) {
|
||||
this->publish_state(state);
|
||||
this->parent_->set_engineering_mode(state);
|
||||
}
|
||||
|
||||
} // namespace esphome::ld2410
|
||||
@@ -1,16 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/components/switch/switch.h"
|
||||
#include "../ld2410.h"
|
||||
|
||||
namespace esphome::ld2410 {
|
||||
|
||||
class EngineeringModeSwitch final : public switch_::Switch, public Parented<LD2410Component> {
|
||||
public:
|
||||
EngineeringModeSwitch() = default;
|
||||
|
||||
protected:
|
||||
void write_state(bool state) override;
|
||||
};
|
||||
|
||||
} // namespace esphome::ld2410
|
||||
@@ -16,38 +16,32 @@ from esphome.const import (
|
||||
)
|
||||
from esphome.types import ConfigType
|
||||
|
||||
from .. import CONF_LD2412_ID, LD2412_ns, LD2412Component
|
||||
from .. import CONF_LD2412_ID, LD2412Component
|
||||
|
||||
FactoryResetButton = LD2412_ns.class_("FactoryResetButton", button.Button)
|
||||
QueryButton = LD2412_ns.class_("QueryButton", button.Button)
|
||||
RestartButton = LD2412_ns.class_("RestartButton", button.Button)
|
||||
StartDynamicBackgroundCorrectionButton = LD2412_ns.class_(
|
||||
"StartDynamicBackgroundCorrectionButton", button.Button
|
||||
)
|
||||
CONF_START_DYNAMIC_BACKGROUND_CORRECTION = "start_dynamic_background_correction"
|
||||
|
||||
CONFIG_SCHEMA = {
|
||||
cv.GenerateID(CONF_ID): cv.declare_id(cg.EntityBase),
|
||||
cv.GenerateID(CONF_LD2412_ID): cv.use_id(LD2412Component),
|
||||
cv.Optional(CONF_FACTORY_RESET): button.button_schema(
|
||||
FactoryResetButton,
|
||||
button.ApplyButton,
|
||||
device_class=DEVICE_CLASS_RESTART,
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
icon=ICON_RESTART_ALERT,
|
||||
),
|
||||
cv.Optional(CONF_QUERY_PARAMS): button.button_schema(
|
||||
QueryButton,
|
||||
button.ApplyButton,
|
||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
icon=ICON_DATABASE,
|
||||
),
|
||||
cv.Optional(CONF_RESTART): button.button_schema(
|
||||
RestartButton,
|
||||
button.ApplyButton,
|
||||
device_class=DEVICE_CLASS_RESTART,
|
||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
icon=ICON_RESTART,
|
||||
),
|
||||
cv.Optional(CONF_START_DYNAMIC_BACKGROUND_CORRECTION): button.button_schema(
|
||||
StartDynamicBackgroundCorrectionButton,
|
||||
button.ApplyButton,
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
icon=ICON_PULSE,
|
||||
),
|
||||
@@ -57,10 +51,15 @@ CONFIG_SCHEMA = {
|
||||
async def to_code(config: ConfigType) -> None:
|
||||
hub = await cg.get_variable(config[CONF_LD2412_ID])
|
||||
buttons = button.sub_buttons(config, parent=hub)
|
||||
await buttons(CONF_FACTORY_RESET, hub.set_factory_reset_button)
|
||||
await buttons(CONF_QUERY_PARAMS, hub.set_query_button)
|
||||
await buttons(CONF_RESTART, hub.set_restart_button)
|
||||
await buttons(
|
||||
CONF_FACTORY_RESET, hub.set_factory_reset_button, apply="factory_reset()"
|
||||
)
|
||||
await buttons(CONF_QUERY_PARAMS, hub.set_query_button, apply="read_all_info()")
|
||||
await buttons(
|
||||
CONF_RESTART, hub.set_restart_button, apply="restart_and_read_all_info()"
|
||||
)
|
||||
await buttons(
|
||||
CONF_START_DYNAMIC_BACKGROUND_CORRECTION,
|
||||
hub.set_start_dynamic_background_correction_button,
|
||||
apply="start_dynamic_background_correction()",
|
||||
)
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
#include "factory_reset_button.h"
|
||||
|
||||
namespace esphome::ld2412 {
|
||||
|
||||
void FactoryResetButton::press_action() { this->parent_->factory_reset(); }
|
||||
|
||||
} // namespace esphome::ld2412
|
||||
@@ -1,16 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/components/button/button.h"
|
||||
#include "../ld2412.h"
|
||||
|
||||
namespace esphome::ld2412 {
|
||||
|
||||
class FactoryResetButton final : public button::Button, public Parented<LD2412Component> {
|
||||
public:
|
||||
FactoryResetButton() = default;
|
||||
|
||||
protected:
|
||||
void press_action() override;
|
||||
};
|
||||
|
||||
} // namespace esphome::ld2412
|
||||
@@ -1,7 +0,0 @@
|
||||
#include "query_button.h"
|
||||
|
||||
namespace esphome::ld2412 {
|
||||
|
||||
void QueryButton::press_action() { this->parent_->read_all_info(); }
|
||||
|
||||
} // namespace esphome::ld2412
|
||||
@@ -1,16 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/components/button/button.h"
|
||||
#include "../ld2412.h"
|
||||
|
||||
namespace esphome::ld2412 {
|
||||
|
||||
class QueryButton final : public button::Button, public Parented<LD2412Component> {
|
||||
public:
|
||||
QueryButton() = default;
|
||||
|
||||
protected:
|
||||
void press_action() override;
|
||||
};
|
||||
|
||||
} // namespace esphome::ld2412
|
||||
@@ -1,7 +0,0 @@
|
||||
#include "restart_button.h"
|
||||
|
||||
namespace esphome::ld2412 {
|
||||
|
||||
void RestartButton::press_action() { this->parent_->restart_and_read_all_info(); }
|
||||
|
||||
} // namespace esphome::ld2412
|
||||
@@ -1,16 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/components/button/button.h"
|
||||
#include "../ld2412.h"
|
||||
|
||||
namespace esphome::ld2412 {
|
||||
|
||||
class RestartButton final : public button::Button, public Parented<LD2412Component> {
|
||||
public:
|
||||
RestartButton() = default;
|
||||
|
||||
protected:
|
||||
void press_action() override;
|
||||
};
|
||||
|
||||
} // namespace esphome::ld2412
|
||||
@@ -1,9 +0,0 @@
|
||||
#include "start_dynamic_background_correction_button.h"
|
||||
|
||||
#include "restart_button.h"
|
||||
|
||||
namespace esphome::ld2412 {
|
||||
|
||||
void StartDynamicBackgroundCorrectionButton::press_action() { this->parent_->start_dynamic_background_correction(); }
|
||||
|
||||
} // namespace esphome::ld2412
|
||||
@@ -1,16 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/components/button/button.h"
|
||||
#include "../ld2412.h"
|
||||
|
||||
namespace esphome::ld2412 {
|
||||
|
||||
class StartDynamicBackgroundCorrectionButton final : public button::Button, public Parented<LD2412Component> {
|
||||
public:
|
||||
StartDynamicBackgroundCorrectionButton() = default;
|
||||
|
||||
protected:
|
||||
void press_action() override;
|
||||
};
|
||||
|
||||
} // namespace esphome::ld2412
|
||||
@@ -1,3 +1,5 @@
|
||||
from functools import partial
|
||||
|
||||
import esphome.codegen as cg
|
||||
from esphome.components import number
|
||||
import esphome.config_validation as cv
|
||||
@@ -18,11 +20,7 @@ from esphome.const import (
|
||||
)
|
||||
from esphome.types import ConfigType
|
||||
|
||||
from .. import CONF_LD2412_ID, LD2412_ns, LD2412Component
|
||||
|
||||
GateThresholdNumber = LD2412_ns.class_("GateThresholdNumber", number.Number)
|
||||
LightThresholdNumber = LD2412_ns.class_("LightThresholdNumber", number.Number)
|
||||
MaxDistanceTimeoutNumber = LD2412_ns.class_("MaxDistanceTimeoutNumber", number.Number)
|
||||
from .. import CONF_LD2412_ID, LD2412Component
|
||||
|
||||
CONF_LIGHT_THRESHOLD = "light_threshold"
|
||||
CONF_MAX_DISTANCE_GATE = "max_distance_gate"
|
||||
@@ -35,25 +33,25 @@ CONFIG_SCHEMA = cv.Schema(
|
||||
cv.GenerateID(CONF_ID): cv.declare_id(cg.EntityBase),
|
||||
cv.GenerateID(CONF_LD2412_ID): cv.use_id(LD2412Component),
|
||||
cv.Optional(CONF_LIGHT_THRESHOLD): number.number_schema(
|
||||
LightThresholdNumber,
|
||||
number.ApplyNumber,
|
||||
device_class=DEVICE_CLASS_ILLUMINANCE,
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
icon=ICON_LIGHTBULB,
|
||||
),
|
||||
cv.Optional(CONF_MAX_DISTANCE_GATE): number.number_schema(
|
||||
MaxDistanceTimeoutNumber,
|
||||
number.ApplyNumber,
|
||||
device_class=DEVICE_CLASS_DISTANCE,
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
icon=ICON_MOTION_SENSOR,
|
||||
),
|
||||
cv.Optional(CONF_MIN_DISTANCE_GATE): number.number_schema(
|
||||
MaxDistanceTimeoutNumber,
|
||||
number.ApplyNumber,
|
||||
device_class=DEVICE_CLASS_DISTANCE,
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
icon=ICON_MOTION_SENSOR,
|
||||
),
|
||||
cv.Optional(CONF_TIMEOUT): number.number_schema(
|
||||
MaxDistanceTimeoutNumber,
|
||||
number.ApplyNumber,
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
icon=ICON_TIMELAPSE,
|
||||
unit_of_measurement=UNIT_SECOND,
|
||||
@@ -66,14 +64,14 @@ CONFIG_SCHEMA = CONFIG_SCHEMA.extend(
|
||||
cv.Optional(f"gate_{x}"): (
|
||||
{
|
||||
cv.Required(CONF_MOVE_THRESHOLD): number.number_schema(
|
||||
GateThresholdNumber,
|
||||
number.ApplyNumber,
|
||||
device_class=DEVICE_CLASS_SIGNAL_STRENGTH,
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
icon=ICON_MOTION_SENSOR,
|
||||
unit_of_measurement=UNIT_PERCENT,
|
||||
),
|
||||
cv.Required(CONF_STILL_THRESHOLD): number.number_schema(
|
||||
GateThresholdNumber,
|
||||
number.ApplyNumber,
|
||||
device_class=DEVICE_CLASS_SIGNAL_STRENGTH,
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
icon=ICON_MOTION_SENSOR,
|
||||
@@ -95,13 +93,17 @@ async def to_code(config: ConfigType) -> None:
|
||||
min_value=0,
|
||||
max_value=255,
|
||||
step=1,
|
||||
apply="set_light_out_control()",
|
||||
publish="before",
|
||||
)
|
||||
basic = {"apply": "set_basic_config()", "publish": "before"}
|
||||
await numbers(
|
||||
CONF_MAX_DISTANCE_GATE,
|
||||
hub.set_max_distance_gate_number,
|
||||
min_value=2,
|
||||
max_value=13,
|
||||
step=1,
|
||||
**basic,
|
||||
)
|
||||
await numbers(
|
||||
CONF_MIN_DISTANCE_GATE,
|
||||
@@ -109,23 +111,32 @@ async def to_code(config: ConfigType) -> None:
|
||||
min_value=1,
|
||||
max_value=12,
|
||||
step=1,
|
||||
**basic,
|
||||
)
|
||||
threshold = {
|
||||
"min_value": 0,
|
||||
"max_value": 100,
|
||||
"step": 1,
|
||||
"apply": "set_gate_threshold(entity)",
|
||||
"publish": "before",
|
||||
}
|
||||
for x in range(14):
|
||||
if gate_conf := config.get(f"gate_{x}"):
|
||||
move_config = gate_conf[CONF_MOVE_THRESHOLD]
|
||||
n = await number.new_number(move_config, min_value=0, max_value=100, step=1)
|
||||
await cg.register_parented(n, hub)
|
||||
cg.add(hub.set_gate_move_threshold_number(x, n))
|
||||
still_config = gate_conf[CONF_STILL_THRESHOLD]
|
||||
n = await number.new_number(
|
||||
still_config, min_value=0, max_value=100, step=1
|
||||
await numbers.create(
|
||||
gate_conf[CONF_MOVE_THRESHOLD],
|
||||
partial(hub.set_gate_move_threshold_number, x),
|
||||
**threshold,
|
||||
)
|
||||
await numbers.create(
|
||||
gate_conf[CONF_STILL_THRESHOLD],
|
||||
partial(hub.set_gate_still_threshold_number, x),
|
||||
**threshold,
|
||||
)
|
||||
await cg.register_parented(n, hub)
|
||||
cg.add(hub.set_gate_still_threshold_number(x, n))
|
||||
await numbers(
|
||||
CONF_TIMEOUT,
|
||||
hub.set_timeout_number,
|
||||
min_value=0,
|
||||
max_value=900,
|
||||
step=1,
|
||||
**basic,
|
||||
)
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
#include "gate_threshold_number.h"
|
||||
|
||||
namespace esphome::ld2412 {
|
||||
|
||||
void GateThresholdNumber::control(float value) {
|
||||
this->publish_state(value);
|
||||
this->parent_->set_gate_threshold(this);
|
||||
}
|
||||
|
||||
} // namespace esphome::ld2412
|
||||
@@ -1,17 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/components/number/number.h"
|
||||
#include "../ld2412.h"
|
||||
|
||||
namespace esphome::ld2412 {
|
||||
|
||||
class GateThresholdNumber final : public number::Number, public Parented<LD2412Component> {
|
||||
public:
|
||||
// Not "= default": that makes new(p) T() zero-fill the object at every codegen site before the ctor runs.
|
||||
GateThresholdNumber() {}
|
||||
|
||||
protected:
|
||||
void control(float value) override;
|
||||
};
|
||||
|
||||
} // namespace esphome::ld2412
|
||||
@@ -1,10 +0,0 @@
|
||||
#include "light_threshold_number.h"
|
||||
|
||||
namespace esphome::ld2412 {
|
||||
|
||||
void LightThresholdNumber::control(float value) {
|
||||
this->publish_state(value);
|
||||
this->parent_->set_light_out_control();
|
||||
}
|
||||
|
||||
} // namespace esphome::ld2412
|
||||
@@ -1,17 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/components/number/number.h"
|
||||
#include "../ld2412.h"
|
||||
|
||||
namespace esphome::ld2412 {
|
||||
|
||||
class LightThresholdNumber final : public number::Number, public Parented<LD2412Component> {
|
||||
public:
|
||||
// User provided, not "= default": `new(p) LightThresholdNumber()` would zero-fill .bss that is already zero.
|
||||
LightThresholdNumber() {}
|
||||
|
||||
protected:
|
||||
void control(float value) override;
|
||||
};
|
||||
|
||||
} // namespace esphome::ld2412
|
||||
@@ -1,10 +0,0 @@
|
||||
#include "max_distance_timeout_number.h"
|
||||
|
||||
namespace esphome::ld2412 {
|
||||
|
||||
void MaxDistanceTimeoutNumber::control(float value) {
|
||||
this->publish_state(value);
|
||||
this->parent_->set_basic_config();
|
||||
}
|
||||
|
||||
} // namespace esphome::ld2412
|
||||
@@ -1,16 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/components/number/number.h"
|
||||
#include "../ld2412.h"
|
||||
|
||||
namespace esphome::ld2412 {
|
||||
|
||||
class MaxDistanceTimeoutNumber final : public number::Number, public Parented<LD2412Component> {
|
||||
public:
|
||||
MaxDistanceTimeoutNumber() = default;
|
||||
|
||||
protected:
|
||||
void control(float value) override;
|
||||
};
|
||||
|
||||
} // namespace esphome::ld2412
|
||||
@@ -13,11 +13,7 @@ from esphome.const import (
|
||||
)
|
||||
from esphome.types import ConfigType
|
||||
|
||||
from .. import CONF_LD2412_ID, LD2412_ns, LD2412Component
|
||||
|
||||
BaudRateSelect = LD2412_ns.class_("BaudRateSelect", select.Select)
|
||||
DistanceResolutionSelect = LD2412_ns.class_("DistanceResolutionSelect", select.Select)
|
||||
LightOutControlSelect = LD2412_ns.class_("LightOutControlSelect", select.Select)
|
||||
from .. import CONF_LD2412_ID, LD2412Component
|
||||
|
||||
CONF_DISTANCE_RESOLUTION = "distance_resolution"
|
||||
CONF_LIGHT_FUNCTION = "light_function"
|
||||
@@ -27,22 +23,22 @@ CONFIG_SCHEMA = {
|
||||
cv.GenerateID(CONF_ID): cv.declare_id(cg.EntityBase),
|
||||
cv.GenerateID(CONF_LD2412_ID): cv.use_id(LD2412Component),
|
||||
cv.Optional(CONF_BAUD_RATE): select.select_schema(
|
||||
BaudRateSelect,
|
||||
select.ApplySelect,
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
icon=ICON_THERMOMETER,
|
||||
),
|
||||
cv.Optional(CONF_DISTANCE_RESOLUTION): select.select_schema(
|
||||
DistanceResolutionSelect,
|
||||
select.ApplySelect,
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
icon=ICON_RULER,
|
||||
),
|
||||
cv.Optional(CONF_LIGHT_FUNCTION): select.select_schema(
|
||||
LightOutControlSelect,
|
||||
select.ApplySelect,
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
icon=ICON_LIGHTBULB,
|
||||
),
|
||||
cv.Optional(CONF_OUT_PIN_LEVEL): select.select_schema(
|
||||
LightOutControlSelect,
|
||||
select.ApplySelect,
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
icon=ICON_SCALE,
|
||||
),
|
||||
@@ -65,19 +61,26 @@ async def to_code(config: ConfigType) -> None:
|
||||
"256000",
|
||||
"460800",
|
||||
],
|
||||
apply="set_baud_rate(entity->option_at(index))",
|
||||
publish="before",
|
||||
)
|
||||
await selects(
|
||||
CONF_DISTANCE_RESOLUTION,
|
||||
hub.set_distance_resolution_select,
|
||||
options=["0.2m", "0.5m", "0.75m"],
|
||||
apply="set_distance_resolution(entity->option_at(index))",
|
||||
publish="before",
|
||||
)
|
||||
light = {"apply": "set_light_out_control()", "publish": "before"}
|
||||
await selects(
|
||||
CONF_LIGHT_FUNCTION,
|
||||
hub.set_light_function_select,
|
||||
options=["off", "below", "above"],
|
||||
**light,
|
||||
)
|
||||
await selects(
|
||||
CONF_OUT_PIN_LEVEL,
|
||||
hub.set_out_pin_level_select,
|
||||
options=["low", "high"],
|
||||
**light,
|
||||
)
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
#include "baud_rate_select.h"
|
||||
|
||||
namespace esphome::ld2412 {
|
||||
|
||||
void BaudRateSelect::control(size_t index) {
|
||||
this->publish_state(index);
|
||||
this->parent_->set_baud_rate(this->option_at(index));
|
||||
}
|
||||
|
||||
} // namespace esphome::ld2412
|
||||
@@ -1,17 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/components/select/select.h"
|
||||
#include "../ld2412.h"
|
||||
|
||||
namespace esphome::ld2412 {
|
||||
|
||||
class BaudRateSelect final : public select::Select, public Parented<LD2412Component> {
|
||||
public:
|
||||
// User provided, not "= default": `new(p) BaudRateSelect()` would zero-fill .bss that is already zero.
|
||||
BaudRateSelect() {}
|
||||
|
||||
protected:
|
||||
void control(size_t index) override;
|
||||
};
|
||||
|
||||
} // namespace esphome::ld2412
|
||||
@@ -1,10 +0,0 @@
|
||||
#include "distance_resolution_select.h"
|
||||
|
||||
namespace esphome::ld2412 {
|
||||
|
||||
void DistanceResolutionSelect::control(size_t index) {
|
||||
this->publish_state(index);
|
||||
this->parent_->set_distance_resolution(this->option_at(index));
|
||||
}
|
||||
|
||||
} // namespace esphome::ld2412
|
||||
@@ -1,17 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/components/select/select.h"
|
||||
#include "../ld2412.h"
|
||||
|
||||
namespace esphome::ld2412 {
|
||||
|
||||
class DistanceResolutionSelect final : public select::Select, public Parented<LD2412Component> {
|
||||
public:
|
||||
// User provided, not "= default": `new(p) DistanceResolutionSelect()` would zero-fill .bss that is already zero.
|
||||
DistanceResolutionSelect() {}
|
||||
|
||||
protected:
|
||||
void control(size_t index) override;
|
||||
};
|
||||
|
||||
} // namespace esphome::ld2412
|
||||
@@ -1,10 +0,0 @@
|
||||
#include "light_out_control_select.h"
|
||||
|
||||
namespace esphome::ld2412 {
|
||||
|
||||
void LightOutControlSelect::control(size_t index) {
|
||||
this->publish_state(index);
|
||||
this->parent_->set_light_out_control();
|
||||
}
|
||||
|
||||
} // namespace esphome::ld2412
|
||||
@@ -1,17 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/components/select/select.h"
|
||||
#include "../ld2412.h"
|
||||
|
||||
namespace esphome::ld2412 {
|
||||
|
||||
class LightOutControlSelect final : public select::Select, public Parented<LD2412Component> {
|
||||
public:
|
||||
// User provided, not "= default": `new(p) LightOutControlSelect()` would zero-fill .bss that is already zero.
|
||||
LightOutControlSelect() {}
|
||||
|
||||
protected:
|
||||
void control(size_t index) override;
|
||||
};
|
||||
|
||||
} // namespace esphome::ld2412
|
||||
@@ -11,10 +11,7 @@ from esphome.const import (
|
||||
)
|
||||
from esphome.types import ConfigType
|
||||
|
||||
from .. import CONF_LD2412_ID, LD2412_ns, LD2412Component
|
||||
|
||||
BluetoothSwitch = LD2412_ns.class_("BluetoothSwitch", switch.Switch)
|
||||
EngineeringModeSwitch = LD2412_ns.class_("EngineeringModeSwitch", switch.Switch)
|
||||
from .. import CONF_LD2412_ID, LD2412Component
|
||||
|
||||
CONF_ENGINEERING_MODE = "engineering_mode"
|
||||
|
||||
@@ -22,13 +19,13 @@ CONFIG_SCHEMA = {
|
||||
cv.GenerateID(CONF_ID): cv.declare_id(cg.EntityBase),
|
||||
cv.GenerateID(CONF_LD2412_ID): cv.use_id(LD2412Component),
|
||||
cv.Optional(CONF_BLUETOOTH): switch.switch_schema(
|
||||
BluetoothSwitch,
|
||||
switch.ApplySwitch,
|
||||
device_class=DEVICE_CLASS_SWITCH,
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
icon=ICON_BLUETOOTH,
|
||||
),
|
||||
cv.Optional(CONF_ENGINEERING_MODE): switch.switch_schema(
|
||||
EngineeringModeSwitch,
|
||||
switch.ApplySwitch,
|
||||
device_class=DEVICE_CLASS_SWITCH,
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
icon=ICON_PULSE,
|
||||
@@ -39,5 +36,15 @@ CONFIG_SCHEMA = {
|
||||
async def to_code(config: ConfigType) -> None:
|
||||
hub = await cg.get_variable(config[CONF_LD2412_ID])
|
||||
switches = switch.sub_switches(config, parent=hub)
|
||||
await switches(CONF_BLUETOOTH, hub.set_bluetooth_switch)
|
||||
await switches(CONF_ENGINEERING_MODE, hub.set_engineering_mode_switch)
|
||||
await switches(
|
||||
CONF_BLUETOOTH,
|
||||
hub.set_bluetooth_switch,
|
||||
apply="set_bluetooth(state)",
|
||||
publish="before",
|
||||
)
|
||||
await switches(
|
||||
CONF_ENGINEERING_MODE,
|
||||
hub.set_engineering_mode_switch,
|
||||
apply="set_engineering_mode(state)",
|
||||
publish="before",
|
||||
)
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
#include "bluetooth_switch.h"
|
||||
|
||||
namespace esphome::ld2412 {
|
||||
|
||||
void BluetoothSwitch::write_state(bool state) {
|
||||
this->publish_state(state);
|
||||
this->parent_->set_bluetooth(state);
|
||||
}
|
||||
|
||||
} // namespace esphome::ld2412
|
||||
@@ -1,17 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/components/switch/switch.h"
|
||||
#include "../ld2412.h"
|
||||
|
||||
namespace esphome::ld2412 {
|
||||
|
||||
class BluetoothSwitch final : public switch_::Switch, public Parented<LD2412Component> {
|
||||
public:
|
||||
// User provided, not "= default": `new(p) BluetoothSwitch()` would zero-fill .bss that is already zero.
|
||||
BluetoothSwitch() {}
|
||||
|
||||
protected:
|
||||
void write_state(bool state) override;
|
||||
};
|
||||
|
||||
} // namespace esphome::ld2412
|
||||
@@ -1,10 +0,0 @@
|
||||
#include "engineering_mode_switch.h"
|
||||
|
||||
namespace esphome::ld2412 {
|
||||
|
||||
void EngineeringModeSwitch::write_state(bool state) {
|
||||
this->publish_state(state);
|
||||
this->parent_->set_engineering_mode(state);
|
||||
}
|
||||
|
||||
} // namespace esphome::ld2412
|
||||
@@ -1,17 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/components/switch/switch.h"
|
||||
#include "../ld2412.h"
|
||||
|
||||
namespace esphome::ld2412 {
|
||||
|
||||
class EngineeringModeSwitch final : public switch_::Switch, public Parented<LD2412Component> {
|
||||
public:
|
||||
// User provided, not "= default": `new(p) EngineeringModeSwitch()` would zero-fill .bss that is already zero.
|
||||
EngineeringModeSwitch() {}
|
||||
|
||||
protected:
|
||||
void write_state(bool state) override;
|
||||
};
|
||||
|
||||
} // namespace esphome::ld2412
|
||||
@@ -12,12 +12,7 @@ from esphome.const import (
|
||||
)
|
||||
from esphome.types import ConfigType
|
||||
|
||||
from .. import CONF_LD2420_ID, LD2420Component, ld2420_ns
|
||||
|
||||
LD2420ApplyConfigButton = ld2420_ns.class_("LD2420ApplyConfigButton", button.Button)
|
||||
LD2420RevertConfigButton = ld2420_ns.class_("LD2420RevertConfigButton", button.Button)
|
||||
LD2420RestartModuleButton = ld2420_ns.class_("LD2420RestartModuleButton", button.Button)
|
||||
LD2420FactoryResetButton = ld2420_ns.class_("LD2420FactoryResetButton", button.Button)
|
||||
from .. import CONF_LD2420_ID, LD2420Component
|
||||
|
||||
CONF_APPLY_CONFIG = "apply_config"
|
||||
CONF_REVERT_CONFIG = "revert_config"
|
||||
@@ -27,24 +22,24 @@ CONF_RESTART_MODULE = "restart_module"
|
||||
CONFIG_SCHEMA = {
|
||||
cv.GenerateID(CONF_LD2420_ID): cv.use_id(LD2420Component),
|
||||
cv.Required(CONF_APPLY_CONFIG): button.button_schema(
|
||||
LD2420ApplyConfigButton,
|
||||
button.ApplyButton,
|
||||
device_class=DEVICE_CLASS_RESTART,
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
icon=ICON_RESTART_ALERT,
|
||||
),
|
||||
cv.Optional(CONF_REVERT_CONFIG): button.button_schema(
|
||||
LD2420RevertConfigButton,
|
||||
button.ApplyButton,
|
||||
device_class=DEVICE_CLASS_RESTART,
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
icon=ICON_RESTART,
|
||||
),
|
||||
cv.Optional(CONF_RESTART_MODULE): button.button_schema(
|
||||
LD2420RestartModuleButton,
|
||||
button.ApplyButton,
|
||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
icon=ICON_DATABASE,
|
||||
),
|
||||
cv.Optional(CONF_FACTORY_RESET): button.button_schema(
|
||||
LD2420FactoryResetButton,
|
||||
button.ApplyButton,
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
icon=ICON_DATABASE,
|
||||
),
|
||||
@@ -54,7 +49,21 @@ CONFIG_SCHEMA = {
|
||||
async def to_code(config: ConfigType) -> None:
|
||||
hub = await cg.get_variable(config[CONF_LD2420_ID])
|
||||
buttons = button.sub_buttons(config, parent=hub)
|
||||
await buttons(CONF_APPLY_CONFIG, hub.set_apply_config_button)
|
||||
await buttons(CONF_REVERT_CONFIG, hub.set_revert_config_button)
|
||||
await buttons(CONF_RESTART_MODULE, hub.set_restart_module_button)
|
||||
await buttons(CONF_FACTORY_RESET, hub.set_factory_reset_button)
|
||||
await buttons(
|
||||
CONF_APPLY_CONFIG, hub.set_apply_config_button, apply="apply_config_action()"
|
||||
)
|
||||
await buttons(
|
||||
CONF_REVERT_CONFIG,
|
||||
hub.set_revert_config_button,
|
||||
apply="revert_config_action()",
|
||||
)
|
||||
await buttons(
|
||||
CONF_RESTART_MODULE,
|
||||
hub.set_restart_module_button,
|
||||
apply="restart_module_action()",
|
||||
)
|
||||
await buttons(
|
||||
CONF_FACTORY_RESET,
|
||||
hub.set_factory_reset_button,
|
||||
apply="factory_reset_action()",
|
||||
)
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
#include "reconfig_buttons.h"
|
||||
#include "esphome/core/helpers.h"
|
||||
#include "esphome/core/log.h"
|
||||
|
||||
ESPHOME_LOG_TAG(TAG, "ld2420.button");
|
||||
|
||||
namespace esphome::ld2420 {
|
||||
|
||||
void LD2420ApplyConfigButton::press_action() { this->parent_->apply_config_action(); }
|
||||
void LD2420RevertConfigButton::press_action() { this->parent_->revert_config_action(); }
|
||||
void LD2420RestartModuleButton::press_action() { this->parent_->restart_module_action(); }
|
||||
void LD2420FactoryResetButton::press_action() { this->parent_->factory_reset_action(); }
|
||||
|
||||
} // namespace esphome::ld2420
|
||||
@@ -1,40 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/components/button/button.h"
|
||||
#include "../ld2420.h"
|
||||
|
||||
namespace esphome::ld2420 {
|
||||
|
||||
class LD2420ApplyConfigButton final : public button::Button, public Parented<LD2420Component> {
|
||||
public:
|
||||
LD2420ApplyConfigButton() = default;
|
||||
|
||||
protected:
|
||||
void press_action() override;
|
||||
};
|
||||
|
||||
class LD2420RevertConfigButton final : public button::Button, public Parented<LD2420Component> {
|
||||
public:
|
||||
LD2420RevertConfigButton() = default;
|
||||
|
||||
protected:
|
||||
void press_action() override;
|
||||
};
|
||||
|
||||
class LD2420RestartModuleButton final : public button::Button, public Parented<LD2420Component> {
|
||||
public:
|
||||
LD2420RestartModuleButton() = default;
|
||||
|
||||
protected:
|
||||
void press_action() override;
|
||||
};
|
||||
|
||||
class LD2420FactoryResetButton final : public button::Button, public Parented<LD2420Component> {
|
||||
public:
|
||||
LD2420FactoryResetButton() = default;
|
||||
|
||||
protected:
|
||||
void press_action() override;
|
||||
};
|
||||
|
||||
} // namespace esphome::ld2420
|
||||
@@ -4,7 +4,7 @@ import esphome.config_validation as cv
|
||||
from esphome.const import ENTITY_CATEGORY_CONFIG
|
||||
from esphome.types import ConfigType
|
||||
|
||||
from .. import CONF_LD2420_ID, LD2420Component, ld2420_ns
|
||||
from .. import CONF_LD2420_ID, LD2420Component
|
||||
|
||||
CONF_OPERATING_MODE = "operating_mode"
|
||||
CONF_SELECTS = [
|
||||
@@ -13,12 +13,11 @@ CONF_SELECTS = [
|
||||
"Simple",
|
||||
]
|
||||
|
||||
LD2420Select = ld2420_ns.class_("LD2420Select", select.Select, cg.Component)
|
||||
|
||||
CONFIG_SCHEMA = {
|
||||
cv.GenerateID(CONF_LD2420_ID): cv.use_id(LD2420Component),
|
||||
cv.Required(CONF_OPERATING_MODE): select.select_schema(
|
||||
LD2420Select,
|
||||
select.ApplySelect,
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
),
|
||||
}
|
||||
@@ -28,5 +27,9 @@ async def to_code(config: ConfigType) -> None:
|
||||
hub = await cg.get_variable(config[CONF_LD2420_ID])
|
||||
selects = select.sub_selects(config, parent=hub)
|
||||
await selects(
|
||||
CONF_OPERATING_MODE, hub.set_operating_mode_select, options=CONF_SELECTS
|
||||
CONF_OPERATING_MODE,
|
||||
hub.set_operating_mode_select,
|
||||
options=CONF_SELECTS,
|
||||
apply="set_operating_mode(entity->option_at(index))",
|
||||
publish="before",
|
||||
)
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
#include "operating_mode_select.h"
|
||||
#include "esphome/core/helpers.h"
|
||||
#include "esphome/core/log.h"
|
||||
|
||||
namespace esphome::ld2420 {
|
||||
|
||||
ESPHOME_LOG_TAG(TAG, "ld2420.select");
|
||||
|
||||
void LD2420Select::control(size_t index) {
|
||||
this->publish_state(index);
|
||||
this->parent_->set_operating_mode(this->option_at(index));
|
||||
}
|
||||
|
||||
} // namespace esphome::ld2420
|
||||
@@ -1,16 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "../ld2420.h"
|
||||
#include "esphome/components/select/select.h"
|
||||
|
||||
namespace esphome::ld2420 {
|
||||
|
||||
class LD2420Select final : public Component, public select::Select, public Parented<LD2420Component> {
|
||||
public:
|
||||
LD2420Select() = default;
|
||||
|
||||
protected:
|
||||
void control(size_t index) override;
|
||||
};
|
||||
|
||||
} // namespace esphome::ld2420
|
||||
@@ -13,22 +13,19 @@ from esphome.const import (
|
||||
)
|
||||
from esphome.types import ConfigType
|
||||
|
||||
from .. import CONF_LD2450_ID, LD2450Component, ld2450_ns
|
||||
|
||||
FactoryResetButton = ld2450_ns.class_("FactoryResetButton", button.Button)
|
||||
RestartButton = ld2450_ns.class_("RestartButton", button.Button)
|
||||
from .. import CONF_LD2450_ID, LD2450Component
|
||||
|
||||
CONFIG_SCHEMA = {
|
||||
cv.GenerateID(CONF_ID): cv.declare_id(cg.EntityBase),
|
||||
cv.GenerateID(CONF_LD2450_ID): cv.use_id(LD2450Component),
|
||||
cv.Optional(CONF_FACTORY_RESET): button.button_schema(
|
||||
FactoryResetButton,
|
||||
button.ApplyButton,
|
||||
device_class=DEVICE_CLASS_RESTART,
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
icon=ICON_RESTART_ALERT,
|
||||
),
|
||||
cv.Optional(CONF_RESTART): button.button_schema(
|
||||
RestartButton,
|
||||
button.ApplyButton,
|
||||
device_class=DEVICE_CLASS_RESTART,
|
||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
icon=ICON_RESTART,
|
||||
@@ -39,5 +36,9 @@ CONFIG_SCHEMA = {
|
||||
async def to_code(config: ConfigType) -> None:
|
||||
hub = await cg.get_variable(config[CONF_LD2450_ID])
|
||||
buttons = button.sub_buttons(config, parent=hub)
|
||||
await buttons(CONF_FACTORY_RESET, hub.set_factory_reset_button)
|
||||
await buttons(CONF_RESTART, hub.set_restart_button)
|
||||
await buttons(
|
||||
CONF_FACTORY_RESET, hub.set_factory_reset_button, apply="factory_reset()"
|
||||
)
|
||||
await buttons(
|
||||
CONF_RESTART, hub.set_restart_button, apply="restart_and_read_all_info()"
|
||||
)
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
#include "factory_reset_button.h"
|
||||
|
||||
namespace esphome::ld2450 {
|
||||
|
||||
void FactoryResetButton::press_action() { this->parent_->factory_reset(); }
|
||||
|
||||
} // namespace esphome::ld2450
|
||||
@@ -1,17 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/components/button/button.h"
|
||||
#include "../ld2450.h"
|
||||
|
||||
namespace esphome::ld2450 {
|
||||
|
||||
class FactoryResetButton : public button::Button, public Parented<LD2450Component> {
|
||||
public:
|
||||
// User provided, not "= default": `new(p) FactoryResetButton()` would zero-fill .bss that is already zero.
|
||||
FactoryResetButton() {}
|
||||
|
||||
protected:
|
||||
void press_action() override;
|
||||
};
|
||||
|
||||
} // namespace esphome::ld2450
|
||||
@@ -1,7 +0,0 @@
|
||||
#include "restart_button.h"
|
||||
|
||||
namespace esphome::ld2450 {
|
||||
|
||||
void RestartButton::press_action() { this->parent_->restart_and_read_all_info(); }
|
||||
|
||||
} // namespace esphome::ld2450
|
||||
@@ -1,17 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/components/button/button.h"
|
||||
#include "../ld2450.h"
|
||||
|
||||
namespace esphome::ld2450 {
|
||||
|
||||
class RestartButton : public button::Button, public Parented<LD2450Component> {
|
||||
public:
|
||||
// User provided, not "= default": `new(p) RestartButton()` would zero-fill .bss that is already zero.
|
||||
RestartButton() {}
|
||||
|
||||
protected:
|
||||
void press_action() override;
|
||||
};
|
||||
|
||||
} // namespace esphome::ld2450
|
||||
@@ -24,7 +24,6 @@ ICON_ARROW_TOP_LEFT = "mdi:arrow-top-left"
|
||||
ICON_ARROW_TOP_LEFT_BOLD_BOX_OUTLINE = "mdi:arrow-top-left-bold-box-outline"
|
||||
MAX_ZONES = 3
|
||||
|
||||
PresenceTimeoutNumber = ld2450_ns.class_("PresenceTimeoutNumber", number.Number)
|
||||
ZoneCoordinateNumber = ld2450_ns.class_("ZoneCoordinateNumber", number.Number)
|
||||
|
||||
CONFIG_SCHEMA = cv.Schema(
|
||||
@@ -32,7 +31,7 @@ CONFIG_SCHEMA = cv.Schema(
|
||||
cv.GenerateID(CONF_ID): cv.declare_id(cg.EntityBase),
|
||||
cv.GenerateID(CONF_LD2450_ID): cv.use_id(LD2450Component),
|
||||
cv.Required(CONF_PRESENCE_TIMEOUT): number.number_schema(
|
||||
PresenceTimeoutNumber,
|
||||
number.ApplyNumber,
|
||||
unit_of_measurement=UNIT_SECOND,
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
icon=ICON_TIMELAPSE,
|
||||
@@ -88,6 +87,8 @@ async def to_code(config: ConfigType) -> None:
|
||||
min_value=0,
|
||||
max_value=3600,
|
||||
step=1,
|
||||
apply="set_presence_timeout()",
|
||||
publish="before",
|
||||
)
|
||||
for zone_num in range(MAX_ZONES):
|
||||
if zone_conf := config.get(f"zone_{zone_num + 1}"):
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
#include "presence_timeout_number.h"
|
||||
|
||||
namespace esphome::ld2450 {
|
||||
|
||||
void PresenceTimeoutNumber::control(float value) {
|
||||
this->publish_state(value);
|
||||
this->parent_->set_presence_timeout();
|
||||
}
|
||||
|
||||
} // namespace esphome::ld2450
|
||||
@@ -1,17 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/components/number/number.h"
|
||||
#include "../ld2450.h"
|
||||
|
||||
namespace esphome::ld2450 {
|
||||
|
||||
class PresenceTimeoutNumber : public number::Number, public Parented<LD2450Component> {
|
||||
public:
|
||||
// User provided, not "= default": `new(p) PresenceTimeoutNumber()` would zero-fill .bss that is already zero.
|
||||
PresenceTimeoutNumber() {}
|
||||
|
||||
protected:
|
||||
void control(float value) override;
|
||||
};
|
||||
|
||||
} // namespace esphome::ld2450
|
||||
@@ -9,23 +9,21 @@ from esphome.const import (
|
||||
)
|
||||
from esphome.types import ConfigType
|
||||
|
||||
from .. import CONF_LD2450_ID, LD2450Component, ld2450_ns
|
||||
from .. import CONF_LD2450_ID, LD2450Component
|
||||
|
||||
CONF_ZONE_TYPE = "zone_type"
|
||||
|
||||
BaudRateSelect = ld2450_ns.class_("BaudRateSelect", select.Select)
|
||||
ZoneTypeSelect = ld2450_ns.class_("ZoneTypeSelect", select.Select)
|
||||
|
||||
CONFIG_SCHEMA = {
|
||||
cv.GenerateID(CONF_ID): cv.declare_id(cg.EntityBase),
|
||||
cv.GenerateID(CONF_LD2450_ID): cv.use_id(LD2450Component),
|
||||
cv.Optional(CONF_BAUD_RATE): select.select_schema(
|
||||
BaudRateSelect,
|
||||
select.ApplySelect,
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
icon=ICON_THERMOMETER,
|
||||
),
|
||||
cv.Optional(CONF_ZONE_TYPE): select.select_schema(
|
||||
ZoneTypeSelect,
|
||||
select.ApplySelect,
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
icon=ICON_THERMOMETER,
|
||||
),
|
||||
@@ -48,6 +46,8 @@ async def to_code(config: ConfigType) -> None:
|
||||
"256000",
|
||||
"460800",
|
||||
],
|
||||
apply="set_baud_rate(entity->option_at(index))",
|
||||
publish="before",
|
||||
)
|
||||
await selects(
|
||||
CONF_ZONE_TYPE,
|
||||
@@ -57,4 +57,6 @@ async def to_code(config: ConfigType) -> None:
|
||||
"Detection",
|
||||
"Filter",
|
||||
],
|
||||
apply="set_zone_type(entity->option_at(index))",
|
||||
publish="before",
|
||||
)
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
#include "baud_rate_select.h"
|
||||
|
||||
namespace esphome::ld2450 {
|
||||
|
||||
void BaudRateSelect::control(size_t index) {
|
||||
this->publish_state(index);
|
||||
this->parent_->set_baud_rate(this->option_at(index));
|
||||
}
|
||||
|
||||
} // namespace esphome::ld2450
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user