Compare commits

..
Author SHA1 Message Date
J. Nick Koston 9bc9fc1b9b Reuse the platform SubEntities for gate numbers and share the door command check
Gate thresholds go through numbers.create instead of a SubEntities per gate,
the hoermann_hcp buttons pass the hub id, and the one-shot door command tests
share one check.
2026-10-16 13:43:11 -10:00
J. Nick Koston 90cf7abbde Merge branch 'apply-entities' into apply-entities-migrate 2026-10-16 13:42:28 -10:00
J. Nick Koston b8a0de91db [core] Simplify the Apply entity helpers
Fold the function cache into SubEntities, make each domain's APPLY_ENTITY public,
shorten the class and docstring comments and reuse the shared test hub.
2026-10-16 13:42:23 -10:00
J. Nick Koston fb54defeda [ld2410] Warn when a threshold number matches no gate 2026-10-16 13:06:31 -10:00
J. Nick Koston e2d37f0d7e Merge branch 'apply-entities' into apply-entities-migrate 2026-10-16 12:20:54 -10:00
J. Nick Koston 2937d81216 Mark the test recorders as intentional mutable globals 2026-10-16 12:20:50 -10:00
J. Nick Koston 9d59415766 [hoermann_hcp] Move the door command tests next to the hub tests 2026-10-16 11:47:43 -10:00
J. Nick Koston 29ef01a207 Merge branch 'apply-entities' into apply-entities-migrate 2026-10-16 11:45:51 -10:00
J. Nick Koston 05a4b256db Reject an unknown publish= value 2026-10-16 11:45:47 -10:00
J. Nick Koston e8e98ee3db [ld2410] Find the gate from the number so all gate numbers share one class 2026-10-16 11:05:25 -10:00
J. Nick Koston 6aa647638c Merge branch 'apply-entities' into apply-entities-migrate 2026-10-16 11:04:41 -10:00
J. Nick Koston d0427c36eb [core] Share the apply function naming with automations and check the Apply class at codegen 2026-10-16 11:04:36 -10:00
J. Nick Koston e2c2fdfb3d [bq25186] Use Apply entities for the SHIP_RST buttons 2026-10-16 10:51:36 -10:00
J. Nick Koston 7425b8d3b1 [es8388] Use Apply entities for the line selects 2026-10-16 10:51:36 -10:00
J. Nick Koston 5f697bb0d6 [espectre] Use Apply entities for the recalibrate button and traffic select 2026-10-16 10:51:36 -10:00
J. Nick Koston 8f79467d5f [at581x] Use an Apply entity for the RF switch 2026-10-16 10:51:36 -10:00
J. Nick Koston 5ca927da8e [hoermann_hcp] Use Apply entities for the buttons 2026-10-16 10:48:32 -10:00
J. Nick Koston 776a7f68d8 [tfluna] Use Apply entities for the buttons 2026-10-16 10:48:31 -10:00
J. Nick Koston 87de7d679e [haier] Use Apply entities for the cleaning buttons and airflow selects 2026-10-16 10:48:31 -10:00
J. Nick Koston e75a10ec7d [seeed_mr24hpc1] Use Apply entities for the forwarding buttons, switch, numbers and selects 2026-10-16 10:48:31 -10:00
J. Nick Koston f0ea8edfad [seeed_mr60fda2] Use Apply entities for the forwarding buttons and selects 2026-10-16 10:48:31 -10:00
J. Nick Koston 5df5d44516 [ld2420] Use Apply entities for the forwarding buttons and select 2026-10-16 10:48:31 -10:00
J. Nick Koston dd59a827ff [ld2450] Use Apply entities for the forwarding buttons, switches, numbers and selects 2026-10-16 10:48:30 -10:00
J. Nick Koston ed9b566091 [ld2412] Use Apply entities for the forwarding buttons, switches, numbers and selects 2026-10-16 10:48:30 -10:00
J. Nick Koston 5fd7c33916 [ld2410] Use Apply entities for the forwarding buttons, switches, numbers and selects 2026-10-16 10:48:30 -10:00
J. Nick Koston a990231342 [core] Add Apply button, switch, number and select entities for hub forwarders 2026-10-16 10:48:29 -10:00
354 changed files with 2433 additions and 4080 deletions

No files matched your search

+1 -1
View File
@@ -27,7 +27,7 @@ jobs:
days-before-close: 7
stale-label: stale
exempt-label: not-stale
conflict-label: has-conflicts
conflict-label: needs-rebase
ignored-users: esphbot,codecov-commenter
stale-pr-message: >
There hasn't been any activity on this pull request recently. This
+11 -3
View File
@@ -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,
@@ -19,7 +19,11 @@ AbsoluteHumidityComponent = absolute_humidity_ns.class_(
SaturationVaporPressureEquation = absolute_humidity_ns.enum(
"SaturationVaporPressureEquation"
)
EQUATION = SaturationVaporPressureEquation.options("BUCK", "TETENS", "WOBUS")
EQUATION = {
"BUCK": SaturationVaporPressureEquation.BUCK,
"TETENS": SaturationVaporPressureEquation.TETENS,
"WOBUS": SaturationVaporPressureEquation.WOBUS,
}
CONFIG_SCHEMA = (
sensor.sensor_schema(
+5 -3
View File
@@ -14,9 +14,11 @@ ac_dimmer_ns = cg.esphome_ns.namespace("ac_dimmer")
AcDimmer = ac_dimmer_ns.class_("AcDimmer", output.FloatOutput, cg.Component)
DimMethod = ac_dimmer_ns.enum("DimMethod")
DIM_METHODS = DimMethod.options(
"LEADING_PULSE", "LEADING", "TRAILING", prefix="DIM_METHOD_"
)
DIM_METHODS = {
"LEADING_PULSE": DimMethod.DIM_METHOD_LEADING_PULSE,
"LEADING": DimMethod.DIM_METHOD_LEADING,
"TRAILING": DimMethod.DIM_METHOD_TRAILING,
}
ZC_INTERRUPT_TYPES = {
"RISING": gpio_ns.INTERRUPT_RISING_EDGE,
+5 -1
View File
@@ -46,7 +46,11 @@ ATTENUATION_MODES = {
sampling_mode = adc_ns.enum("SamplingMode", is_class=True)
SAMPLING_MODES = sampling_mode.options("avg", "min", "max")
SAMPLING_MODES = {
"avg": sampling_mode.AVG,
"min": sampling_mode.MIN,
"max": sampling_mode.MAX,
}
adc_unit_t = cg.global_ns.enum("adc_unit_t", is_class=True)
+7 -1
View File
@@ -11,6 +11,12 @@
namespace esphome::ade7880 {
// adapted from https://stackoverflow.com/a/55912127/1886371
template<size_t Bits, typename T> inline T sign_extend(const T &v) noexcept {
using S = struct { signed Val : Bits; };
return reinterpret_cast<const S *>(&v)->Val;
}
// Register types
// unsigned 8-bit (uint8_t)
// signed 10-bit - 16-bit ZP on wire (int16_t, needs sign extension)
@@ -43,7 +49,7 @@ uint16_t ADE7880::read_u16_register16_(uint16_t a_register) {
int32_t ADE7880::read_s24zp_register16_(uint16_t a_register) {
// s24zp means 24 bit signed value in the lower 24 bits of a 32-bit register
uint32_t in;
int32_t in;
this->read_register16(a_register, reinterpret_cast<uint8_t *>(&in), sizeof(in));
return sign_extend<24>(convert_big_endian(in));
}
+5 -3
View File
@@ -84,9 +84,11 @@ automation.register_apply_action(
)
AGS10SetZeroPointActionMode = ags10_ns.enum("AGS10SetZeroPointActionMode")
AGS10_SET_ZERO_POINT_ACTION_MODE = AGS10SetZeroPointActionMode.options(
"FACTORY_DEFAULT", "CURRENT_VALUE", "CUSTOM_VALUE"
)
AGS10_SET_ZERO_POINT_ACTION_MODE = {
"FACTORY_DEFAULT": AGS10SetZeroPointActionMode.FACTORY_DEFAULT,
"CURRENT_VALUE": AGS10SetZeroPointActionMode.CURRENT_VALUE,
"CUSTOM_VALUE": AGS10SetZeroPointActionMode.CUSTOM_VALUE,
}
AGS10_SET_ZERO_POINT_SCHEMA = cv.Schema(
{
+4 -1
View File
@@ -20,7 +20,10 @@ aht10_ns = cg.esphome_ns.namespace("aht10")
AHT10Component = aht10_ns.class_("AHT10Component", cg.PollingComponent, i2c.I2CDevice)
AHT10Variant = aht10_ns.enum("AHT10Variant")
AHT10_VARIANTS = AHT10Variant.options("AHT10", "AHT20")
AHT10_VARIANTS = {
"AHT10": AHT10Variant.AHT10,
"AHT20": AHT10Variant.AHT20,
}
CONFIG_SCHEMA = (
cv.Schema(
@@ -29,7 +29,10 @@ AirthingsWavePlus = airthings_wave_plus_ns.class_(
CONF_DEVICE_TYPE = "device_type"
WaveDeviceType = airthings_wave_plus_ns.enum("WaveDeviceType")
DEVICE_TYPES = WaveDeviceType.options("WAVE_PLUS", "WAVE_GEN2")
DEVICE_TYPES = {
"WAVE_PLUS": WaveDeviceType.WAVE_PLUS,
"WAVE_GEN2": WaveDeviceType.WAVE_GEN2,
}
def validate_wave_gen2_config(config: ConfigType) -> ConfigType:
+4 -1
View File
@@ -30,7 +30,10 @@ CONF_END_POSITION = "end_position"
CONF_OUT_OF_RANGE_MODE = "out_of_range_mode"
OutOfRangeMode = as5600_ns.enum("OutRangeMode")
OUT_OF_RANGE_MODES = OutOfRangeMode.options("MIN_MAX", "NAN", prefix="OUT_RANGE_MODE_")
OUT_OF_RANGE_MODES = {
"MIN_MAX": OutOfRangeMode.OUT_RANGE_MODE_MIN_MAX,
"NAN": OutOfRangeMode.OUT_RANGE_MODE_NAN,
}
CONF_AS5600_ID = "as5600_id"
+6 -3
View File
@@ -55,9 +55,12 @@ GAINS_41 = {
GAINS_43 = {**GAINS_41, "X1024": Gain.GAIN_1024X, "X2048": Gain.GAIN_2048X}
Normalization = as734x_ns.enum("Normalization", True)
NORMALIZATIONS = Normalization.options(
"NONE", "ALL", "BANDS", "CLEAR", prefix="NORMALIZATION_"
)
NORMALIZATIONS = {
"NONE": Normalization.NORMALIZATION_NONE,
"ALL": Normalization.NORMALIZATION_ALL,
"BANDS": Normalization.NORMALIZATION_BANDS,
"CLEAR": Normalization.NORMALIZATION_CLEAR,
}
# Per-channel correction for the golden device, measured by the manufacturer.
DEFAULT_CHANNEL_CORRECTION_43 = [
+6 -7
View File
@@ -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
+7 -1
View File
@@ -27,7 +27,13 @@ audio_ns = cg.esphome_ns.namespace("audio")
AudioFile = audio_ns.struct("AudioFile")
AudioFileType = audio_ns.enum("AudioFileType", is_class=True)
AUDIO_FILE_TYPE_ENUM = AudioFileType.options("NONE", "WAV", "MP3", "FLAC", "OPUS")
AUDIO_FILE_TYPE_ENUM = {
"NONE": AudioFileType.NONE,
"WAV": AudioFileType.WAV,
"MP3": AudioFileType.MP3,
"FLAC": AudioFileType.FLAC,
"OPUS": AudioFileType.OPUS,
}
MEMORY_PSRAM = "psram"
MEMORY_INTERNAL = "internal"
@@ -12,10 +12,14 @@ DEPENDENCIES = ["bedjet"]
BedJetClimate = bedjet_ns.class_("BedJetClimate", climate.Climate, cg.PollingComponent)
BedjetHeatMode = bedjet_ns.enum("BedjetHeatMode")
BedjetTemperatureSource = bedjet_ns.enum("BedjetTemperatureSource")
BEDJET_HEAT_MODES = BedjetHeatMode.options("heat", "extended", prefix="HEAT_MODE_")
BEDJET_TEMPERATURE_SOURCES = BedjetTemperatureSource.options(
"outlet", "ambient", prefix="TEMPERATURE_SOURCE_"
)
BEDJET_HEAT_MODES = {
"heat": BedjetHeatMode.HEAT_MODE_HEAT,
"extended": BedjetHeatMode.HEAT_MODE_EXTENDED,
}
BEDJET_TEMPERATURE_SOURCES = {
"outlet": BedjetTemperatureSource.TEMPERATURE_SOURCE_OUTLET,
"ambient": BedjetTemperatureSource.TEMPERATURE_SOURCE_AMBIENT,
}
CONFIG_SCHEMA = (
climate.climate_schema(BedJetClimate)
+5 -1
View File
@@ -25,7 +25,11 @@ BH1745Component = bh1745_ns.class_(
)
AdcGain = bh1745_ns.enum("AdcGain", is_class=True)
ADC_GAINS = AdcGain.options("1X", "2X", "16X", prefix="ADC_GAIN_")
ADC_GAINS = {
"1X": AdcGain.ADC_GAIN_1X,
"2X": AdcGain.ADC_GAIN_2X,
"16X": AdcGain.ADC_GAIN_16X,
}
MeasurementTime = bh1745_ns.enum("MeasurementTime", is_class=True)
MEASUREMENT_TIMES = {
+4 -3
View File
@@ -35,9 +35,10 @@ CONF_ENERGY_TOTAL = "energy_total"
bl0939_ns = cg.esphome_ns.namespace("bl0939")
BL0939 = bl0939_ns.class_("BL0939", cg.PollingComponent, uart.UARTDevice)
BL0939Mode = bl0939_ns.enum("BL0939Mode", is_class=True)
MODE_OPTIONS = BL0939Mode.options(
"direct", "current_transformer", prefix="BL0939_MODE_"
)
MODE_OPTIONS = {
"direct": BL0939Mode.BL0939_MODE_DIRECT,
"current_transformer": BL0939Mode.BL0939_MODE_CURRENT_TRANSFORMER,
}
# Must match the mode_ member initializer in bl0939.h; set_mode() is skipped
# when the config already equals it.
DEFAULT_MODE = "direct"
+15 -6
View File
@@ -24,14 +24,23 @@ DOMAIN = "bme280_base"
bme280_ns = cg.esphome_ns.namespace("bme280_base")
BME280Oversampling = bme280_ns.enum("BME280Oversampling")
OVERSAMPLING_OPTIONS = BME280Oversampling.options(
"NONE", "1X", "2X", "4X", "8X", "16X", prefix="BME280_OVERSAMPLING_"
)
OVERSAMPLING_OPTIONS = {
"NONE": BME280Oversampling.BME280_OVERSAMPLING_NONE,
"1X": BME280Oversampling.BME280_OVERSAMPLING_1X,
"2X": BME280Oversampling.BME280_OVERSAMPLING_2X,
"4X": BME280Oversampling.BME280_OVERSAMPLING_4X,
"8X": BME280Oversampling.BME280_OVERSAMPLING_8X,
"16X": BME280Oversampling.BME280_OVERSAMPLING_16X,
}
BME280IIRFilter = bme280_ns.enum("BME280IIRFilter")
IIR_FILTER_OPTIONS = BME280IIRFilter.options(
"OFF", "2X", "4X", "8X", "16X", prefix="BME280_IIR_FILTER_"
)
IIR_FILTER_OPTIONS = {
"OFF": BME280IIRFilter.BME280_IIR_FILTER_OFF,
"2X": BME280IIRFilter.BME280_IIR_FILTER_2X,
"4X": BME280IIRFilter.BME280_IIR_FILTER_4X,
"8X": BME280IIRFilter.BME280_IIR_FILTER_8X,
"16X": BME280IIRFilter.BME280_IIR_FILTER_16X,
}
CONFIG_SCHEMA_BASE = cv.Schema(
{
@@ -3,7 +3,6 @@
#include "bme280_base.h"
#include "esphome/core/hal.h"
#include "esphome/core/helpers.h"
#include "esphome/core/log.h"
#include <esphome/components/sensor/sensor.h>
#include <esphome/core/component.h>
@@ -145,10 +144,11 @@ void BME280Component::setup() {
this->calibration_.h1 = read_u8_(BME280_REGISTER_DIG_H1);
this->calibration_.h2 = read_s16_le_(BME280_REGISTER_DIG_H2);
this->calibration_.h3 = read_u8_(BME280_REGISTER_DIG_H3);
this->calibration_.h4 =
sign_extend<12>(read_u8_(BME280_REGISTER_DIG_H4) << 4 | (read_u8_(BME280_REGISTER_DIG_H4 + 1) & 0x0F));
this->calibration_.h5 =
sign_extend<12>(read_u8_(BME280_REGISTER_DIG_H5 + 1) << 4 | (read_u8_(BME280_REGISTER_DIG_H5) >> 4));
// h4 and h5 are signed 12-bit values; shift left then arithmetic right shift to sign-extend
int16_t h4_raw = read_u8_(BME280_REGISTER_DIG_H4) << 4 | (read_u8_(BME280_REGISTER_DIG_H4 + 1) & 0x0F);
this->calibration_.h4 = static_cast<int16_t>(h4_raw << 4) >> 4;
int16_t h5_raw = read_u8_(BME280_REGISTER_DIG_H5 + 1) << 4 | (read_u8_(BME280_REGISTER_DIG_H5) >> 4);
this->calibration_.h5 = static_cast<int16_t>(h5_raw << 4) >> 4;
this->calibration_.h6 = read_u8_(BME280_REGISTER_DIG_H6);
uint8_t humid_control_val = 0;
+18 -6
View File
@@ -28,14 +28,26 @@ DEPENDENCIES = ["i2c"]
bme680_ns = cg.esphome_ns.namespace("bme680")
BME680Oversampling = bme680_ns.enum("BME680Oversampling")
OVERSAMPLING_OPTIONS = BME680Oversampling.options(
"NONE", "1X", "2X", "4X", "8X", "16X", prefix="BME680_OVERSAMPLING_"
)
OVERSAMPLING_OPTIONS = {
"NONE": BME680Oversampling.BME680_OVERSAMPLING_NONE,
"1X": BME680Oversampling.BME680_OVERSAMPLING_1X,
"2X": BME680Oversampling.BME680_OVERSAMPLING_2X,
"4X": BME680Oversampling.BME680_OVERSAMPLING_4X,
"8X": BME680Oversampling.BME680_OVERSAMPLING_8X,
"16X": BME680Oversampling.BME680_OVERSAMPLING_16X,
}
BME680IIRFilter = bme680_ns.enum("BME680IIRFilter")
IIR_FILTER_OPTIONS = BME680IIRFilter.options(
"OFF", "1X", "3X", "7X", "15X", "31X", "63X", "127X", prefix="BME680_IIR_FILTER_"
)
IIR_FILTER_OPTIONS = {
"OFF": BME680IIRFilter.BME680_IIR_FILTER_OFF,
"1X": BME680IIRFilter.BME680_IIR_FILTER_1X,
"3X": BME680IIRFilter.BME680_IIR_FILTER_3X,
"7X": BME680IIRFilter.BME680_IIR_FILTER_7X,
"15X": BME680IIRFilter.BME680_IIR_FILTER_15X,
"31X": BME680IIRFilter.BME680_IIR_FILTER_31X,
"63X": BME680IIRFilter.BME680_IIR_FILTER_63X,
"127X": BME680IIRFilter.BME680_IIR_FILTER_127X,
}
BME680Component = bme680_ns.class_(
"BME680Component", cg.PollingComponent, i2c.I2CDevice
+8 -2
View File
@@ -19,7 +19,10 @@ CONF_SUPPLY_VOLTAGE = "supply_voltage"
bme680_bsec_ns = cg.esphome_ns.namespace("bme680_bsec")
IAQMode = bme680_bsec_ns.enum("IAQMode")
IAQ_MODE_OPTIONS = IAQMode.options("STATIC", "MOBILE", prefix="IAQ_MODE_")
IAQ_MODE_OPTIONS = {
"STATIC": IAQMode.IAQ_MODE_STATIC,
"MOBILE": IAQMode.IAQ_MODE_MOBILE,
}
SupplyVoltage = bme680_bsec_ns.enum("SupplyVoltage")
SUPPLY_VOLTAGE_OPTIONS = {
@@ -28,7 +31,10 @@ SUPPLY_VOLTAGE_OPTIONS = {
}
SampleRate = bme680_bsec_ns.enum("SampleRate")
SAMPLE_RATE_OPTIONS = SampleRate.options("LP", "ULP", prefix="SAMPLE_RATE_")
SAMPLE_RATE_OPTIONS = {
"LP": SampleRate.SAMPLE_RATE_LP,
"ULP": SampleRate.SAMPLE_RATE_ULP,
}
BME680BSECComponent = bme680_bsec_ns.class_(
"BME680BSECComponent", cg.Component, i2c.I2CDevice
+16 -6
View File
@@ -36,18 +36,28 @@ BME68xBSEC2Component = bme68x_bsec2_ns.class_("BME68xBSEC2Component", cg.Compone
MODEL_OPTIONS = ["bme680", "bme688"]
AlgorithmOutput = bme68x_bsec2_ns.enum("AlgorithmOutput")
ALGORITHM_OUTPUT_OPTIONS = AlgorithmOutput.options(
"classification", "regression", prefix="ALGORITHM_OUTPUT_"
)
ALGORITHM_OUTPUT_OPTIONS = {
"classification": AlgorithmOutput.ALGORITHM_OUTPUT_CLASSIFICATION,
"regression": AlgorithmOutput.ALGORITHM_OUTPUT_REGRESSION,
}
OperatingAge = bme68x_bsec2_ns.enum("OperatingAge")
OPERATING_AGE_OPTIONS = OperatingAge.options("4d", "28d", prefix="OPERATING_AGE_")
OPERATING_AGE_OPTIONS = {
"4d": OperatingAge.OPERATING_AGE_4D,
"28d": OperatingAge.OPERATING_AGE_28D,
}
SampleRate = bme68x_bsec2_ns.enum("SampleRate")
SAMPLE_RATE_OPTIONS = SampleRate.options("LP", "ULP", prefix="SAMPLE_RATE_")
SAMPLE_RATE_OPTIONS = {
"LP": SampleRate.SAMPLE_RATE_LP,
"ULP": SampleRate.SAMPLE_RATE_ULP,
}
Voltage = bme68x_bsec2_ns.enum("Voltage")
VOLTAGE_OPTIONS = Voltage.options("1.8V", "3.3V", prefix="VOLTAGE_")
VOLTAGE_OPTIONS = {
"1.8V": Voltage.VOLTAGE_1_8V,
"3.3V": Voltage.VOLTAGE_3_3V,
}
ALGORITHM_OUTPUT_FILE_NAME = {
"classification": "sel",
+6 -3
View File
@@ -20,9 +20,12 @@ CONF_AUX_DEVICE = "aux_device"
# Enum proxies (must match the C++ enum values exactly)
BMI270AuxDevice = bmi270_ns.enum("BMI270AuxDevice")
BMI270AccelRange = bmi270_ns.enum("BMI270AccelRange")
ACCEL_RANGE_OPTIONS = BMI270AccelRange.options(
"2G", "4G", "8G", "16G", prefix="BMI270_ACCEL_RANGE_"
)
ACCEL_RANGE_OPTIONS = {
"2G": BMI270AccelRange.BMI270_ACCEL_RANGE_2G,
"4G": BMI270AccelRange.BMI270_ACCEL_RANGE_4G,
"8G": BMI270AccelRange.BMI270_ACCEL_RANGE_8G,
"16G": BMI270AccelRange.BMI270_ACCEL_RANGE_16G,
}
BMI270GyroRange = bmi270_ns.enum("BMI270GyroRange")
GYRO_RANGE_OPTIONS = {
+15 -6
View File
@@ -21,14 +21,23 @@ DOMAIN = "bmp280_base"
bmp280_ns = cg.esphome_ns.namespace("bmp280_base")
BMP280Oversampling = bmp280_ns.enum("BMP280Oversampling")
OVERSAMPLING_OPTIONS = BMP280Oversampling.options(
"NONE", "1X", "2X", "4X", "8X", "16X", prefix="BMP280_OVERSAMPLING_"
)
OVERSAMPLING_OPTIONS = {
"NONE": BMP280Oversampling.BMP280_OVERSAMPLING_NONE,
"1X": BMP280Oversampling.BMP280_OVERSAMPLING_1X,
"2X": BMP280Oversampling.BMP280_OVERSAMPLING_2X,
"4X": BMP280Oversampling.BMP280_OVERSAMPLING_4X,
"8X": BMP280Oversampling.BMP280_OVERSAMPLING_8X,
"16X": BMP280Oversampling.BMP280_OVERSAMPLING_16X,
}
BMP280IIRFilter = bmp280_ns.enum("BMP280IIRFilter")
IIR_FILTER_OPTIONS = BMP280IIRFilter.options(
"OFF", "2X", "4X", "8X", "16X", prefix="BMP280_IIR_FILTER_"
)
IIR_FILTER_OPTIONS = {
"OFF": BMP280IIRFilter.BMP280_IIR_FILTER_OFF,
"2X": BMP280IIRFilter.BMP280_IIR_FILTER_2X,
"4X": BMP280IIRFilter.BMP280_IIR_FILTER_4X,
"8X": BMP280IIRFilter.BMP280_IIR_FILTER_8X,
"16X": BMP280IIRFilter.BMP280_IIR_FILTER_16X,
}
CONFIG_SCHEMA_BASE = cv.Schema(
{
@@ -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
+4 -7
View File
@@ -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})")
+7 -2
View File
@@ -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(
+10
View File
@@ -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
+23 -24
View File
@@ -56,30 +56,29 @@ CanbusTrigger = canbus_ns.class_(
)
CanSpeed = canbus_ns.enum("CAN_SPEED")
CAN_SPEEDS = CanSpeed.options(
"1KBPS",
"5KBPS",
"10KBPS",
"12K5BPS",
"16KBPS",
"20KBPS",
"25KBPS",
"31K25BPS",
"33KBPS",
"40KBPS",
"50KBPS",
"80KBPS",
"83K3BPS",
"95KBPS",
"100KBPS",
"125KBPS",
"200KBPS",
"250KBPS",
"500KBPS",
"800KBPS",
"1000KBPS",
prefix="CAN_",
)
CAN_SPEEDS = {
"1KBPS": CanSpeed.CAN_1KBPS,
"5KBPS": CanSpeed.CAN_5KBPS,
"10KBPS": CanSpeed.CAN_10KBPS,
"12K5BPS": CanSpeed.CAN_12K5BPS,
"16KBPS": CanSpeed.CAN_16KBPS,
"20KBPS": CanSpeed.CAN_20KBPS,
"25KBPS": CanSpeed.CAN_25KBPS,
"31K25BPS": CanSpeed.CAN_31K25BPS,
"33KBPS": CanSpeed.CAN_33KBPS,
"40KBPS": CanSpeed.CAN_40KBPS,
"50KBPS": CanSpeed.CAN_50KBPS,
"80KBPS": CanSpeed.CAN_80KBPS,
"83K3BPS": CanSpeed.CAN_83K3BPS,
"95KBPS": CanSpeed.CAN_95KBPS,
"100KBPS": CanSpeed.CAN_100KBPS,
"125KBPS": CanSpeed.CAN_125KBPS,
"200KBPS": CanSpeed.CAN_200KBPS,
"250KBPS": CanSpeed.CAN_250KBPS,
"500KBPS": CanSpeed.CAN_500KBPS,
"800KBPS": CanSpeed.CAN_800KBPS,
"1000KBPS": CanSpeed.CAN_1000KBPS,
}
def get_rate(value: str) -> int:
+83 -32
View File
@@ -67,30 +67,41 @@ CONF_GDO0_PIN = "gdo0_pin"
# Enums
SyncMode = ns.enum("SyncMode", True)
SYNC_MODE = SyncMode.options("None", "15/16", "16/16", "30/32", prefix="SYNC_MODE_")
SYNC_MODE = {
"None": SyncMode.SYNC_MODE_NONE,
"15/16": SyncMode.SYNC_MODE_15_16,
"16/16": SyncMode.SYNC_MODE_16_16,
"30/32": SyncMode.SYNC_MODE_30_32,
}
Modulation = ns.enum("Modulation", True)
MODULATION = Modulation.options(
"2-FSK", "GFSK", "ASK/OOK", "4-FSK", "MSK", prefix="MODULATION_"
)
MODULATION = {
"2-FSK": Modulation.MODULATION_2_FSK,
"GFSK": Modulation.MODULATION_GFSK,
"ASK/OOK": Modulation.MODULATION_ASK_OOK,
"4-FSK": Modulation.MODULATION_4_FSK,
"MSK": Modulation.MODULATION_MSK,
}
RxAttenuation = ns.enum("RxAttenuation", True)
RX_ATTENUATION = RxAttenuation.options(
"0dB", "6dB", "12dB", "18dB", prefix="RX_ATTENUATION_"
)
RX_ATTENUATION = {
"0dB": RxAttenuation.RX_ATTENUATION_0DB,
"6dB": RxAttenuation.RX_ATTENUATION_6DB,
"12dB": RxAttenuation.RX_ATTENUATION_12DB,
"18dB": RxAttenuation.RX_ATTENUATION_18DB,
}
MagnTarget = ns.enum("MagnTarget", True)
MAGN_TARGET = MagnTarget.options(
"24dB",
"27dB",
"30dB",
"33dB",
"36dB",
"38dB",
"40dB",
"42dB",
prefix="MAGN_TARGET_",
)
MAGN_TARGET = {
"24dB": MagnTarget.MAGN_TARGET_24DB,
"27dB": MagnTarget.MAGN_TARGET_27DB,
"30dB": MagnTarget.MAGN_TARGET_30DB,
"33dB": MagnTarget.MAGN_TARGET_33DB,
"36dB": MagnTarget.MAGN_TARGET_36DB,
"38dB": MagnTarget.MAGN_TARGET_38DB,
"40dB": MagnTarget.MAGN_TARGET_40DB,
"42dB": MagnTarget.MAGN_TARGET_42DB,
}
MaxLnaGain = ns.enum("MaxLnaGain", True)
MAX_LNA_GAIN = {
@@ -129,14 +140,20 @@ FILTER_LENGTH_FSK_MSK = {
}
FilterLengthAskOok = ns.enum("FilterLengthAskOok", True)
FILTER_LENGTH_ASK_OOK = FilterLengthAskOok.options(
"4dB", "8dB", "12dB", "16dB", prefix="FILTER_LENGTH_"
)
FILTER_LENGTH_ASK_OOK = {
"4dB": FilterLengthAskOok.FILTER_LENGTH_4DB,
"8dB": FilterLengthAskOok.FILTER_LENGTH_8DB,
"12dB": FilterLengthAskOok.FILTER_LENGTH_12DB,
"16dB": FilterLengthAskOok.FILTER_LENGTH_16DB,
}
Freeze = ns.enum("Freeze", True)
FREEZE = Freeze.options(
"Default", "On Sync", "Analog Only", "Analog And Digital", prefix="FREEZE_"
)
FREEZE = {
"Default": Freeze.FREEZE_DEFAULT,
"On Sync": Freeze.FREEZE_ON_SYNC,
"Analog Only": Freeze.FREEZE_ANALOG_ONLY,
"Analog And Digital": Freeze.FREEZE_ANALOG_AND_DIGITAL,
}
WaitTime = ns.enum("WaitTime", True)
WAIT_TIME = {
@@ -147,16 +164,34 @@ WAIT_TIME = {
}
HystLevel = ns.enum("HystLevel", True)
HYST_LEVEL = HystLevel.options("None", "Low", "Medium", "High", prefix="HYST_LEVEL_")
HYST_LEVEL = {
"None": HystLevel.HYST_LEVEL_NONE,
"Low": HystLevel.HYST_LEVEL_LOW,
"Medium": HystLevel.HYST_LEVEL_MEDIUM,
"High": HystLevel.HYST_LEVEL_HIGH,
}
FocLimit = ns.enum("FocLimit", True)
FOC_LIMIT = FocLimit.options("Disabled", "BW/8", "BW/4", "BW/2", prefix="FOC_LIMIT_")
FOC_LIMIT = {
"Disabled": FocLimit.FOC_LIMIT_DISABLED,
"BW/8": FocLimit.FOC_LIMIT_BW_8,
"BW/4": FocLimit.FOC_LIMIT_BW_4,
"BW/2": FocLimit.FOC_LIMIT_BW_2,
}
FocPreK = ns.enum("FocPreK", True)
FOC_PRE_K = FocPreK.options("K", "2K", "3K", "4K", prefix="FOC_PRE_K_")
FOC_PRE_K = {
"K": FocPreK.FOC_PRE_K_K,
"2K": FocPreK.FOC_PRE_K_2K,
"3K": FocPreK.FOC_PRE_K_3K,
"4K": FocPreK.FOC_PRE_K_4K,
}
FocPostK = ns.enum("FocPostK", True)
FOC_POST_K = FocPostK.options("Same", "K/2", prefix="FOC_POST_K_")
FOC_POST_K = {
"Same": FocPostK.FOC_POST_K_SAME,
"K/2": FocPostK.FOC_POST_K_K_2,
}
BsLimit = ns.enum("BsLimit", True)
BS_LIMIT = {
@@ -167,16 +202,32 @@ BS_LIMIT = {
}
BsPreKi = ns.enum("BsPreKi", True)
BS_PRE_KI = BsPreKi.options("KI", "2KI", "3KI", "4KI", prefix="BS_PRE_KI_")
BS_PRE_KI = {
"KI": BsPreKi.BS_PRE_KI_KI,
"2KI": BsPreKi.BS_PRE_KI_2KI,
"3KI": BsPreKi.BS_PRE_KI_3KI,
"4KI": BsPreKi.BS_PRE_KI_4KI,
}
BsPreKp = ns.enum("BsPreKp", True)
BS_PRE_KP = BsPreKp.options("KP", "2KP", "3KP", "4KP", prefix="BS_PRE_KP_")
BS_PRE_KP = {
"KP": BsPreKp.BS_PRE_KP_KP,
"2KP": BsPreKp.BS_PRE_KP_2KP,
"3KP": BsPreKp.BS_PRE_KP_3KP,
"4KP": BsPreKp.BS_PRE_KP_4KP,
}
BsPostKi = ns.enum("BsPostKi", True)
BS_POST_KI = BsPostKi.options("Same", "KI/2", prefix="BS_POST_KI_")
BS_POST_KI = {
"Same": BsPostKi.BS_POST_KI_SAME,
"KI/2": BsPostKi.BS_POST_KI_KI_2,
}
BsPostKp = ns.enum("BsPostKp", True)
BS_POST_KP = BsPostKp.options("Same", "KP", prefix="BS_POST_KP_")
BS_POST_KP = {
"Same": BsPostKp.BS_POST_KP_SAME,
"KP": BsPostKp.BS_POST_KP_KP,
}
# Optional settings to generate setter calls for
CONFIG_MAP = {
+46 -47
View File
@@ -69,68 +69,67 @@ ClimateCall = climate_ns.class_("ClimateCall")
ClimateTraits = climate_ns.class_("ClimateTraits")
ClimateMode = climate_ns.enum("ClimateMode")
CLIMATE_MODES = ClimateMode.options(
"OFF",
"HEAT_COOL",
"COOL",
"HEAT",
"DRY",
"FAN_ONLY",
"AUTO",
prefix="CLIMATE_MODE_",
)
CLIMATE_MODES = {
"OFF": ClimateMode.CLIMATE_MODE_OFF,
"HEAT_COOL": ClimateMode.CLIMATE_MODE_HEAT_COOL,
"COOL": ClimateMode.CLIMATE_MODE_COOL,
"HEAT": ClimateMode.CLIMATE_MODE_HEAT,
"DRY": ClimateMode.CLIMATE_MODE_DRY,
"FAN_ONLY": ClimateMode.CLIMATE_MODE_FAN_ONLY,
"AUTO": ClimateMode.CLIMATE_MODE_AUTO,
}
validate_climate_mode = cv.enum(CLIMATE_MODES, upper=True)
ClimateFanMode = climate_ns.enum("ClimateFanMode")
CLIMATE_FAN_MODES = ClimateFanMode.options(
"ON",
"OFF",
"AUTO",
"LOW",
"MEDIUM",
"HIGH",
"MIDDLE",
"FOCUS",
"DIFFUSE",
"QUIET",
prefix="CLIMATE_FAN_",
)
CLIMATE_FAN_MODES = {
"ON": ClimateFanMode.CLIMATE_FAN_ON,
"OFF": ClimateFanMode.CLIMATE_FAN_OFF,
"AUTO": ClimateFanMode.CLIMATE_FAN_AUTO,
"LOW": ClimateFanMode.CLIMATE_FAN_LOW,
"MEDIUM": ClimateFanMode.CLIMATE_FAN_MEDIUM,
"HIGH": ClimateFanMode.CLIMATE_FAN_HIGH,
"MIDDLE": ClimateFanMode.CLIMATE_FAN_MIDDLE,
"FOCUS": ClimateFanMode.CLIMATE_FAN_FOCUS,
"DIFFUSE": ClimateFanMode.CLIMATE_FAN_DIFFUSE,
"QUIET": ClimateFanMode.CLIMATE_FAN_QUIET,
}
validate_climate_fan_mode = cv.enum(CLIMATE_FAN_MODES, upper=True)
ClimatePreset = climate_ns.enum("ClimatePreset")
CLIMATE_PRESETS = ClimatePreset.options(
"NONE",
"ECO",
"AWAY",
"BOOST",
"COMFORT",
"HOME",
"SLEEP",
"ACTIVITY",
prefix="CLIMATE_PRESET_",
)
CLIMATE_PRESETS = {
"NONE": ClimatePreset.CLIMATE_PRESET_NONE,
"ECO": ClimatePreset.CLIMATE_PRESET_ECO,
"AWAY": ClimatePreset.CLIMATE_PRESET_AWAY,
"BOOST": ClimatePreset.CLIMATE_PRESET_BOOST,
"COMFORT": ClimatePreset.CLIMATE_PRESET_COMFORT,
"HOME": ClimatePreset.CLIMATE_PRESET_HOME,
"SLEEP": ClimatePreset.CLIMATE_PRESET_SLEEP,
"ACTIVITY": ClimatePreset.CLIMATE_PRESET_ACTIVITY,
}
validate_climate_preset = cv.enum(CLIMATE_PRESETS, upper=True)
ClimateSwingMode = climate_ns.enum("ClimateSwingMode")
CLIMATE_SWING_MODES = ClimateSwingMode.options(
"OFF", "BOTH", "VERTICAL", "HORIZONTAL", prefix="CLIMATE_SWING_"
)
CLIMATE_SWING_MODES = {
"OFF": ClimateSwingMode.CLIMATE_SWING_OFF,
"BOTH": ClimateSwingMode.CLIMATE_SWING_BOTH,
"VERTICAL": ClimateSwingMode.CLIMATE_SWING_VERTICAL,
"HORIZONTAL": ClimateSwingMode.CLIMATE_SWING_HORIZONTAL,
}
validate_climate_swing_mode = cv.enum(CLIMATE_SWING_MODES, upper=True)
ClimateAction = climate_ns.enum("ClimateAction")
CLIMATE_ACTIONS = ClimateAction.options(
"OFF",
"COOLING",
"HEATING",
"IDLE",
"DRYING",
"FAN",
"DEFROSTING",
prefix="CLIMATE_ACTION_",
)
CLIMATE_ACTIONS = {
"OFF": ClimateAction.CLIMATE_ACTION_OFF,
"COOLING": ClimateAction.CLIMATE_ACTION_COOLING,
"HEATING": ClimateAction.CLIMATE_ACTION_HEATING,
"IDLE": ClimateAction.CLIMATE_ACTION_IDLE,
"DRYING": ClimateAction.CLIMATE_ACTION_DRYING,
"FAN": ClimateAction.CLIMATE_ACTION_FAN,
"DEFROSTING": ClimateAction.CLIMATE_ACTION_DEFROSTING,
}
validate_climate_action = cv.enum(CLIMATE_ACTIONS, upper=True)
+5 -3
View File
@@ -80,9 +80,11 @@ COVER_STATES = {
validate_cover_state = cv.enum(COVER_STATES, upper=True)
CoverOperation = cover_ns.enum("CoverOperation")
COVER_OPERATIONS = CoverOperation.options(
"IDLE", "OPENING", "CLOSING", prefix="COVER_OPERATION_"
)
COVER_OPERATIONS = {
"IDLE": CoverOperation.COVER_OPERATION_IDLE,
"OPENING": CoverOperation.COVER_OPERATION_OPENING,
"CLOSING": CoverOperation.COVER_OPERATION_CLOSING,
}
validate_cover_operation = cv.enum(COVER_OPERATIONS, upper=True)
# Actions
+1 -2
View File
@@ -1,5 +1,4 @@
#include "cs5460a.h"
#include "esphome/core/helpers.h"
#include "esphome/core/log.h"
namespace esphome::cs5460a {
@@ -305,7 +304,7 @@ bool CS5460AComponent::check_status_() {
voltage_sensor_->publish_state(raw_voltage * voltage_multiplier_);
if (power_sensor_ != nullptr && raw_energy != prev_raw_energy_) {
int32_t raw = sign_extend<24>(raw_energy);
int32_t raw = (int32_t) (raw_energy << 8) >> 8; /* Sign-extend */
power_sensor_->publish_state(raw * power_multiplier_);
prev_raw_energy_ = raw_energy;
}
+4 -1
View File
@@ -24,7 +24,10 @@ DEPENDENCIES = ["spi"]
cs5460a_ns = cg.esphome_ns.namespace("cs5460a")
CS5460APGAGain = cs5460a_ns.enum("CS5460APGAGain")
PGA_GAIN_OPTIONS = CS5460APGAGain.options("10X", "50X", prefix="CS5460A_PGA_GAIN_")
PGA_GAIN_OPTIONS = {
"10X": CS5460APGAGain.CS5460A_PGA_GAIN_10X,
"50X": CS5460APGAGain.CS5460A_PGA_GAIN_50X,
}
CS5460AComponent = cs5460a_ns.class_("CS5460AComponent", spi.SPIDevice, cg.Component)
+4 -3
View File
@@ -39,9 +39,10 @@ CONF_POWER_FACTOR_1 = "power_factor_1"
CONF_CURRENT_INPUT = "current_input"
CSE7761CurrentInput = cse7761_ns.enum("CSE7761CurrentInput", is_class=True)
CURRENT_INPUTS = CSE7761CurrentInput.options(
"shunt", "current_transformer", prefix="CSE7761_CURRENT_INPUT_"
)
CURRENT_INPUTS = {
"shunt": CSE7761CurrentInput.CSE7761_CURRENT_INPUT_SHUNT,
"current_transformer": CSE7761CurrentInput.CSE7761_CURRENT_INPUT_CURRENT_TRANSFORMER,
}
CONFIG_SCHEMA = (
cv.Schema(
+10 -6
View File
@@ -223,15 +223,19 @@ DeepSleepComponent = deep_sleep_ns.class_("DeepSleepComponent", cg.Component)
EnterDeepSleepAction = deep_sleep_ns.class_("EnterDeepSleepAction", automation.Action)
WakeupPinMode = deep_sleep_ns.enum("WakeupPinMode")
WAKEUP_PIN_MODES = WakeupPinMode.options(
"IGNORE", "KEEP_AWAKE", "INVERT_WAKEUP", prefix="WAKEUP_PIN_MODE_"
)
WAKEUP_PIN_MODES = {
"IGNORE": WakeupPinMode.WAKEUP_PIN_MODE_IGNORE,
"KEEP_AWAKE": WakeupPinMode.WAKEUP_PIN_MODE_KEEP_AWAKE,
"INVERT_WAKEUP": WakeupPinMode.WAKEUP_PIN_MODE_INVERT_WAKEUP,
}
esp_sleep_ext1_wakeup_mode_t = cg.global_ns.enum("esp_sleep_ext1_wakeup_mode_t")
Ext1Wakeup = deep_sleep_ns.struct("Ext1Wakeup")
EXT1_WAKEUP_MODES = esp_sleep_ext1_wakeup_mode_t.options(
"ANY_LOW", "ALL_LOW", "ANY_HIGH", prefix="ESP_EXT1_WAKEUP_"
)
EXT1_WAKEUP_MODES = {
"ANY_LOW": esp_sleep_ext1_wakeup_mode_t.ESP_EXT1_WAKEUP_ANY_LOW,
"ALL_LOW": esp_sleep_ext1_wakeup_mode_t.ESP_EXT1_WAKEUP_ALL_LOW,
"ANY_HIGH": esp_sleep_ext1_wakeup_mode_t.ESP_EXT1_WAKEUP_ANY_HIGH,
}
WakeupCauseToRunDuration = deep_sleep_ns.struct("WakeupCauseToRunDuration")
WakeupCause = deep_sleep_ns.enum("WakeupCause")
+12 -2
View File
@@ -21,9 +21,19 @@ CONF_EQ_PRESET = "eq_preset"
CONF_ON_FINISHED_PLAYBACK = "on_finished_playback"
EqPreset = dfplayer_ns.enum("EqPreset")
EQ_PRESET = EqPreset.options("NORMAL", "POP", "ROCK", "JAZZ", "CLASSIC", "BASS")
EQ_PRESET = {
"NORMAL": EqPreset.NORMAL,
"POP": EqPreset.POP,
"ROCK": EqPreset.ROCK,
"JAZZ": EqPreset.JAZZ,
"CLASSIC": EqPreset.CLASSIC,
"BASS": EqPreset.BASS,
}
Device = dfplayer_ns.enum("Device")
DEVICE = Device.options("USB", "TF_CARD")
DEVICE = {
"USB": Device.USB,
"TF_CARD": Device.TF_CARD,
}
CONFIG_SCHEMA = cv.All(
cv.Schema(
+10 -11
View File
@@ -19,17 +19,16 @@ from esphome.types import ConfigType
dht_ns = cg.esphome_ns.namespace("dht")
DHTModel = dht_ns.enum("DHTModel")
DHT_MODELS = DHTModel.options(
"AUTO_DETECT",
"DHT11",
"DHT22",
"AM2120",
"AM2302",
"RHT03",
"SI7021",
"DHT22_TYPE2",
prefix="DHT_MODEL_",
)
DHT_MODELS = {
"AUTO_DETECT": DHTModel.DHT_MODEL_AUTO_DETECT,
"DHT11": DHTModel.DHT_MODEL_DHT11,
"DHT22": DHTModel.DHT_MODEL_DHT22,
"AM2120": DHTModel.DHT_MODEL_AM2120,
"AM2302": DHTModel.DHT_MODEL_AM2302,
"RHT03": DHTModel.DHT_MODEL_RHT03,
"SI7021": DHTModel.DHT_MODEL_SI7021,
"DHT22_TYPE2": DHTModel.DHT_MODEL_DHT22_TYPE2,
}
DHT = dht_ns.class_("DHT", cg.PollingComponent)
CONFIG_SCHEMA = cv.Schema(
+10 -11
View File
@@ -22,17 +22,16 @@ ES8311_BITS_PER_SAMPLE_ENUM = {
}
es8311_mic_gain = es8311_ns.enum("ES8311MicGain")
ES8311_MIC_GAIN_ENUM = es8311_mic_gain.options(
"0DB",
"6DB",
"12DB",
"18DB",
"24DB",
"30DB",
"36DB",
"42DB",
prefix="ES8311_MIC_GAIN_",
)
ES8311_MIC_GAIN_ENUM = {
"0DB": es8311_mic_gain.ES8311_MIC_GAIN_0DB,
"6DB": es8311_mic_gain.ES8311_MIC_GAIN_6DB,
"12DB": es8311_mic_gain.ES8311_MIC_GAIN_12DB,
"18DB": es8311_mic_gain.ES8311_MIC_GAIN_18DB,
"24DB": es8311_mic_gain.ES8311_MIC_GAIN_24DB,
"30DB": es8311_mic_gain.ES8311_MIC_GAIN_30DB,
"36DB": es8311_mic_gain.ES8311_MIC_GAIN_36DB,
"42DB": es8311_mic_gain.ES8311_MIC_GAIN_42DB,
}
_validate_bits = cv.float_with_unit("bits", "bit")
+19 -11
View File
@@ -14,24 +14,26 @@ CONF_DAC_OUTPUT = "dac_output"
CONF_ADC_INPUT_MIC = "adc_input_mic"
DacOutputLine = es8388_ns.enum("DacOutputLine")
DAC_OUTPUT_OPTIONS = DacOutputLine.options(
"LINE1", "LINE2", "BOTH", prefix="DAC_OUTPUT_"
)
DAC_OUTPUT_OPTIONS = {
"LINE1": DacOutputLine.DAC_OUTPUT_LINE1,
"LINE2": DacOutputLine.DAC_OUTPUT_LINE2,
"BOTH": DacOutputLine.DAC_OUTPUT_BOTH,
}
DAC_OUTPUT_OPTION_NAMES = list(DAC_OUTPUT_OPTIONS)
AdcInputMicLine = es8388_ns.enum("AdcInputMicLine")
ADC_INPUT_MIC_OPTIONS = AdcInputMicLine.options(
"LINE1", "LINE2", "DIFFERENCE", prefix="ADC_INPUT_MIC_"
)
ADC_INPUT_MIC_OPTIONS = {
"LINE1": AdcInputMicLine.ADC_INPUT_MIC_LINE1,
"LINE2": AdcInputMicLine.ADC_INPUT_MIC_LINE2,
"DIFFERENCE": AdcInputMicLine.ADC_INPUT_MIC_DIFFERENCE,
}
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(
@@ -42,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(
@@ -61,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
@@ -42,9 +42,12 @@ FILTER_SHAPES = {
}
DeemphasisMode = es9038q2m_katana_ns.enum("DeemphasisMode")
DEEMPHASIS_MODES = DeemphasisMode.options(
"bypass", "32khz", "44_1khz", "48khz", prefix="DEEMPHASIS_"
)
DEEMPHASIS_MODES = {
"bypass": DeemphasisMode.DEEMPHASIS_BYPASS,
"32khz": DeemphasisMode.DEEMPHASIS_32KHZ,
"44_1khz": DeemphasisMode.DEEMPHASIS_44_1KHZ,
"48khz": DeemphasisMode.DEEMPHASIS_48KHZ,
}
CONFIG_SCHEMA = (
cv.Schema(
+10 -11
View File
@@ -310,17 +310,16 @@ IO_CAPABILITY = {
}
AuthReqMode = esp32_ble_ns.enum("AuthReqMode")
AUTH_REQ_MODE = AuthReqMode.options(
"no_bond",
"bond",
"mitm",
"bond_mitm",
"sc_only",
"sc_bond",
"sc_mitm",
"sc_mitm_bond",
prefix="AUTH_REQ_",
)
AUTH_REQ_MODE = {
"no_bond": AuthReqMode.AUTH_REQ_NO_BOND,
"bond": AuthReqMode.AUTH_REQ_BOND,
"mitm": AuthReqMode.AUTH_REQ_MITM,
"bond_mitm": AuthReqMode.AUTH_REQ_BOND_MITM,
"sc_only": AuthReqMode.AUTH_REQ_SC_ONLY,
"sc_bond": AuthReqMode.AUTH_REQ_SC_BOND,
"sc_mitm": AuthReqMode.AUTH_REQ_SC_MITM,
"sc_mitm_bond": AuthReqMode.AUTH_REQ_SC_MITM_BOND,
}
esp_power_level_t = cg.global_ns.enum("esp_power_level_t")
+36 -28
View File
@@ -90,42 +90,50 @@ FRAME_SIZES = {
"QSXGA": ESP32CameraFrameSize.ESP32_CAMERA_SIZE_2560X1920,
}
ESP32CameraPixelFormat = esp32_camera_ns.enum("ESP32CameraPixelFormat")
PIXEL_FORMATS = ESP32CameraPixelFormat.options(
"RGB565",
"YUV422",
"YUV420",
"GRAYSCALE",
"JPEG",
"RGB888",
"RAW",
"RGB444",
"RGB555",
prefix="ESP32_PIXEL_FORMAT_",
)
PIXEL_FORMATS = {
"RGB565": ESP32CameraPixelFormat.ESP32_PIXEL_FORMAT_RGB565,
"YUV422": ESP32CameraPixelFormat.ESP32_PIXEL_FORMAT_YUV422,
"YUV420": ESP32CameraPixelFormat.ESP32_PIXEL_FORMAT_YUV420,
"GRAYSCALE": ESP32CameraPixelFormat.ESP32_PIXEL_FORMAT_GRAYSCALE,
"JPEG": ESP32CameraPixelFormat.ESP32_PIXEL_FORMAT_JPEG,
"RGB888": ESP32CameraPixelFormat.ESP32_PIXEL_FORMAT_RGB888,
"RAW": ESP32CameraPixelFormat.ESP32_PIXEL_FORMAT_RAW,
"RGB444": ESP32CameraPixelFormat.ESP32_PIXEL_FORMAT_RGB444,
"RGB555": ESP32CameraPixelFormat.ESP32_PIXEL_FORMAT_RGB555,
}
ESP32GainControlMode = esp32_camera_ns.enum("ESP32GainControlMode")
ENUM_GAIN_CONTROL_MODE = {
"MANUAL": ESP32GainControlMode.ESP32_GC_MODE_MANU,
"AUTO": ESP32GainControlMode.ESP32_GC_MODE_AUTO,
}
ESP32AgcGainCeiling = esp32_camera_ns.enum("ESP32AgcGainCeiling")
ENUM_GAIN_CEILING = ESP32AgcGainCeiling.options(
"2X", "4X", "8X", "16X", "32X", "64X", "128X", prefix="ESP32_GAINCEILING_"
)
ENUM_GAIN_CEILING = {
"2X": ESP32AgcGainCeiling.ESP32_GAINCEILING_2X,
"4X": ESP32AgcGainCeiling.ESP32_GAINCEILING_4X,
"8X": ESP32AgcGainCeiling.ESP32_GAINCEILING_8X,
"16X": ESP32AgcGainCeiling.ESP32_GAINCEILING_16X,
"32X": ESP32AgcGainCeiling.ESP32_GAINCEILING_32X,
"64X": ESP32AgcGainCeiling.ESP32_GAINCEILING_64X,
"128X": ESP32AgcGainCeiling.ESP32_GAINCEILING_128X,
}
ESP32WhiteBalanceMode = esp32_camera_ns.enum("ESP32WhiteBalanceMode")
ENUM_WB_MODE = ESP32WhiteBalanceMode.options(
"AUTO", "SUNNY", "CLOUDY", "OFFICE", "HOME", prefix="ESP32_WB_MODE_"
)
ENUM_WB_MODE = {
"AUTO": ESP32WhiteBalanceMode.ESP32_WB_MODE_AUTO,
"SUNNY": ESP32WhiteBalanceMode.ESP32_WB_MODE_SUNNY,
"CLOUDY": ESP32WhiteBalanceMode.ESP32_WB_MODE_CLOUDY,
"OFFICE": ESP32WhiteBalanceMode.ESP32_WB_MODE_OFFICE,
"HOME": ESP32WhiteBalanceMode.ESP32_WB_MODE_HOME,
}
ESP32SpecialEffect = esp32_camera_ns.enum("ESP32SpecialEffect")
ENUM_SPECIAL_EFFECT = ESP32SpecialEffect.options(
"NONE",
"NEGATIVE",
"GRAYSCALE",
"RED_TINT",
"GREEN_TINT",
"BLUE_TINT",
"SEPIA",
prefix="ESP32_SPECIAL_EFFECT_",
)
ENUM_SPECIAL_EFFECT = {
"NONE": ESP32SpecialEffect.ESP32_SPECIAL_EFFECT_NONE,
"NEGATIVE": ESP32SpecialEffect.ESP32_SPECIAL_EFFECT_NEGATIVE,
"GRAYSCALE": ESP32SpecialEffect.ESP32_SPECIAL_EFFECT_GRAYSCALE,
"RED_TINT": ESP32SpecialEffect.ESP32_SPECIAL_EFFECT_RED_TINT,
"GREEN_TINT": ESP32SpecialEffect.ESP32_SPECIAL_EFFECT_GREEN_TINT,
"BLUE_TINT": ESP32SpecialEffect.ESP32_SPECIAL_EFFECT_BLUE_TINT,
"SEPIA": ESP32SpecialEffect.ESP32_SPECIAL_EFFECT_SEPIA,
}
camera_fb_location_t = cg.global_ns.enum("camera_fb_location_t")
ENUM_FB_LOCATION = {
@@ -14,7 +14,7 @@ esp32_camera_web_server_ns = cg.esphome_ns.namespace("esp32_camera_web_server")
CameraWebServer = esp32_camera_web_server_ns.class_("CameraWebServer", cg.Component)
Mode = esp32_camera_web_server_ns.enum("Mode")
MODES = Mode.options("STREAM", "SNAPSHOT")
MODES = {"STREAM": Mode.STREAM, "SNAPSHOT": Mode.SNAPSHOT}
def _consume_camera_web_server_sockets(config: ConfigType) -> ConfigType:
+9 -2
View File
@@ -38,8 +38,15 @@ CsiCapturePolicy = sdk_ns.enum("CsiCapturePolicy", is_class=True)
TrafficGeneratorMode = sdk_ns.enum("TrafficGeneratorMode", is_class=True)
WifiBandPolicy = sdk_ns.enum("WifiBandPolicy", is_class=True)
DETECTION_ALGORITHMS = DetectionAlgorithm.options("lightweight", "high_accuracy")
CSI_CAPTURE_PROFILES = CsiCapturePolicy.options("auto", "lltf", "ht_vht")
DETECTION_ALGORITHMS = {
"lightweight": DetectionAlgorithm.LIGHTWEIGHT,
"high_accuracy": DetectionAlgorithm.HIGH_ACCURACY,
}
CSI_CAPTURE_PROFILES = {
"auto": CsiCapturePolicy.AUTO,
"lltf": CsiCapturePolicy.LLTF,
"ht_vht": CsiCapturePolicy.HT_VHT,
}
TRAFFIC_GENERATOR_MODES = {
"ping": TrafficGeneratorMode.PING,
"dns": TrafficGeneratorMode.DNS,
@@ -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
+25 -23
View File
@@ -117,28 +117,27 @@ CONF_INTERFACE = "interface"
CONF_CLOCK_SPEED = "clock_speed"
EthernetType = ethernet_ns.enum("EthernetType")
ETHERNET_TYPES = EthernetType.options(
"LAN8720",
"RTL8201",
"DP83848",
"IP101",
"JL1101",
"KSZ8081",
"KSZ8081RNA",
"W5100",
"W5500",
"OPENETH",
"DM9051",
"LAN8670",
"ENC28J60",
"W6100",
"W6300",
"GENERIC",
"YT8531",
"CH390",
"KSZ8851SNL",
prefix="ETHERNET_TYPE_",
)
ETHERNET_TYPES = {
"LAN8720": EthernetType.ETHERNET_TYPE_LAN8720,
"RTL8201": EthernetType.ETHERNET_TYPE_RTL8201,
"DP83848": EthernetType.ETHERNET_TYPE_DP83848,
"IP101": EthernetType.ETHERNET_TYPE_IP101,
"JL1101": EthernetType.ETHERNET_TYPE_JL1101,
"KSZ8081": EthernetType.ETHERNET_TYPE_KSZ8081,
"KSZ8081RNA": EthernetType.ETHERNET_TYPE_KSZ8081RNA,
"W5100": EthernetType.ETHERNET_TYPE_W5100,
"W5500": EthernetType.ETHERNET_TYPE_W5500,
"OPENETH": EthernetType.ETHERNET_TYPE_OPENETH,
"DM9051": EthernetType.ETHERNET_TYPE_DM9051,
"LAN8670": EthernetType.ETHERNET_TYPE_LAN8670,
"ENC28J60": EthernetType.ETHERNET_TYPE_ENC28J60,
"W6100": EthernetType.ETHERNET_TYPE_W6100,
"W6300": EthernetType.ETHERNET_TYPE_W6300,
"GENERIC": EthernetType.ETHERNET_TYPE_GENERIC,
"YT8531": EthernetType.ETHERNET_TYPE_YT8531,
"CH390": EthernetType.ETHERNET_TYPE_CH390,
"KSZ8851SNL": EthernetType.ETHERNET_TYPE_KSZ8851SNL,
}
# PHY types that need compile-time defines for conditional compilation
# Each RMII PHY type gets a define so unused PHY drivers are excluded by the linker
@@ -208,7 +207,10 @@ SPI_ETHERNET_DEFAULT_POLLING_INTERVAL = TimePeriodMilliseconds(milliseconds=10)
emac_rmii_clock_mode_t = cg.global_ns.enum("emac_rmii_clock_mode_t")
CLK_MODES = emac_rmii_clock_mode_t.options("CLK_EXT_IN", "CLK_OUT", prefix="EMAC_")
CLK_MODES = {
"CLK_EXT_IN": emac_rmii_clock_mode_t.EMAC_CLK_EXT_IN,
"CLK_OUT": emac_rmii_clock_mode_t.EMAC_CLK_OUT,
}
spi_host_device_t = cg.global_ns.enum("spi_host_device_t")
@@ -23,9 +23,11 @@ ExponentialMovingAverageSensor = exponential_moving_average_ns.class_(
)
TimeWeighting = exponential_moving_average_ns.enum("TimeWeighting")
TIME_WEIGHTINGS: dict[str, cg.MockObj] = TimeWeighting.options(
"new", "previous", "linear", prefix="TIME_WEIGHTING_"
)
TIME_WEIGHTINGS: dict[str, cg.MockObj] = {
"new": TimeWeighting.TIME_WEIGHTING_NEW,
"previous": TimeWeighting.TIME_WEIGHTING_PREVIOUS,
"linear": TimeWeighting.TIME_WEIGHTING_LINEAR,
}
CONF_TIME_WEIGHTING: str = "time_weighting"
+13 -10
View File
@@ -45,18 +45,21 @@ fan_ns = cg.esphome_ns.namespace("fan")
Fan = fan_ns.class_("Fan", cg.EntityBase)
FanDirection = fan_ns.enum("FanDirection", is_class=True)
FAN_DIRECTION_ENUM = FanDirection.options("FORWARD", "REVERSE")
FAN_DIRECTION_ENUM = {
"FORWARD": FanDirection.FORWARD,
"REVERSE": FanDirection.REVERSE,
}
FanRestoreMode = fan_ns.enum("FanRestoreMode", is_class=True)
RESTORE_MODES = FanRestoreMode.options(
"NO_RESTORE",
"ALWAYS_OFF",
"ALWAYS_ON",
"RESTORE_DEFAULT_OFF",
"RESTORE_DEFAULT_ON",
"RESTORE_INVERTED_DEFAULT_OFF",
"RESTORE_INVERTED_DEFAULT_ON",
)
RESTORE_MODES = {
"NO_RESTORE": FanRestoreMode.NO_RESTORE,
"ALWAYS_OFF": FanRestoreMode.ALWAYS_OFF,
"ALWAYS_ON": FanRestoreMode.ALWAYS_ON,
"RESTORE_DEFAULT_OFF": FanRestoreMode.RESTORE_DEFAULT_OFF,
"RESTORE_DEFAULT_ON": FanRestoreMode.RESTORE_DEFAULT_ON,
"RESTORE_INVERTED_DEFAULT_OFF": FanRestoreMode.RESTORE_INVERTED_DEFAULT_OFF,
"RESTORE_INVERTED_DEFAULT_ON": FanRestoreMode.RESTORE_INVERTED_DEFAULT_ON,
}
# Actions
CycleSpeedAction = fan_ns.class_("CycleSpeedAction", automation.Action)
@@ -40,14 +40,25 @@ FingerprintGrowComponent = fingerprint_grow_ns.class_(
AuraLEDState = fingerprint_grow_ns.enum("GrowAuraLEDState", True)
AURA_LED_STATES = AuraLEDState.options(
"BREATHING", "FLASHING", "ALWAYS_ON", "ALWAYS_OFF", "GRADUAL_ON", "GRADUAL_OFF"
)
AURA_LED_STATES = {
"BREATHING": AuraLEDState.BREATHING,
"FLASHING": AuraLEDState.FLASHING,
"ALWAYS_ON": AuraLEDState.ALWAYS_ON,
"ALWAYS_OFF": AuraLEDState.ALWAYS_OFF,
"GRADUAL_ON": AuraLEDState.GRADUAL_ON,
"GRADUAL_OFF": AuraLEDState.GRADUAL_OFF,
}
validate_aura_led_states = cv.enum(AURA_LED_STATES, upper=True)
AuraLEDColor = fingerprint_grow_ns.enum("GrowAuraLEDColor", True)
AURA_LED_COLORS = AuraLEDColor.options(
"RED", "BLUE", "PURPLE", "GREEN", "YELLOW", "CYAN", "WHITE"
)
AURA_LED_COLORS = {
"RED": AuraLEDColor.RED,
"BLUE": AuraLEDColor.BLUE,
"PURPLE": AuraLEDColor.PURPLE,
"GREEN": AuraLEDColor.GREEN,
"YELLOW": AuraLEDColor.YELLOW,
"CYAN": AuraLEDColor.CYAN,
"WHITE": AuraLEDColor.WHITE,
}
validate_aura_led_colors = cv.enum(AURA_LED_COLORS, upper=True)
+3 -1
View File
@@ -11,7 +11,9 @@ friedrich_ns = cg.esphome_ns.namespace("friedrich")
FriedrichClimate = friedrich_ns.class_("FriedrichClimate", climate_ir.ClimateIR)
Model = friedrich_ns.enum("Model", is_class=True)
MODELS = Model.options("MW12Y3H", prefix="MODEL_")
MODELS = {
"MW12Y3H": Model.MODEL_MW12Y3H,
}
CONFIG_SCHEMA = climate_ir.climate_ir_with_receiver_schema(FriedrichClimate).extend(
{
+8 -2
View File
@@ -17,9 +17,15 @@ GP8403Model = gp8403_ns.enum("GP8403Model")
CONF_GP8403_ID = "gp8403_id"
MODELS = GP8403Model.options("GP8403", "GP8413")
MODELS = {
"GP8403": GP8403Model.GP8403,
"GP8413": GP8403Model.GP8413,
}
VOLTAGES = GP8403Voltage.options("5V", "10V", prefix="GP8403_VOLTAGE_")
VOLTAGES = {
"5V": GP8403Voltage.GP8403_VOLTAGE_5V,
"10V": GP8403Voltage.GP8403_VOLTAGE_10V,
}
CONFIG_SCHEMA = (
cv.Schema(
+16 -7
View File
@@ -43,17 +43,26 @@ GraphTrace = graph_ns.class_("GraphTrace")
GraphLegend = graph_ns.class_("GraphLegend")
LineType = graph_ns.enum("LineType")
LINE_TYPE = LineType.options("SOLID", "DOTTED", "DASHED", prefix="LINE_TYPE_")
LINE_TYPE = {
"SOLID": LineType.LINE_TYPE_SOLID,
"DOTTED": LineType.LINE_TYPE_DOTTED,
"DASHED": LineType.LINE_TYPE_DASHED,
}
DirectionType = graph_ns.enum("DirectionType")
DIRECTION_TYPE = DirectionType.options(
"AUTO", "HORIZONTAL", "VERTICAL", prefix="DIRECTION_TYPE_"
)
DIRECTION_TYPE = {
"AUTO": DirectionType.DIRECTION_TYPE_AUTO,
"HORIZONTAL": DirectionType.DIRECTION_TYPE_HORIZONTAL,
"VERTICAL": DirectionType.DIRECTION_TYPE_VERTICAL,
}
ValuePositionType = graph_ns.enum("ValuePositionType")
VALUE_POSITION_TYPE = ValuePositionType.options(
"NONE", "AUTO", "BESIDE", "BELOW", prefix="VALUE_POSITION_TYPE_"
)
VALUE_POSITION_TYPE = {
"NONE": ValuePositionType.VALUE_POSITION_TYPE_NONE,
"AUTO": ValuePositionType.VALUE_POSITION_TYPE_AUTO,
"BESIDE": ValuePositionType.VALUE_POSITION_TYPE_BESIDE,
"BELOW": ValuePositionType.VALUE_POSITION_TYPE_BELOW,
}
GRAPH_TRACE_SCHEMA = cv.Schema(
{
+9 -3
View File
@@ -12,9 +12,15 @@ AUTO_LOAD = ["climate_ir"]
GreeClimate = gree_ns.class_("GreeClimate", climate_ir.ClimateIR)
Model = gree_ns.enum("Model")
MODELS = Model.options(
"generic", "yan", "yaa", "yac", "yac1fb9", "yx1ff", "yag", prefix="GREE_"
)
MODELS = {
"generic": Model.GREE_GENERIC,
"yan": Model.GREE_YAN,
"yaa": Model.GREE_YAA,
"yac": Model.GREE_YAC,
"yac1fb9": Model.GREE_YAC1FB9,
"yx1ff": Model.GREE_YX1FF,
"yag": Model.GREE_YAG,
}
CONFIG_SCHEMA = climate_ir.climate_ir_with_receiver_schema(GreeClimate).extend(
{
+4 -1
View File
@@ -100,7 +100,10 @@ PV_SCHEMA = cv.Schema(
)
GrowattProtocolVersion = growatt_solar_ns.enum("GrowattProtocolVersion")
PROTOCOL_VERSIONS = GrowattProtocolVersion.options("RTU", "RTU2")
PROTOCOL_VERSIONS = {
"RTU": GrowattProtocolVersion.RTU,
"RTU2": GrowattProtocolVersion.RTU2,
}
CONFIG_SCHEMA = (
+8 -11
View File
@@ -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
+20 -9
View File
@@ -67,14 +67,23 @@ Smartair2Climate = haier_ns.class_("Smartair2Climate", HaierClimateBase)
CONF_HAIER_ID = "haier_id"
AirflowVerticalDirection = hon_protocol_ns.enum("VerticalSwingMode", True)
AIRFLOW_VERTICAL_DIRECTION_OPTIONS = AirflowVerticalDirection.options(
"HEALTH_UP", "MAX_UP", "UP", "CENTER", "DOWN", "HEALTH_DOWN"
)
AIRFLOW_VERTICAL_DIRECTION_OPTIONS = {
"HEALTH_UP": AirflowVerticalDirection.HEALTH_UP,
"MAX_UP": AirflowVerticalDirection.MAX_UP,
"UP": AirflowVerticalDirection.UP,
"CENTER": AirflowVerticalDirection.CENTER,
"DOWN": AirflowVerticalDirection.DOWN,
"HEALTH_DOWN": AirflowVerticalDirection.HEALTH_DOWN,
}
AirflowHorizontalDirection = hon_protocol_ns.enum("HorizontalSwingMode", True)
AIRFLOW_HORIZONTAL_DIRECTION_OPTIONS = AirflowHorizontalDirection.options(
"MAX_LEFT", "LEFT", "CENTER", "RIGHT", "MAX_RIGHT"
)
AIRFLOW_HORIZONTAL_DIRECTION_OPTIONS = {
"MAX_LEFT": AirflowHorizontalDirection.MAX_LEFT,
"LEFT": AirflowHorizontalDirection.LEFT,
"CENTER": AirflowHorizontalDirection.CENTER,
"RIGHT": AirflowHorizontalDirection.RIGHT,
"MAX_RIGHT": AirflowHorizontalDirection.MAX_RIGHT,
}
SUPPORTED_SWING_MODES_OPTIONS = {
"OFF": ClimateSwingMode.CLIMATE_SWING_OFF,
@@ -105,9 +114,11 @@ SUPPORTED_CLIMATE_PRESETS_HON_OPTIONS = {
}
HonControlMethod = haier_ns.enum("HonControlMethod", True)
SUPPORTED_HON_CONTROL_METHODS = HonControlMethod.options(
"MONITOR_ONLY", "SET_GROUP_PARAMETERS", "SET_SINGLE_PARAMETER"
)
SUPPORTED_HON_CONTROL_METHODS = {
"MONITOR_ONLY": HonControlMethod.MONITOR_ONLY,
"SET_GROUP_PARAMETERS": HonControlMethod.SET_GROUP_PARAMETERS,
"SET_SINGLE_PARAMETER": HonControlMethod.SET_SINGLE_PARAMETER,
}
def validate_visual(config):
+6 -5
View File
@@ -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
+4 -1
View File
@@ -12,7 +12,10 @@ HaierTundra = haier_tundra_ns.class_("HaierTundra", climate_ir.ClimateIR)
CONF_UNIT = "unit"
Unit = haier_tundra_ns.enum("Unit")
UNITS = Unit.options("a", "b", prefix="HAIER_HEADER_UNIT_")
UNITS = {
"a": Unit.HAIER_HEADER_UNIT_A,
"b": Unit.HAIER_HEADER_UNIT_B,
}
CONFIG_SCHEMA = climate_ir.climate_ir_with_receiver_schema(HaierTundra).extend(
{
+4 -1
View File
@@ -22,7 +22,10 @@ CODEOWNERS = ["@WeekendWarrior"]
HBridgeFan = hbridge_ns.class_("HBridgeFan", cg.Component, fan.Fan)
DecayMode = hbridge_ns.enum("DecayMode")
DECAY_MODE_OPTIONS = DecayMode.options("SLOW", "FAST", prefix="DECAY_MODE_")
DECAY_MODE_OPTIONS = {
"SLOW": DecayMode.DECAY_MODE_SLOW,
"FAST": DecayMode.DECAY_MODE_FAST,
}
CONFIG_SCHEMA = (
fan.fan_schema(HBridgeFan)
+6 -3
View File
@@ -28,9 +28,12 @@ HDC302XComponent = hdc302x_ns.class_(
)
HDC302XPowerMode = hdc302x_ns.enum("HDC302XPowerMode")
POWER_MODE_OPTIONS = HDC302XPowerMode.options(
"HIGH_ACCURACY", "BALANCED", "LOW_POWER", "ULTRA_LOW_POWER"
)
POWER_MODE_OPTIONS = {
"HIGH_ACCURACY": HDC302XPowerMode.HIGH_ACCURACY,
"BALANCED": HDC302XPowerMode.BALANCED,
"LOW_POWER": HDC302XPowerMode.LOW_POWER,
"ULTRA_LOW_POWER": HDC302XPowerMode.ULTRA_LOW_POWER,
}
CONFIG_SCHEMA = (
cv.Schema(
+16 -6
View File
@@ -78,15 +78,25 @@ PROTOCOLS = {
CONF_HORIZONTAL_DEFAULT = "horizontal_default"
HorizontalDirections = heatpumpir_ns.enum("HorizontalDirections")
HORIZONTAL_DIRECTIONS = HorizontalDirections.options(
"auto", "middle", "left", "mleft", "mright", "right", prefix="HORIZONTAL_DIRECTION_"
)
HORIZONTAL_DIRECTIONS = {
"auto": HorizontalDirections.HORIZONTAL_DIRECTION_AUTO,
"middle": HorizontalDirections.HORIZONTAL_DIRECTION_MIDDLE,
"left": HorizontalDirections.HORIZONTAL_DIRECTION_LEFT,
"mleft": HorizontalDirections.HORIZONTAL_DIRECTION_MLEFT,
"mright": HorizontalDirections.HORIZONTAL_DIRECTION_MRIGHT,
"right": HorizontalDirections.HORIZONTAL_DIRECTION_RIGHT,
}
CONF_VERTICAL_DEFAULT = "vertical_default"
VerticalDirections = heatpumpir_ns.enum("VerticalDirections")
VERTICAL_DIRECTIONS = VerticalDirections.options(
"auto", "up", "mup", "middle", "mdown", "down", prefix="VERTICAL_DIRECTION_"
)
VERTICAL_DIRECTIONS = {
"auto": VerticalDirections.VERTICAL_DIRECTION_AUTO,
"up": VerticalDirections.VERTICAL_DIRECTION_UP,
"mup": VerticalDirections.VERTICAL_DIRECTION_MUP,
"middle": VerticalDirections.VERTICAL_DIRECTION_MIDDLE,
"mdown": VerticalDirections.VERTICAL_DIRECTION_MDOWN,
"down": VerticalDirections.VERTICAL_DIRECTION_DOWN,
}
def _default_visual(config: ConfigType) -> ConfigType:
+5 -3
View File
@@ -41,9 +41,11 @@ INITIAL_MODES = {
CONF_VOLTAGE: HLW8012InitialMode.HLW8012_INITIAL_MODE_VOLTAGE,
}
MODELS = HLW8012SensorModels.options(
"HLW8012", "CSE7759", "BL0937", prefix="HLW8012_SENSOR_MODEL_"
)
MODELS = {
"HLW8012": HLW8012SensorModels.HLW8012_SENSOR_MODEL_HLW8012,
"CSE7759": HLW8012SensorModels.HLW8012_SENSOR_MODEL_CSE7759,
"BL0937": HLW8012SensorModels.HLW8012_SENSOR_MODEL_BL0937,
}
CONF_CF1_PIN = "cf1_pin"
CONF_CF_PIN = "cf_pin"
@@ -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
@@ -20,7 +20,10 @@ CONF_MIN_PRESSURE = "min_pressure"
CONF_MAX_PRESSURE = "max_pressure"
TRANSFER_FUNCTION = "transfer_function"
ABP2TRANFERFUNCTION = honeywellabp2_ns.enum("ABP2TRANFERFUNCTION")
TRANS_FUNC_OPTIONS = ABP2TRANFERFUNCTION.options("A", "B", prefix="ABP2_TRANS_FUNC_")
TRANS_FUNC_OPTIONS = {
"A": ABP2TRANFERFUNCTION.ABP2_TRANS_FUNC_A,
"B": ABP2TRANFERFUNCTION.ABP2_TRANS_FUNC_B,
}
HONEYWELLABP2Sensor = honeywellabp2_ns.class_(
"HONEYWELLABP2Sensor", sensor.Sensor, cg.PollingComponent, i2c.I2CDevice
-4
View File
@@ -31,10 +31,6 @@ bool random_bytes(uint8_t *data, size_t len) {
return true;
}
// The host has no interrupts to mask
InterruptLock::InterruptLock() {}
InterruptLock::~InterruptLock() {}
// Host platform uses std::mutex for proper thread synchronization
Mutex::Mutex() { handle_ = new std::mutex(); }
Mutex::~Mutex() { delete static_cast<std::mutex *>(handle_); }
+5 -3
View File
@@ -27,9 +27,11 @@ HTU21DComponent = htu21d_ns.class_(
)
HTU21DSensorModels = htu21d_ns.enum("HTU21DSensorModels")
MODELS = HTU21DSensorModels.options(
"HTU21D", "SI7021", "SHT21", prefix="HTU21D_SENSOR_MODEL_"
)
MODELS = {
"HTU21D": HTU21DSensorModels.HTU21D_SENSOR_MODEL_HTU21D,
"SI7021": HTU21DSensorModels.HTU21D_SENSOR_MODEL_SI7021,
"SHT21": HTU21DSensorModels.HTU21D_SENSOR_MODEL_SHT21,
}
CONFIG_SCHEMA = (
cv.Schema(
+27 -22
View File
@@ -97,32 +97,37 @@ CONF_MIN_REFRESH_RATE = "min_refresh_rate"
# Map to hub75 library enums (in global namespace)
Hub75ShiftDriver = cg.global_ns.enum("Hub75ShiftDriver", is_class=True)
SHIFT_DRIVERS = Hub75ShiftDriver.options(
"GENERIC", "FM6126A", "ICN2038S", "FM6124", "MBI5124", "DP3246"
)
SHIFT_DRIVERS = {
"GENERIC": Hub75ShiftDriver.GENERIC,
"FM6126A": Hub75ShiftDriver.FM6126A,
"ICN2038S": Hub75ShiftDriver.ICN2038S,
"FM6124": Hub75ShiftDriver.FM6124,
"MBI5124": Hub75ShiftDriver.MBI5124,
"DP3246": Hub75ShiftDriver.DP3246,
}
Hub75PanelLayout = cg.global_ns.enum("Hub75PanelLayout", is_class=True)
PANEL_LAYOUTS = Hub75PanelLayout.options(
"HORIZONTAL",
"TOP_LEFT_DOWN",
"TOP_RIGHT_DOWN",
"BOTTOM_LEFT_UP",
"BOTTOM_RIGHT_UP",
"TOP_LEFT_DOWN_ZIGZAG",
"TOP_RIGHT_DOWN_ZIGZAG",
"BOTTOM_LEFT_UP_ZIGZAG",
"BOTTOM_RIGHT_UP_ZIGZAG",
)
PANEL_LAYOUTS = {
"HORIZONTAL": Hub75PanelLayout.HORIZONTAL,
"TOP_LEFT_DOWN": Hub75PanelLayout.TOP_LEFT_DOWN,
"TOP_RIGHT_DOWN": Hub75PanelLayout.TOP_RIGHT_DOWN,
"BOTTOM_LEFT_UP": Hub75PanelLayout.BOTTOM_LEFT_UP,
"BOTTOM_RIGHT_UP": Hub75PanelLayout.BOTTOM_RIGHT_UP,
"TOP_LEFT_DOWN_ZIGZAG": Hub75PanelLayout.TOP_LEFT_DOWN_ZIGZAG,
"TOP_RIGHT_DOWN_ZIGZAG": Hub75PanelLayout.TOP_RIGHT_DOWN_ZIGZAG,
"BOTTOM_LEFT_UP_ZIGZAG": Hub75PanelLayout.BOTTOM_LEFT_UP_ZIGZAG,
"BOTTOM_RIGHT_UP_ZIGZAG": Hub75PanelLayout.BOTTOM_RIGHT_UP_ZIGZAG,
}
Hub75ScanWiring = cg.global_ns.enum("Hub75ScanWiring", is_class=True)
SCAN_WIRINGS = Hub75ScanWiring.options(
"STANDARD_TWO_SCAN",
"SCAN_1_4_16PX_HIGH",
"SCAN_1_8_32PX_HIGH",
"SCAN_1_8_32PX_FULL",
"SCAN_1_8_40PX_HIGH",
"SCAN_1_8_64PX_HIGH",
)
SCAN_WIRINGS = {
"STANDARD_TWO_SCAN": Hub75ScanWiring.STANDARD_TWO_SCAN,
"SCAN_1_4_16PX_HIGH": Hub75ScanWiring.SCAN_1_4_16PX_HIGH,
"SCAN_1_8_32PX_HIGH": Hub75ScanWiring.SCAN_1_8_32PX_HIGH,
"SCAN_1_8_32PX_FULL": Hub75ScanWiring.SCAN_1_8_32PX_FULL,
"SCAN_1_8_40PX_HIGH": Hub75ScanWiring.SCAN_1_8_40PX_HIGH,
"SCAN_1_8_64PX_HIGH": Hub75ScanWiring.SCAN_1_8_64PX_HIGH,
}
def _validate_scan_wiring(value: Any) -> str:
+3 -1
View File
@@ -67,7 +67,9 @@ bool HX711Sensor::read_sensor_(uint32_t *result) {
this->status_clear_warning();
data = static_cast<uint32_t>(sign_extend<24>(data));
if (data & 0x800000ULL) {
data |= 0xFF000000ULL;
}
if (result != nullptr)
*result = data;
+6 -20
View File
@@ -3,6 +3,7 @@
#include "esphome/core/defines.h"
#include "esphome/core/hal.h"
#include "esphome/core/log.h"
#include <memory>
namespace esphome::i2c {
@@ -21,10 +22,6 @@ void I2CBus::i2c_scan_() {
}
}
void log_wrong_chip_id(uint8_t id, uint8_t expected) {
ESP_LOGE(TAG, "Wrong chip ID 0x%02X, expected 0x%02X", id, expected);
}
ErrorCode I2CDevice::read_register(uint8_t a_register, uint8_t *data, size_t len) {
return bus_->write_readv(this->address_, &a_register, 1, data, len);
}
@@ -62,22 +59,11 @@ bool I2CDevice::read_bytes_16(uint8_t a_register, uint16_t *data, uint8_t len) {
}
bool I2CDevice::write_bytes_16(uint8_t a_register, const uint16_t *data, uint8_t len) const {
const size_t size = 1 + len * 2;
SmallBufferWithHeapFallback<17> buffer_alloc(size); // Register plus up to 8 words
uint8_t *buffer = buffer_alloc.get();
buffer[0] = a_register;
for (size_t i = 0; i < len; i++) {
const uint16_t word = data[i];
buffer[1 + i * 2] = word >> 8;
buffer[2 + i * 2] = word;
}
return this->bus_->write_readv(this->address_, buffer, size, nullptr, 0) == ERROR_OK;
}
bool I2CDevice::write_byte_16(uint8_t a_register, uint16_t data) const {
const uint8_t buffer[3] = {a_register, static_cast<uint8_t>(data >> 8), static_cast<uint8_t>(data)};
return this->bus_->write_readv(this->address_, buffer, sizeof(buffer), nullptr, 0) == ERROR_OK;
// we have to copy in order to be able to change byte order
std::unique_ptr<uint16_t[]> temp{new uint16_t[len]};
for (size_t i = 0; i < len; i++)
temp[i] = htoi2cs(data[i]);
return write_register(a_register, reinterpret_cast<const uint8_t *>(temp.get()), len * 2) == ERROR_OK;
}
I2CRegister &I2CRegister::operator=(uint8_t value) {
+1 -19
View File
@@ -2,9 +2,7 @@
#include <array>
#include <vector>
#include "esphome/core/component.h"
#include "esphome/core/helpers.h"
#include "esphome/core/log.h"
#include "esphome/core/optional.h"
#include "i2c_bus.h"
@@ -14,9 +12,6 @@ namespace esphome::i2c {
class I2CDevice; // forward declaration
/// Out of line so each check_chip_id() caller only pays for a call.
void log_wrong_chip_id(uint8_t id, uint8_t expected);
/// @brief This class is used to create I2CRegister objects that act as proxies to read/write internal registers on an
/// I2C device.
/// @details
@@ -213,19 +208,6 @@ class I2CDevice {
/// @return an i2c::ErrorCode
ErrorCode write_register16(uint16_t a_register, const uint8_t *data, size_t len) const;
/// Read the 8-bit ID at \p a_register and accept it when it matches \p expected in the bits set in \p mask.
/// Otherwise mark \p component failed and return false.
bool check_chip_id(Component *component, uint8_t a_register, uint8_t expected, uint8_t mask = 0xFF) {
uint8_t id;
const ErrorCode err = this->read_register(a_register, &id, 1);
if (err == ERROR_OK && (id & mask) == (expected & mask))
return true;
if (err == ERROR_OK)
log_wrong_chip_id(id, expected & mask);
component->mark_failed(err == ERROR_OK ? LOG_STR("Wrong chip ID") : LOG_STR(ESP_LOG_MSG_COMM_FAIL));
return false;
}
///
/// Compat APIs
/// All methods below have been added for compatibility reasons. They do not bring any functionality and therefore on
@@ -282,7 +264,7 @@ class I2CDevice {
bool write_byte(uint8_t a_register, uint8_t data) const { return write_bytes(a_register, &data, 1); }
bool write_byte_16(uint8_t a_register, uint16_t data) const;
bool write_byte_16(uint8_t a_register, uint16_t data) const { return write_bytes_16(a_register, &data, 1); }
protected:
uint8_t address_{0x00}; ///< store the address of the device on the bus
@@ -68,19 +68,18 @@ INTERNAL_DAC_OPTIONS = {
}
i2s_comm_format_t = cg.global_ns.enum("i2s_comm_format_t")
I2C_COMM_FMT_OPTIONS = i2s_comm_format_t.options(
"stand_i2s",
"stand_msb",
"stand_pcm_short",
"stand_pcm_long",
"stand_max",
"i2s_msb",
"i2s_lsb",
"pcm",
"pcm_short",
"pcm_long",
prefix="I2S_COMM_FORMAT_",
)
I2C_COMM_FMT_OPTIONS = {
"stand_i2s": i2s_comm_format_t.I2S_COMM_FORMAT_STAND_I2S,
"stand_msb": i2s_comm_format_t.I2S_COMM_FORMAT_STAND_MSB,
"stand_pcm_short": i2s_comm_format_t.I2S_COMM_FORMAT_STAND_PCM_SHORT,
"stand_pcm_long": i2s_comm_format_t.I2S_COMM_FORMAT_STAND_PCM_LONG,
"stand_max": i2s_comm_format_t.I2S_COMM_FORMAT_STAND_MAX,
"i2s_msb": i2s_comm_format_t.I2S_COMM_FORMAT_I2S_MSB,
"i2s_lsb": i2s_comm_format_t.I2S_COMM_FORMAT_I2S_LSB,
"pcm": i2s_comm_format_t.I2S_COMM_FORMAT_PCM,
"pcm_short": i2s_comm_format_t.I2S_COMM_FORMAT_PCM_SHORT,
"pcm_long": i2s_comm_format_t.I2S_COMM_FORMAT_PCM_LONG,
}
INTERNAL_DAC_VARIANTS = [esp32.VARIANT_ESP32]
+6 -3
View File
@@ -11,9 +11,12 @@ DEPENDENCIES = ["spi"]
# Enum proxies (must match the C++ enum values exactly)
ICM20689AccelRange = icm20689_ns.enum("ICM20689AccelRange")
ACCEL_RANGE_OPTIONS = ICM20689AccelRange.options(
"2G", "4G", "8G", "16G", prefix="ICM20689_ACCEL_RANGE_"
)
ACCEL_RANGE_OPTIONS = {
"2G": ICM20689AccelRange.ICM20689_ACCEL_RANGE_2G,
"4G": ICM20689AccelRange.ICM20689_ACCEL_RANGE_4G,
"8G": ICM20689AccelRange.ICM20689_ACCEL_RANGE_8G,
"16G": ICM20689AccelRange.ICM20689_ACCEL_RANGE_16G,
}
ICM20689GyroRange = icm20689_ns.enum("ICM20689GyroRange")
GYRO_RANGE_OPTIONS = {
+8 -8
View File
@@ -57,14 +57,14 @@ Inkplate = inkplate_ns.class_(
InkplateModel = inkplate_ns.enum("InkplateModel")
MODELS = InkplateModel.options(
"inkplate_6",
"inkplate_10",
"inkplate_6_plus",
"inkplate_6_v2",
"inkplate_5",
"inkplate_5_v2",
)
MODELS = {
"inkplate_6": InkplateModel.INKPLATE_6,
"inkplate_10": InkplateModel.INKPLATE_10,
"inkplate_6_plus": InkplateModel.INKPLATE_6_PLUS,
"inkplate_6_v2": InkplateModel.INKPLATE_6_V2,
"inkplate_5": InkplateModel.INKPLATE_5,
"inkplate_5_v2": InkplateModel.INKPLATE_5_V2,
}
CONF_CUSTOM_WAVEFORM = "custom_waveform"
+5 -3
View File
@@ -28,9 +28,11 @@ INTEGRATION_TIMES = {
"d": IntegrationSensorTime.INTEGRATION_SENSOR_TIME_DAY,
}
IntegrationMethod = integration_ns.enum("IntegrationMethod")
INTEGRATION_METHODS = IntegrationMethod.options(
"trapezoid", "left", "right", prefix="INTEGRATION_METHOD_"
)
INTEGRATION_METHODS = {
"trapezoid": IntegrationMethod.INTEGRATION_METHOD_TRAPEZOID,
"left": IntegrationMethod.INTEGRATION_METHOD_LEFT,
"right": IntegrationMethod.INTEGRATION_METHOD_RIGHT,
}
CONF_TIME_UNIT = "time_unit"
CONF_INTEGRATION_METHOD = "integration_method"
+4 -1
View File
@@ -17,7 +17,10 @@ Jsnsr04tComponent = jsn_sr04t_ns.class_(
"Jsnsr04tComponent", sensor.Sensor, cg.PollingComponent, uart.UARTDevice
)
Model = jsn_sr04t_ns.enum("Model")
MODEL = Model.options("jsn_sr04t", "aj_sr04m")
MODEL = {
"jsn_sr04t": Model.JSN_SR04T,
"aj_sr04m": Model.AJ_SR04M,
}
CONFIG_SCHEMA = (
sensor.sensor_schema(
+4 -3
View File
@@ -25,9 +25,10 @@ DEPENDENCIES = ["i2c"]
lc709203f_ns = cg.esphome_ns.namespace("lc709203f")
LC709203FBatteryVoltage = lc709203f_ns.enum("LC709203FBatteryVoltage")
BATTERY_VOLTAGE_OPTIONS = LC709203FBatteryVoltage.options(
"3.7", "3.8", prefix="LC709203F_BATTERY_VOLTAGE_"
)
BATTERY_VOLTAGE_OPTIONS = {
"3.7": LC709203FBatteryVoltage.LC709203F_BATTERY_VOLTAGE_3_7,
"3.8": LC709203FBatteryVoltage.LC709203F_BATTERY_VOLTAGE_3_8,
}
lc709203f = lc709203f_ns.class_("Lc709203f", cg.PollingComponent, i2c.I2CDevice)
+11 -11
View File
@@ -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
Loaded 100 of 354 files, more files were not shown because too many files have changed in this diff. Show more